Class: Epuber::Book
- Inherits:
-
DSL::Object
- Object
- DSL::Object
- Epuber::Book
- Defined in:
- lib/epuber/book.rb,
lib/epuber/book/target.rb,
lib/epuber/book/toc_item.rb,
lib/epuber/book/contributor.rb,
lib/epuber/book/file_request.rb
Defined Under Namespace
Classes: Contributor, FileRequest, NormalContributor, StandardError, Target, TocItem
Instance Attribute Summary collapse
Attributes inherited from DSL::Object
Other methods collapse
-
#target_named(target_name) ⇒ Epuber::Book::Target?
Finds target with name or nil when not found.
Class Method Summary collapse
-
.default_target_attribute(sym, readonly: false) ⇒ Void
Defines setter and getter for default target attribute.
Instance Method Summary collapse
- #abstract_target(name) ⇒ Object
-
#add_const(*args) ⇒ Object
Add constant to target, constants can be used within text files.
-
#add_default_script(*file_paths) ⇒ Object
Add default script to default target, default scripts will be automatically added to xhtml document.
-
#add_default_scripts(*file_paths) ⇒ Object
Add default scripts to default target, default scripts will be automatically added to xhtml document.
-
#add_default_style(*file_paths) ⇒ Object
Add default styles to default target, default styles will be automatically added to xhtml document.
-
#add_default_styles(*file_paths) ⇒ Object
Add default styles to default target, default styles will be automatically added to xhtml document.
-
#add_file(*args) ⇒ Object
Add file to book, see Target#add_file to more details.
-
#add_files(*file_paths) ⇒ Object
Add files to book, see Target#add_files to more details.
-
#all_targets ⇒ Array<Target>
All targets.
-
#authors ⇒ Array<Contributor>
Authors of book.
-
#build_version ⇒ String
Build version of book.
- #buildable_targets ⇒ Object
-
#cover_image ⇒ String
Path or name of cover image.
-
#create_mobi ⇒ Bool
Whether the target should create mobi.
-
#custom_fonts ⇒ Bool
Book uses custom fonts (used only for iBooks).
-
#default_viewport ⇒ Size
Default view port size.
-
#epub_version ⇒ String|Fixnum
Epub version.
-
#finish_toc ⇒ Object
Nil.
-
#fixed_layout ⇒ Bool
Whether the book uses fixed layout.
- #flat_all_targets ⇒ Object
-
#freeze ⇒ Object
Nil.
-
#identifier ⇒ String
Book identifier used in OPF file.
-
#initialize {|_self| ... } ⇒ Book
constructor
A new instance of Book.
-
#is_ibooks ⇒ Bool
Book is for iBooks.
-
#isbn ⇒ String
Isbn of this book.
-
#language ⇒ String
Language of this book.
-
#output_base_name ⇒ String
Base name for output epub file.
-
#print_isbn ⇒ String
Isbn of printed book.
-
#published ⇒ Date
Date of book was published.
-
#publisher ⇒ String
Publisher name.
-
#subtitle ⇒ String
Subtitle of book.
-
#target(name) ⇒ Target
Defines new target.
-
#targets(*names, &block) ⇒ Array<Target>
Defines several new targets with same configuration.
-
#title ⇒ String
Title of book.
-
#toc(&block) ⇒ Object
Nil.
-
#use(path) ⇒ Object
Method to add plugin, that should be used while building book.
-
#validate ⇒ Object
Nil.
-
#version ⇒ Version
Book version.
Methods inherited from DSL::Object
from_file, #from_file?, from_string, #to_s
Methods included from DSL::AttributeSupport
#attribute, #define_method_attr, #dsl_attributes, #find_root
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Epuber::DSL::Object
Instance Attribute Details
#default_target ⇒ Epuber::Book::Target (readonly)
49 50 51 |
# File 'lib/epuber/book.rb', line 49 def default_target @default_target end |
Class Method Details
.default_target_attribute(sym, readonly: false) ⇒ Void
Defines setter and getter for default target attribute
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/epuber/book.rb', line 58 def self.default_target_attribute(sym, readonly: false) # getter define_method(sym) do @default_target.send(sym) end return if readonly # setter setter_method = "#{sym}=" define_method(setter_method) do |new_value| @default_target.send(setter_method, new_value) end end |
Instance Method Details
#abstract_target(name) ⇒ Object
113 114 115 116 117 118 |
# File 'lib/epuber/book.rb', line 113 def abstract_target(name) @default_target.sub_abstract_target(name) do |target| target.book = self yield target if block_given? end end |
#add_const(*args) ⇒ Object
Add constant to target, constants can be used within text files
256 257 258 |
# File 'lib/epuber/book.rb', line 256 def add_const(*args) @default_target.add_const(*args) end |
#add_default_script(*file_paths) ⇒ Object
Add default script to default target, default scripts will be automatically added to xhtml document
274 275 276 |
# File 'lib/epuber/book.rb', line 274 def add_default_script(*file_paths) @default_target.add_default_script(*file_paths) end |
#add_default_scripts(*file_paths) ⇒ Object
Add default scripts to default target, default scripts will be automatically added to xhtml document
280 281 282 |
# File 'lib/epuber/book.rb', line 280 def add_default_scripts(*file_paths) @default_target.add_default_scripts(*file_paths) end |
#add_default_style(*file_paths) ⇒ Object
Add default styles to default target, default styles will be automatically added to xhtml document
262 263 264 |
# File 'lib/epuber/book.rb', line 262 def add_default_style(*file_paths) @default_target.add_default_style(*file_paths) end |
#add_default_styles(*file_paths) ⇒ Object
Add default styles to default target, default styles will be automatically added to xhtml document
268 269 270 |
# File 'lib/epuber/book.rb', line 268 def add_default_styles(*file_paths) @default_target.add_default_styles(*file_paths) end |
#add_file(*args) ⇒ Object
Add file to book, see Epuber::Book::Target#add_file to more details
244 245 246 |
# File 'lib/epuber/book.rb', line 244 def add_file(*args) @default_target.add_file(*args) end |
#add_files(*file_paths) ⇒ Object
Add files to book, see Target#add_files to more details
250 251 252 |
# File 'lib/epuber/book.rb', line 250 def add_files(*file_paths) @default_target.add_files(*file_paths) end |
#all_targets ⇒ Array<Target>
All targets
80 81 82 83 84 85 86 |
# File 'lib/epuber/book.rb', line 80 def all_targets if @default_target.sub_targets.empty? [@default_target] else @default_target.sub_targets end end |
#authors ⇒ Array<Contributor>
Returns authors of book.
158 159 160 161 162 163 |
# File 'lib/epuber/book.rb', line 158 attribute :authors, types: [Contributor, NormalContributor], container: Array, required: true, singularize: true, auto_convert: { [String, Hash] => ->(value) { Contributor.from_obj(value) } } |
#build_version ⇒ String
Returns build version of book.
232 233 234 |
# File 'lib/epuber/book.rb', line 232 attribute :build_version, types: [Version], auto_convert: { [String, Integer, Float] => Version } |
#buildable_targets ⇒ Object
96 97 98 |
# File 'lib/epuber/book.rb', line 96 def buildable_targets flat_all_targets.reject(&:is_abstract) end |
#cover_image ⇒ String
Returns path or name of cover image.
196 |
# File 'lib/epuber/book.rb', line 196 default_target_attribute :cover_image |
#create_mobi ⇒ Bool
Returns whether the target should create mobi.
204 |
# File 'lib/epuber/book.rb', line 204 default_target_attribute :create_mobi |
#custom_fonts ⇒ Bool
Returns book uses custom fonts (used only for iBooks).
188 |
# File 'lib/epuber/book.rb', line 188 default_target_attribute :custom_fonts |
#default_viewport ⇒ Size
Returns default view port size.
200 |
# File 'lib/epuber/book.rb', line 200 default_target_attribute :default_viewport |
#epub_version ⇒ String|Fixnum
Returns epub version.
184 |
# File 'lib/epuber/book.rb', line 184 default_target_attribute :epub_version |
#finish_toc ⇒ Object
Returns nil.
25 26 27 28 29 30 31 |
# File 'lib/epuber/book.rb', line 25 def finish_toc @toc_blocks.each do |block| flat_all_targets.each do |target| target.toc(&block) end end end |
#fixed_layout ⇒ Bool
Returns whether the book uses fixed layout.
192 |
# File 'lib/epuber/book.rb', line 192 default_target_attribute :fixed_layout |
#flat_all_targets ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/epuber/book.rb', line 88 def flat_all_targets if @default_target.sub_targets.empty? [@default_target] else @default_target.flat_sub_items end end |
#freeze ⇒ Object
Returns nil.
42 43 44 45 |
# File 'lib/epuber/book.rb', line 42 def freeze super @default_target.freeze end |
#identifier ⇒ String
Returns book identifier used in OPF file.
208 |
# File 'lib/epuber/book.rb', line 208 default_target_attribute :identifier |
#is_ibooks ⇒ Bool
Returns book is for iBooks.
176 |
# File 'lib/epuber/book.rb', line 176 default_target_attribute :is_ibooks |
#isbn ⇒ String
Returns isbn of this book.
180 |
# File 'lib/epuber/book.rb', line 180 default_target_attribute :isbn |
#language ⇒ String
Returns language of this book.
172 |
# File 'lib/epuber/book.rb', line 172 attribute :language |
#output_base_name ⇒ String
Returns base name for output epub file.
238 239 |
# File 'lib/epuber/book.rb', line 238 attribute :output_base_name, inherited: true |
#print_isbn ⇒ String
Returns isbn of printed book.
213 |
# File 'lib/epuber/book.rb', line 213 attribute :print_isbn |
#published ⇒ Date
Returns date of book was published.
217 218 219 |
# File 'lib/epuber/book.rb', line 217 attribute :published, types: [Date], auto_convert: { String => Date } |
#publisher ⇒ String
Returns publisher name.
168 |
# File 'lib/epuber/book.rb', line 168 attribute :publisher |
#subtitle ⇒ String
Returns subtitle of book.
154 |
# File 'lib/epuber/book.rb', line 154 attribute :subtitle |
#target(name) ⇒ Target
Defines new target
106 107 108 109 110 111 |
# File 'lib/epuber/book.rb', line 106 def target(name) @default_target.sub_target(name) do |target| target.book = self yield target if block_given? end end |
#target_named(target_name) ⇒ Epuber::Book::Target?
Finds target with name or nil when not found
301 302 303 304 305 306 307 |
# File 'lib/epuber/book.rb', line 301 def target_named(target_name) return target_name if target_name.is_a?(Epuber::Book::Target) flat_all_targets.find do |target| target.name == target_name || target.name.to_s == target_name.to_s end end |
#targets(*names, &block) ⇒ Array<Target>
Defines several new targets with same configuration
126 127 128 129 130 131 132 133 134 |
# File 'lib/epuber/book.rb', line 126 def targets(*names, &block) if names.empty? UI.warning('Book#targets to get all targets is deprecated, use #all_targets instead', location: caller_locations.first) return all_targets end names.map { |name| target(name, &block) } end |
#title ⇒ String
Returns title of book.
149 150 |
# File 'lib/epuber/book.rb', line 149 attribute :title, required: true |
#toc(&block) ⇒ Object
Returns nil.
141 142 143 |
# File 'lib/epuber/book.rb', line 141 def toc(&block) @toc_blocks << block end |
#use(path) ⇒ Object
Method to add plugin, that should be used while building book
286 287 288 |
# File 'lib/epuber/book.rb', line 286 def use(path) @default_target.use(path) end |
#validate ⇒ Object
Returns nil.
35 36 37 38 |
# File 'lib/epuber/book.rb', line 35 def validate super @default_target.validate end |