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_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_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_ibooks ⇒ Bool
Hint for compiler to add some iBooks related stuff.
-
#isbn ⇒ String
Isbn of epub.
- #plugins ⇒ Array<String>
-
#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 |
# 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 = [] @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.
59 60 61 |
# File 'lib/epuber/book/target.rb', line 59 def book @book end |
#name ⇒ String, Symbol (readonly)
Returns target name.
47 48 49 |
# File 'lib/epuber/book/target.rb', line 47 def name @name end |
#root_toc ⇒ Epuber::Book::TocItem (readonly)
55 56 57 |
# File 'lib/epuber/book/target.rb', line 55 def root_toc @root_toc end |
Instance Method Details
#add_const(key, value = nil) ⇒ void
This method returns an undefined value.
227 228 229 230 231 232 233 |
# File 'lib/epuber/book/target.rb', line 227 def add_const(key, value = nil) if key.is_a?(Hash) && value.nil? @constants.merge!(key) else @constants[key] = value end end |
#add_default_style(*file_paths) ⇒ void
This method returns an undefined value.
240 241 242 243 244 245 246 247 |
# File 'lib/epuber/book/target.rb', line 240 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
256 257 258 259 260 261 262 263 |
# File 'lib/epuber/book/target.rb', line 256 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.
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/epuber/book/target.rb', line 193 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.
215 216 217 218 219 220 |
# File 'lib/epuber/book/target.rb', line 215 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
111 112 113 |
# File 'lib/epuber/book/target.rb', line 111 def constants ((parent && parent.constants) || {}).merge(@constants) end |
#cover_image ⇒ FileRequest
Returns file request to cover image.
170 171 172 173 |
# File 'lib/epuber/book/target.rb', line 170 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.
183 184 185 |
# File 'lib/epuber/book/target.rb', line 183 attribute :create_mobi, types: [TrueClass, FalseClass], inherited: true |
#custom_fonts ⇒ String
Returns target will use custom font (for iBooks only).
152 153 154 |
# File 'lib/epuber/book/target.rb', line 152 attribute :custom_fonts, types: [TrueClass, FalseClass], inherited: true |
#default_styles ⇒ Array<Epuber::Book::FileRequest>
117 118 119 |
# File 'lib/epuber/book/target.rb', line 117 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.
177 178 179 |
# File 'lib/epuber/book/target.rb', line 177 attribute :default_viewport, types: [Size], inherited: true |
#epub_version ⇒ String
Returns version of result epub.
133 134 135 136 137 138 |
# File 'lib/epuber/book/target.rb', line 133 attribute :epub_version, required: true, inherited: true, types: [Version], auto_convert: { [String, Fixnum, Float] => Version }, default_value: 3.0 |
#files ⇒ Array<Epuber::Book::FileRequest>
Returns all files
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/epuber/book/target.rb', line 97 def files # parent files plus our files all_files = ((parent && parent.files) || []) + @files + @default_styles 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.
164 165 166 |
# File 'lib/epuber/book/target.rb', line 164 attribute :fixed_layout, types: [TrueClass, FalseClass], inherited: true |
#freeze ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/epuber/book/target.rb', line 30 def freeze super @files.freeze @files.each(&:freeze) @default_styles.freeze @default_styles.each(&:freeze) @plugins.freeze @plugins.each(&:freeze) @root_toc.freeze @constants.freeze end |
#ibooks? ⇒ Bool
86 87 88 89 90 91 92 |
# File 'lib/epuber/book/target.rb', line 86 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.
147 148 |
# File 'lib/epuber/book/target.rb', line 147 attribute :identifier, inherited: true |
#is_ibooks ⇒ Bool
Returns hint for compiler to add some iBooks related stuff.
158 159 160 |
# File 'lib/epuber/book/target.rb', line 158 attribute :is_ibooks, types: [TrueClass, FalseClass], inherited: true |
#isbn ⇒ String
Returns isbn of epub.
142 143 |
# File 'lib/epuber/book/target.rb', line 142 attribute :isbn, inherited: true |
#plugins ⇒ Array<String>
123 124 125 |
# File 'lib/epuber/book/target.rb', line 123 def plugins ((parent && parent.plugins) || []) + @plugins end |
#sub_target(name) {|child| ... } ⇒ Target
Create new sub_target with name
74 75 76 77 78 79 80 |
# File 'lib/epuber/book/target.rb', line 74 def sub_target(name) child = create_child_item(name) yield child if block_given? child end |
#toc {|toc_item, target| ... } ⇒ Object
Returns nil.
271 272 273 |
# File 'lib/epuber/book/target.rb', line 271 def toc yield(@root_toc, self) if block_given? end |
#use(path) ⇒ nil
279 280 281 |
# File 'lib/epuber/book/target.rb', line 279 def use(path) @plugins << path end |