Class: Burr::Exporter
Constant Summary collapse
- FRONTMATTER =
%w(acknowledgement author cover dedication edition foreword introduction license preface prologue title toc)
- BODYMATTER =
%w(appendix blank chapter conclusion part)
- BACKMATTER =
%w(afterword epilogue glossary lof lot)
Instance Attribute Summary collapse
-
#backmatter ⇒ Object
Returns the value of attribute backmatter.
-
#bodymatter ⇒ Object
Returns the value of attribute bodymatter.
-
#book ⇒ Object
Returns the value of attribute book.
-
#config ⇒ Object
Returns the value of attribute config.
-
#frontmatter ⇒ Object
Returns the value of attribute frontmatter.
Instance Method Summary collapse
-
#initialize(book) ⇒ Exporter
constructor
A new instance of Exporter.
-
#load_contents ⇒ Object
Load book contents.
-
#run ⇒ Object
Run exporter.
-
#run_plugins_of_type(type) ⇒ Object
Run all hooks of a type.
Constructor Details
#initialize(book) ⇒ Exporter
Returns a new instance of Exporter.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/burr/exporter.rb', line 12 def initialize(book) @book = book @config = book.config @frontmatter = [] @bodymatter = [] @backmatter = [] prepare_output_dir end |
Instance Attribute Details
#backmatter ⇒ Object
Returns the value of attribute backmatter.
10 11 12 |
# File 'lib/burr/exporter.rb', line 10 def backmatter @backmatter end |
#bodymatter ⇒ Object
Returns the value of attribute bodymatter.
10 11 12 |
# File 'lib/burr/exporter.rb', line 10 def bodymatter @bodymatter end |
#book ⇒ Object
Returns the value of attribute book.
9 10 11 |
# File 'lib/burr/exporter.rb', line 9 def book @book end |
#config ⇒ Object
Returns the value of attribute config.
9 10 11 |
# File 'lib/burr/exporter.rb', line 9 def config @config end |
#frontmatter ⇒ Object
Returns the value of attribute frontmatter.
10 11 12 |
# File 'lib/burr/exporter.rb', line 10 def frontmatter @frontmatter end |
Instance Method Details
#load_contents ⇒ Object
Load book contents
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/burr/exporter.rb', line 53 def load_contents special_elements = %w(cover toc blank) self.config['contents'].each do |content_config| item = initialize_item(content_config) # if the element defines its own content file (usually: `chapter`, `appendix`) if !item['file'].blank? content_file = File.join(self.book.contents_dir, item['file']) # check that content file exists and is readable if !File.readable? content_file raise <<-MESSAGE % content_config['file'], item['element'], "outputs/#{content_config['file']}" The '%s' content associated with '%s' element doesn't exist\n or is not readable.\n\n Check that '%s'\n file exists and check its permissions. MESSAGE end item['original'] = File.read(content_file) elsif item['file'].blank? && special_elements.include?(item['element']) item['skip'] = true else # look for a default content defined by burr for this element # e.g. `cover.md`, `license.md`, `title.md` default_content_file = File.join(self.book.contents_dir, "#{item['element']}.md") if File.exist?(default_content_file) item['original'] = File.read(default_content_file) else self.book.ui.error("Missing file for #{item['element']}") exit 1 end end self.frontmatter << item if item['matter'] == 'frontmatter' self.bodymatter << item if item['matter'] == 'bodymatter' self.backmatter << item if item['matter'] == 'backmatter' self.book.items << item end end |
#run ⇒ Object
Run exporter.
The details should implement in subclass.
45 46 47 48 49 50 |
# File 'lib/burr/exporter.rb', line 45 def run self.load_contents self.parse_contents self.decorate_contents self.assemble_book end |
#run_plugins_of_type(type) ⇒ Object
Run all hooks of a type.
type - The plugin name in Symbol, valid options are: :before_parse, :after_parse
:before_decorate, :after_decorate.
Returns nothing.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/burr/exporter.rb', line 29 def run_plugins_of_type(type) type = type.to_sym Burr::Plugin.subclasses.each do |k| k_obj = k.new(self.book) Burr::Plugin::VALIDS.each do |h| k_obj.send(type) if k_obj.respond_to?(h) && h == type end end nil end |