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 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
@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
@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 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
@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 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
@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
@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
Returns all constants @return [Hash<String, Object>]
# File lib/epuber/book/target.rb, line 133 def constants ((parent && parent.constants) || {}).merge(@constants) end
@return [Array<Epuber::Book::FileRequest>]
# File lib/epuber/book/target.rb, line 145 def default_scripts ((parent && parent.default_scripts) || []) + @default_scripts end
@return [Array<Epuber::Book::FileRequest>]
# File lib/epuber/book/target.rb, line 139 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 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
# 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
@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
@return [Array<String>]
# File lib/epuber/book/target.rb, line 151 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 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
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
@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
@param path [String] use some file/module/package
@return [nil]
# File lib/epuber/book/target.rb, line 341 def use(path) @plugins << path end