Class: Epuber::Book::Target
- Inherits:
-
DSL::TreeObject
- Object
- DSL::Object
- DSL::TreeObject
- Epuber::Book::Target
- Defined in:
- lib/epuber/book/target.rb
Instance Attribute Summary collapse
-
#book ⇒ Epuber::Book
Reference to book.
-
#name ⇒ String, Symbol
readonly
Target name.
- #root_toc ⇒ Epuber::Book::TocItem readonly
Attributes inherited from DSL::TreeObject
Attributes inherited from DSL::Object
Instance Method Summary collapse
- #add_const(key, value = nil) ⇒ void
- #add_default_script(*file_paths) ⇒ void
-
#add_default_scripts(*file_paths) ⇒ void
Add default scripts to target, default scripts will be automatically added to xhtml document.
- #add_default_style(*file_paths) ⇒ void
-
#add_default_styles(*file_paths) ⇒ void
Add default styles to default target, default styles will be automatically added to xhtml document.
-
#add_file(file_path, group: nil) ⇒ Epuber::Book::File
Created file.
- #add_files(*file_paths) ⇒ void
-
#constants ⇒ Hash<String, Object>
Returns all constants.
-
#cover_image ⇒ FileRequest
File request to cover image.
-
#create_mobi ⇒ Bool
Whether the target should create mobi.
-
#custom_fonts ⇒ String
Target will use custom font (for iBooks only).
- #default_scripts ⇒ Array<Epuber::Book::FileRequest>
- #default_styles ⇒ Array<Epuber::Book::FileRequest>
-
#default_viewport ⇒ Size
Size of view port, mainly this is used for fixed layout.
-
#epub_version ⇒ String
Version of result epub.
-
#files ⇒ Array<Epuber::Book::FileRequest>
Returns all files.
-
#fixed_layout ⇒ Bool
Whether the target uses fixed layout.
- #freeze ⇒ Object
- #ibooks? ⇒ Bool
-
#identifier ⇒ String
Book identifier used in OPF file.
-
#initialize(parent = nil, name) ⇒ Target
constructor
A new instance of Target.
-
#is_abstract ⇒ Bool
Allows to create abstract targets that are only used as template for other targets.
-
#is_ibooks ⇒ Bool
Hint for compiler to add some iBooks related stuff.
-
#isbn ⇒ String
Isbn of epub.
- #plugins ⇒ Array<String>
-
#sub_abstract_target(name) {|child| ... } ⇒ Target
Create new sub_target with name.
-
#sub_target(name) {|child| ... } ⇒ Target
Create new sub_target with name.
-
#toc {|toc_item, target| ... } ⇒ Object
Nil.
- #use(path) ⇒ nil
Methods inherited from DSL::TreeObject
#create_child_item, #create_child_items, #flat_sub_items, #root?, #validate
Methods inherited from DSL::Object
from_file, #from_file?, from_string, #to_s, #validate
Methods included from DSL::AttributeSupport
#attribute, #define_method_attr, #dsl_attributes, #find_root
Constructor Details
#initialize(parent = nil, name) ⇒ Target
Returns a new instance of Target.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Epuber::DSL::Object
Instance Attribute Details
#book ⇒ Epuber::Book
Returns reference to book.
63 64 65 |
# File 'lib/epuber/book/target.rb', line 63 def book @book end |
#name ⇒ String, Symbol (readonly)
Returns target name.
51 52 53 |
# File 'lib/epuber/book/target.rb', line 51 def name @name end |
#root_toc ⇒ Epuber::Book::TocItem (readonly)
59 60 61 |
# File 'lib/epuber/book/target.rb', line 59 def root_toc @root_toc end |
Instance Method Details
#add_const(key, value = nil) ⇒ void
This method returns an undefined value.
260 261 262 263 264 265 266 |
# 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) ⇒ void
This method returns an undefined value.
302 303 304 305 306 307 308 309 |
# 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) ⇒ void
This method returns an undefined value.
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
318 319 320 321 322 323 324 325 |
# 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) ⇒ void
This method returns an undefined value.
273 274 275 276 277 278 279 280 |
# 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) ⇒ void
This method returns an undefined value.
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
289 290 291 292 293 294 295 296 |
# 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) ⇒ Epuber::Book::File
Returns created file.
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# 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) ⇒ void
This method returns an undefined value.
248 249 250 251 252 253 |
# 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 ⇒ Hash<String, Object>
Returns all constants
133 134 135 |
# File 'lib/epuber/book/target.rb', line 133 def constants ((parent && parent.constants) || {}).merge(@constants) end |
#cover_image ⇒ FileRequest
Returns file request to cover image.
197 198 199 200 |
# File 'lib/epuber/book/target.rb', line 197 attribute :cover_image, types: [FileRequest], inherited: true, auto_convert: { [String] => ->(value) { FileRequest.new(value, group: :image, properties: [:cover_image]) } } |
#create_mobi ⇒ Bool
Returns whether the target should create mobi.
210 211 212 |
# File 'lib/epuber/book/target.rb', line 210 attribute :create_mobi, types: [TrueClass, FalseClass], inherited: true |
#custom_fonts ⇒ String
Returns target will use custom font (for iBooks only).
179 180 181 |
# File 'lib/epuber/book/target.rb', line 179 attribute :custom_fonts, types: [TrueClass, FalseClass], inherited: true |
#default_scripts ⇒ Array<Epuber::Book::FileRequest>
145 146 147 |
# File 'lib/epuber/book/target.rb', line 145 def default_scripts ((parent && parent.default_scripts) || []) + @default_scripts end |
#default_styles ⇒ Array<Epuber::Book::FileRequest>
139 140 141 |
# File 'lib/epuber/book/target.rb', line 139 def default_styles ((parent && parent.default_styles) || []) + @default_styles end |
#default_viewport ⇒ Size
Returns size of view port, mainly this is used for fixed layout.
204 205 206 |
# File 'lib/epuber/book/target.rb', line 204 attribute :default_viewport, types: [Size], inherited: true |
#epub_version ⇒ String
Returns version of result epub.
161 162 163 164 165 |
# File 'lib/epuber/book/target.rb', line 161 attribute :epub_version, required: true, inherited: true, auto_convert: { [String, Integer, Float] => Version }, default_value: 3.0 |
#files ⇒ Array<Epuber::Book::FileRequest>
Returns all files
119 120 121 122 123 124 125 126 127 128 |
# 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 |
#fixed_layout ⇒ Bool
Returns whether the target uses fixed layout.
191 192 193 |
# File 'lib/epuber/book/target.rb', line 191 attribute :fixed_layout, types: [TrueClass, FalseClass], inherited: true |
#freeze ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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? ⇒ Bool
108 109 110 111 112 113 114 |
# File 'lib/epuber/book/target.rb', line 108 def ibooks? if is_ibooks.nil? name.to_s.include?('ibooks') else is_ibooks end end |
#identifier ⇒ String
Returns book identifier used in OPF file.
174 175 |
# File 'lib/epuber/book/target.rb', line 174 attribute :identifier, inherited: true |
#is_abstract ⇒ Bool
Returns allows to create abstract targets that are only used as template for other targets.
216 217 218 |
# File 'lib/epuber/book/target.rb', line 216 attribute :is_abstract, types: [TrueClass, FalseClass], inherited: false |
#is_ibooks ⇒ Bool
Returns hint for compiler to add some iBooks related stuff.
185 186 187 |
# File 'lib/epuber/book/target.rb', line 185 attribute :is_ibooks, types: [TrueClass, FalseClass], inherited: true |
#isbn ⇒ String
Returns isbn of epub.
169 170 |
# File 'lib/epuber/book/target.rb', line 169 attribute :isbn, inherited: true |
#plugins ⇒ Array<String>
151 152 153 |
# File 'lib/epuber/book/target.rb', line 151 def plugins ((parent && parent.plugins) || []) + @plugins end |
#sub_abstract_target(name) {|child| ... } ⇒ Target
Create new sub_target with name
94 95 96 97 98 99 100 101 102 |
# 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| ... } ⇒ Target
Create new sub_target with name
79 80 81 82 83 84 85 86 |
# 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 {|toc_item, target| ... } ⇒ Object
Returns nil.
333 334 335 |
# File 'lib/epuber/book/target.rb', line 333 def toc yield(@root_toc, self) if block_given? end |
#use(path) ⇒ nil
341 342 343 |
# File 'lib/epuber/book/target.rb', line 341 def use(path) @plugins << path end |