Class: Riven::HTMLGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/riven/html_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tmp_file, markup, options) ⇒ HTMLGenerator

Returns a new instance of HTMLGenerator.



10
11
12
13
14
15
16
17
18
# File 'lib/riven/html_generator.rb', line 10

public def initialize(tmp_file, markup, options)
  @html_file = Riven::HTMLFile.new(tmp_file)

  @markup = markup
  @options = options

  @html = generate_html
  @html_file.write(@html)
end

Instance Attribute Details

#htmlObject

Returns the value of attribute html.



8
9
10
# File 'lib/riven/html_generator.rb', line 8

def html
  @html
end

#html_fileObject

Returns the value of attribute html_file.



8
9
10
# File 'lib/riven/html_generator.rb', line 8

def html_file
  @html_file
end

Instance Method Details

#close!Object



61
62
63
# File 'lib/riven/html_generator.rb', line 61

public def close!
  @html_file.delete!
end

#generate_htmlObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/riven/html_generator.rb', line 20

public def generate_html
  css = File.read(File.expand_path(File.dirname(__FILE__)) + '/../../css/style.css')

  unless @options[:css_file].empty?
    css << "\n\n"
    css << File.read(@options[:css_file])
  end

  html =  '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
  html << '<style type="text/css">' + css + '</style></head><body>'
  html << markup_to_html(@markup)
  html << '</body></html>'
end

#markup_to_html(markup) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/riven/html_generator.rb', line 34

public def markup_to_html(markup)
  code = Riven::Markup::Code.new

  markup = code.extract(markup)

  opts = {
    no_intra_emphasis: true,
    tables: true,
    underline: true,
    highlight: true,
    with_toc_data: true,
    lax_spacing: true,
    xhtml: true,
    fenced_code_blocks: true
  }

  redcarpet_markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, opts)
  html = redcarpet_markdown.render(markup)

  html = code.process(html)

  html.gsub! '////[COVERSTART]////', '<div class="cover-page">'
  html.gsub! '////[COVEREND]////',   '</div>'

  return html
end