Class: Riven::HTMLGenerator
- Inherits:
-
Object
- Object
- Riven::HTMLGenerator
- Defined in:
- lib/riven/html_generator.rb
Instance Attribute Summary collapse
-
#html ⇒ Object
Returns the value of attribute html.
-
#html_file ⇒ Object
Returns the value of attribute html_file.
Instance Method Summary collapse
- #close! ⇒ Object
- #generate_html ⇒ Object
-
#initialize(tmp_file, markup, options) ⇒ HTMLGenerator
constructor
A new instance of HTMLGenerator.
- #markup_to_html(markup) ⇒ Object
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, ) @html_file = Riven::HTMLFile.new(tmp_file) @markup = markup = @html = generate_html @html_file.write(@html) end |
Instance Attribute Details
#html ⇒ Object
Returns the value of attribute html.
8 9 10 |
# File 'lib/riven/html_generator.rb', line 8 def html @html end |
#html_file ⇒ Object
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_html ⇒ Object
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.(File.dirname(__FILE__)) + '/../../css/style.css') unless [:css_file].empty? css << "\n\n" css << File.read([: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 |