class Epuber::Book::Target

Attributes

book[W]

@return [Epuber::Book] reference to book

name[R]

@return [String, Symbol] target name

root_toc[R]

@return [Epuber::Book::TocItem]

Public Class Methods

new(name, parent: nil) click to toggle source

@param [Target] parent reference to parent target @param [String] name name of this target

Calls superclass method
# File lib/epuber/book/target.rb, line 15
def initialize(name, parent: nil)
  super(parent)

  @name      = name
  @is_ibooks = nil
  @book      = nil
  @files     = []
  @constants = {}
  @root_toc  = TocItem.new

  @default_styles = []
  @default_scripts = []
  @plugins = []
end

Public Instance Methods

add_const(key, value = nil) click to toggle source

@param [String] key @param [String] value

@return [void]

# File lib/epuber/book/target.rb, line 257
def add_const(key, value = nil)
  if key.is_a?(Hash) && value.nil?
    @constants.merge!(key)
  else
    @constants[key] = value
  end
end
add_default_script(*file_paths) click to toggle source

@param [Array<String>] file_paths

@return [void]

# File lib/epuber/book/target.rb, line 298
def add_default_script(*file_paths)
  file_paths.map do |file_path|
    file_obj          = add_file(file_path, group: :script)
    file_obj.only_one = true

    @default_scripts << file_obj unless @default_scripts.include?(file_obj)
  end
end
add_default_scripts(*file_paths) click to toggle source

Add default scripts to target, default scripts will be automatically added to xhtml document

Only difference with add_default_script is it adds multiple files with one pattern @param [Array<String>] file_paths

@return [void]

# File lib/epuber/book/target.rb, line 314
def add_default_scripts(*file_paths)
  file_paths.map do |file_path|
    file_obj          = add_file(file_path, group: :script)
    file_obj.only_one = false

    @default_scripts << file_obj unless @default_scripts.include?(file_obj)
  end
end
add_default_style(*file_paths) click to toggle source

@param [Array<String>] file_paths

@return [void]

# File lib/epuber/book/target.rb, line 269
def add_default_style(*file_paths)
  file_paths.map do |file_path|
    file_obj          = add_file(file_path, group: :style)
    file_obj.only_one = true

    @default_styles << file_obj unless @default_styles.include?(file_obj)
  end
end
add_default_styles(*file_paths) click to toggle source

Add default styles to default target, default styles will be automatically added to xhtml document

Only difference with add_default_style is it adds multiple files with one pattern @param [Array<String>] file_paths

@return [void]

# File lib/epuber/book/target.rb, line 285
def add_default_styles(*file_paths)
  file_paths.map do |file_path|
    file_obj          = add_file(file_path, group: :style)
    file_obj.only_one = false

    @default_styles << file_obj unless @default_styles.include?(file_obj)
  end
end
add_file(file_path, group: nil) click to toggle source

@param [String | Epuber::Book::File] file_path @param [Symbol] group

@return [Epuber::Book::File] created file

# File lib/epuber/book/target.rb, line 223
def add_file(file_path, group: nil)
  file = if file_path.is_a?(FileRequest)
           file_path
         else
           FileRequest.new(file_path, group: group)
         end


  old_file = @files.find { |f| f == file }

  if old_file.nil?
    @files << file
    file
  else
    old_file
  end
end
add_files(*file_paths) click to toggle source

@param [Array<String>] file_paths

@return [void]

# File lib/epuber/book/target.rb, line 245
def add_files(*file_paths)
  file_paths.each do |file_path|
    file_obj          = add_file(file_path)
    file_obj.only_one = false
  end
end
book() click to toggle source

@return [Epuber::Book] reference to book

# File lib/epuber/book/target.rb, line 66
def book
  @book || parent&.book
end
constants() click to toggle source

Returns all constants @return [Hash<String, Object>]

# File lib/epuber/book/target.rb, line 128
def constants
  (parent&.constants || {}).merge(@constants)
end
default_scripts() click to toggle source

@return [Array<Epuber::Book::FileRequest>]

# File lib/epuber/book/target.rb, line 140
def default_scripts
  ((parent && parent.default_scripts) || []) + @default_scripts
end
default_styles() click to toggle source

@return [Array<Epuber::Book::FileRequest>]

# File lib/epuber/book/target.rb, line 134
def default_styles
  ((parent && parent.default_styles) || []) + @default_styles
end
files() click to toggle source

Returns all files @return [Array<Epuber::Book::FileRequest>]

# File lib/epuber/book/target.rb, line 116
def files
  # parent files plus our files
  all_files = ((parent && parent.files) || []) + @files + @default_styles + @default_scripts

  all_files << @attributes_values[:cover_image] unless @attributes_values[:cover_image].nil?

  all_files
end
freeze() click to toggle source
Calls superclass method
# File lib/epuber/book/target.rb, line 30
def freeze
  super
  @files.freeze
  @files.each(&:freeze)

  @default_styles.freeze
  @default_styles.each(&:freeze)

  @default_scripts.freeze
  @default_scripts.each(&:freeze)

  @plugins.freeze
  @plugins.each(&:freeze)

  @root_toc.freeze
  @constants.freeze
end
ibooks?() click to toggle source

@return [Bool]

# File lib/epuber/book/target.rb, line 105
def ibooks?
  if is_ibooks.nil?
    name.to_s.include?('ibooks')
  else
    is_ibooks
  end
end
plugins() click to toggle source

@return [Array<String>]

# File lib/epuber/book/target.rb, line 146
def plugins
  ((parent && parent.plugins) || []) + @plugins
end
sub_abstract_target(name) { |child| ... } click to toggle source

Create new sub_target with name

@param [String] name

@return [Target] new created sub target

# File lib/epuber/book/target.rb, line 91
def sub_abstract_target(name)
  child = create_child_item(name)
  child.book = book
  child.is_abstract = true

  yield child if block_given?

  child
end
sub_target(name) { |child| ... } click to toggle source

Create new sub_target with name

@param [String] name

@return [Target] new created sub target

# File lib/epuber/book/target.rb, line 76
def sub_target(name)
  child = create_child_item(name)
  child.book = book

  yield child if block_given?

  child
end
toc() { |root_toc, self| ... } click to toggle source

@yield [toc_item, target] @yieldparam toc_item [TocItem] root toc item @yieldparam target [self] current target

@return nil

# File lib/epuber/book/target.rb, line 329
def toc
  yield(@root_toc, self) if block_given?
end
use(path) click to toggle source

@param [String] path use some file/module/package

@return [nil]

# File lib/epuber/book/target.rb, line 337
def use(path)
  @plugins << path
end