class Epuber::Book::Target

Attributes

book[RW]

@return [Epuber::Book] reference to book

name[R]

@return [String, Symbol] target name

root_toc[R]

@return [Epuber::Book::TocItem]

Public Class Methods

new(parent = nil, name) 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 16
def initialize(parent = nil, name)
  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 key [String] @param value [String]

@return [void]

# File lib/epuber/book/target.rb, line 260
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 file_paths [Array<String>]

@return [void]

# File lib/epuber/book/target.rb, line 302
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 file_paths [Array<String>]

@return [void]

# File lib/epuber/book/target.rb, line 318
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 file_paths [Array<String>]

@return [void]

# File lib/epuber/book/target.rb, line 273
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 file_paths [Array<String>]

@return [void]

# File lib/epuber/book/target.rb, line 289
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 file_path [String | Epuber::Book::File] @param group [Symbol]

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

# File lib/epuber/book/target.rb, line 226
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 file_paths [Array<String>]

@return [void]

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

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

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

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

# File lib/epuber/book/target.rb, line 145
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 139
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 119
def files
  # parent files plus our files
  all_files = ((parent && parent.files) || []) + @files + @default_styles + @default_scripts

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

  all_files
end
freeze() click to toggle source
Calls superclass method
# File lib/epuber/book/target.rb, line 31
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 108
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 151
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 94
def sub_abstract_target(name)
  child = create_child_item(name)
  child.book = self.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 79
def sub_target(name)
  child = create_child_item(name)
  child.book = self.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 333
def toc
  yield(@root_toc, self) if block_given?
end
use(path) click to toggle source

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

@return [nil]

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