Class: Burr::PDF
Constant Summary
Constants inherited from Exporter
Exporter::BACKMATTER, Exporter::BODYMATTER, Exporter::FRONTMATTER
Instance Attribute Summary
Attributes inherited from Exporter
#backmatter, #bodymatter, #book, #config, #frontmatter
Instance Method Summary collapse
- #assemble_book ⇒ Object
-
#decorate_contents ⇒ Object
Decorate the contents with template.
-
#parse_contents ⇒ Object
Convert original contents into HTML.
Methods inherited from Exporter
#initialize, #load_contents, #run, #run_plugins_of_type
Constructor Details
This class inherits a constructor from Burr::Exporter
Instance Method Details
#assemble_book ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/burr/exporters/pdf.rb', line 45 def assemble_book base = File.join(self.book.outputs_dir, 'pdf') html_path = File.join(base, "#{self.book.slug}.html") pdf_path = File.join(base, "#{self.book.slug}-#{Time.new.strftime('%Y%m%d')}.pdf") html = self.book.render(self.book.template_for('book'), { 'frontmatter' => self.frontmatter, 'bodymatter' => self.bodymatter, 'backmatter' => self.backmatter }) File.open(html_path, 'w') { |f| f.puts html } system "prince #{html_path} -o #{pdf_path}" File.unlink html_path end |
#decorate_contents ⇒ Object
Decorate the contents with template
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/burr/exporters/pdf.rb', line 26 def decorate_contents decorated_items = [] self.book.items.each do |item| self.book.current_item = item self.run_plugins_of_type(:before_decorate) item['content'] = self.book.render(self.book.template_for(item['element']), { 'item' => item, 'toc' => toc_html }) self.run_plugins_of_type(:after_decorate) decorated_items << self.book.current_item end self.book.items = decorated_items end |
#parse_contents ⇒ Object
Convert original contents into HTML
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/burr/exporters/pdf.rb', line 6 def parse_contents parsed_items = [] self.book.items.each do |item| self.book.current_item = item self.run_plugins_of_type(:before_parse) unless item['skip'] item['content'] = Burr::Converter.new(self.book).convert(item['original']) end self.run_plugins_of_type(:after_parse) parsed_items << self.book.current_item end self.book.items = parsed_items end |