Class: DocumentationEditor::Revision
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- DocumentationEditor::Revision
- Defined in:
- app/models/documentation_editor/revision.rb
Instance Method Summary collapse
Instance Method Details
#to_html(options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/models/documentation_editor/revision.rb', line 5 def to_html( = {}) html = parse_document().to_html # resolve the variables html = resolve_variables(, html) # resolve the code condition block html = html.gsub(/\[\[ *(.+?) *\]\](.+?)\[\[ *\/.+? *\]\]/m) do |m| [:language] == $1 ? $2 : '' end # add anchor links before headers html.gsub(/<h[1-6] id="([^"]+)">/) { |m| "#{m}<a href=\"##{$1}\" class=\"anchor\"><i class=\"fa fa-link\"></i></a>" } end |
#to_toc(options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/documentation_editor/revision.rb', line 17 def to_toc( = {}) roots = [] levels = [] h1 = nil doc = parse_document(.merge(no_wrap: true)) ids = id_generator(doc) doc.root.children.each do |child| next if child.type != :header text = child.[:raw_text] text = resolve_variables(, text) id = ids.generate_id(text) h1 = id if child.[:level] == 1 item = { label: text, id: id, children: [], level: child.[:level], h1: h1 } while !levels.empty? && levels.last[:level] >= child.[:level] levels.pop end if levels.empty? roots << item else levels.last[:children] << item end levels << item end roots end |