Class: VivlioPack::TocRenderer
- Inherits:
-
Redcarpet::Render::Base
- Object
- Redcarpet::Render::Base
- VivlioPack::TocRenderer
- Defined in:
- lib/vivlio_pack/toc_renderer.rb
Class Method Summary collapse
Instance Method Summary collapse
- #header(c, level) ⇒ Object
-
#initialize ⇒ TocRenderer
constructor
A new instance of TocRenderer.
Constructor Details
#initialize ⇒ TocRenderer
Returns a new instance of TocRenderer.
3 4 5 6 7 |
# File 'lib/vivlio_pack/toc_renderer.rb', line 3 def initialize super @sec = 0 @ch = 0 end |
Class Method Details
.render(files) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vivlio_pack/toc_renderer.rb', line 22 def self.render(files) renderer = TocRenderer.new markdown = Redcarpet::Markdown.new(renderer, fenced_code_blocks: true) toc = [] files.each do |path| File.open(path, "r") do |file| toc << markdown.render(file.read) end end " <nav class=\"toc\">\n <ol>\n \#{toc.map{|c| \"<li>\#{c}</li>\\n</ol>\"}.join(\"\\n\")}\n </ol>\n </nav>\n TOC\nend\n" |
Instance Method Details
#header(c, level) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/vivlio_pack/toc_renderer.rb', line 9 def header(c, level) case level when 1 @sec += 1 @ch = 0 "<a href='#sec#{@sec}'>#{c}</a>\n<ol>" when 2 @ch += 1 "<li><a href='#ch#{@sec}-#{@ch}'>#{c}</a></li>\n" end end |