Class: Bookery::Publishers::HTMLPublisher

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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 = {})
  @options = DEFAULTS.merge(options)

  includes_path = File.join(options[:project_dir], 'assets', 'includes')
  @processors = [
    Processors::IncludeProcessor.new(includes_path)
  ]
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/bookery/publishers/html_publisher.rb', line 11

def options
  @options
end

#processorsObject (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)
  options[: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, options).to_html

  output_dir = File.join(options[:project_dir], 'output', book.language)
  ::FileUtils.mkdir_p(output_dir)
  File.write(File.join(output_dir, 'index.html'), output)

  output
end