Class: Bookery::Publishers::HTMLPublisher
- Inherits:
-
Object
- Object
- Bookery::Publishers::HTMLPublisher
- Defined in:
- lib/bookery/publishers/html_publisher.rb
Defined Under Namespace
Classes: TemplateObject
Constant Summary collapse
- DEFAULTS =
{ input: 'GFM', enable_coderay: true, coderay_css: 'class', coderay_line_numbers: 'inline' }
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#processors ⇒ Object
readonly
Returns the value of attribute processors.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ HTMLPublisher
constructor
A new instance of HTMLPublisher.
- #pre_publish(book) ⇒ Object
- #publish(book) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ HTMLPublisher
Returns a new instance of HTMLPublisher.
13 14 15 16 17 18 19 20 |
# File 'lib/bookery/publishers/html_publisher.rb', line 13 def initialize( = {}) @options = DEFAULTS.merge() includes_path = File.join([:project_dir], 'assets', 'includes') @processors = [ Processors::IncludeProcessor.new(includes_path) ] end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/bookery/publishers/html_publisher.rb', line 11 def @options end |
#processors ⇒ Object (readonly)
Returns the value of attribute processors.
11 12 13 |
# File 'lib/bookery/publishers/html_publisher.rb', line 11 def processors @processors end |
Instance Method Details
#pre_publish(book) ⇒ Object
35 36 37 38 39 |
# File 'lib/bookery/publishers/html_publisher.rb', line 35 def pre_publish(book) erb = ERB.new(File.read(book.template)) bound_object = TemplateObject.new(book) [:template] = "string://#{erb.result(bound_object.get_binding)}" end |
#publish(book) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bookery/publishers/html_publisher.rb', line 22 def publish(book) markdown = process_content(book.content) pre_publish(book) output = Kramdown::Document.new(markdown, ).to_html output_dir = File.join([:project_dir], 'output', book.language) ::FileUtils.mkdir_p(output_dir) File.write(File.join(output_dir, 'index.html'), output) output end |