Class: Carta::CLI::HTMLRenderer
- Inherits:
-
Object
- Object
- Carta::CLI::HTMLRenderer
- Defined in:
- lib/carta/cli/html_renderer.rb
Instance Attribute Summary collapse
-
#epub_toc_html ⇒ Object
Returns the value of attribute epub_toc_html.
-
#html_toc_html ⇒ Object
Returns the value of attribute html_toc_html.
-
#manuscript_html ⇒ Object
Returns the value of attribute manuscript_html.
-
#markdown ⇒ Object
Returns the value of attribute markdown.
-
#outline ⇒ Object
Returns the value of attribute outline.
Instance Method Summary collapse
-
#initialize(path) ⇒ HTMLRenderer
constructor
A new instance of HTMLRenderer.
- #load_markdown(path) ⇒ Object
- #render_manuscript ⇒ Object
- #render_outline(html_class = 'toc', for_html = false) ⇒ Object
Constructor Details
#initialize(path) ⇒ HTMLRenderer
Returns a new instance of HTMLRenderer.
11 12 13 14 15 16 17 18 |
# File 'lib/carta/cli/html_renderer.rb', line 11 def initialize(path) @markdown = '' @epub_toc_html = '' @html_toc_html = '' @manuscript_html = '' @outline = nil load_markdown(path) end |
Instance Attribute Details
#epub_toc_html ⇒ Object
Returns the value of attribute epub_toc_html.
5 6 7 |
# File 'lib/carta/cli/html_renderer.rb', line 5 def epub_toc_html @epub_toc_html end |
#html_toc_html ⇒ Object
Returns the value of attribute html_toc_html.
5 6 7 |
# File 'lib/carta/cli/html_renderer.rb', line 5 def html_toc_html @html_toc_html end |
#manuscript_html ⇒ Object
Returns the value of attribute manuscript_html.
5 6 7 |
# File 'lib/carta/cli/html_renderer.rb', line 5 def manuscript_html @manuscript_html end |
#markdown ⇒ Object
Returns the value of attribute markdown.
5 6 7 |
# File 'lib/carta/cli/html_renderer.rb', line 5 def markdown @markdown end |
#outline ⇒ Object
Returns the value of attribute outline.
5 6 7 |
# File 'lib/carta/cli/html_renderer.rb', line 5 def outline @outline end |
Instance Method Details
#load_markdown(path) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/carta/cli/html_renderer.rb', line 20 def load_markdown(path) FileList.new("#{path}/manuscript/**/*.md").sort.each do |md_file| IO.readlines(md_file).each { |line| markdown << line } markdown << "\n\n" end render_manuscript end |
#render_manuscript ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/carta/cli/html_renderer.rb', line 28 def render_manuscript renderer = OutlineRenderer.new r = Redcarpet::Markdown.new(renderer) manuscript_html << r.render(markdown) @outline = renderer.outline @epub_toc_html = render_outline @html_toc_html = render_outline('toc',true) end |
#render_outline(html_class = 'toc', for_html = false) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/carta/cli/html_renderer.rb', line 37 def render_outline(html_class = 'toc', for_html = false) final_class = "class='#{html_class}'" html = '' outline.each_with_index do |data, i| level, text, link, *children = data html << "<ol #{final_class}>" if i == 0 if for_html html << "\n <li><a href='##{link}'>#{text}</a>" else html << "\n <li><a href='content.xhtml##{link}'>#{text}</a>" end if children.empty? html << '</li>' else children.each_with_index do |child, j| level, text, link = child html << "\n <ol>" if j == 0 if for_html html << "\n <li><a href='##{link}'>#{text}</a></li>" else html << "\n <li><a href='content.xhtml##{link}'>#{text}</a></li>" end html << "\n </ol>\n </li>" if j == children.length - 1 end end html << "\n</ol>" if i == outline.length - 1 end return html end |