Class: Elisp::Sidebar
- Inherits:
-
Object
- Object
- Elisp::Sidebar
- Defined in:
- lib/elisp.rb
Instance Method Summary collapse
- #html ⇒ Object
-
#initialize(headings) ⇒ Sidebar
constructor
A new instance of Sidebar.
Constructor Details
#initialize(headings) ⇒ Sidebar
Returns a new instance of Sidebar.
14 15 16 |
# File 'lib/elisp.rb', line 14 def initialize(headings) @headings = headings end |
Instance Method Details
#html ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/elisp.rb', line 18 def html rest = @headings.dup result = +"" while (head = rest.shift) level = head.level subheadings = [] while (heading = rest.shift) if heading.level > level subheadings << heading else rest.unshift(heading) break end end = subheadings.empty? ? nil : (html = self.class.new(subheadings).html "<details open>#{html}</details>") content = CGI.escape_html(head.content) result << " <li>\n <a href=\"#\#{head.html_id}\">\#{content}</a>\n \#{sub_sidebar}\n </li>\n END_HTML\n end\n \"<ul>\#{result}</ul>\"\nend\n" |