class Epuber::Book::Target
Attributes
@return [Epuber::Book] reference to book
@return [String, Symbol] target name
@return [Epuber::Book::TocItem]
Public Class Methods
@param [Target] parent reference to parent target @param [String] name name of this target
# 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
@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
@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 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
@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 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
@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
@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
@return [Epuber::Book] reference to book
# File lib/epuber/book/target.rb, line 66 def book @book || parent&.book end
Returns all constants @return [Hash<String, Object>]
# File lib/epuber/book/target.rb, line 128 def constants (parent&.constants || {}).merge(@constants) end
@return [Array<Epuber::Book::FileRequest>]
# File lib/epuber/book/target.rb, line 140 def default_scripts ((parent && parent.default_scripts) || []) + @default_scripts end
@return [Array<Epuber::Book::FileRequest>]
# File lib/epuber/book/target.rb, line 134 def default_styles ((parent && parent.default_styles) || []) + @default_styles end
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
# 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
@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
@return [Array<String>]
# File lib/epuber/book/target.rb, line 146 def plugins ((parent && parent.plugins) || []) + @plugins end
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
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
@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
@param [String] path use some file/module/package
@return [nil]
# File lib/epuber/book/target.rb, line 337 def use(path) @plugins << path end