Class: ProsemirrorToHtml::Renderer
- Inherits:
-
Object
- Object
- ProsemirrorToHtml::Renderer
- Defined in:
- lib/prosemirror_to_html.rb
Overview
Your code goes here…
Instance Method Summary collapse
- #addMark(mark) ⇒ Object
- #addMarks(marks) ⇒ Object
- #addNode(node) ⇒ Object
- #addNodes(nodes) ⇒ Object
-
#initialize ⇒ Renderer
constructor
A new instance of Renderer.
- #render(hash) ⇒ Object
Constructor Details
#initialize ⇒ Renderer
Returns a new instance of Renderer.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/prosemirror_to_html.rb', line 27 def initialize() @storedMarks = [] @marks = [ ProsemirrorToHtml::Marks::Bold, ProsemirrorToHtml::Marks::Code, ProsemirrorToHtml::Marks::Italic, ProsemirrorToHtml::Marks::Link ] @nodes = [ ProsemirrorToHtml::Nodes::BulletList, ProsemirrorToHtml::Nodes::CodeBlockWrapper, ProsemirrorToHtml::Nodes::CodeBlock, ProsemirrorToHtml::Nodes::HardBreak, ProsemirrorToHtml::Nodes::Heading, ProsemirrorToHtml::Nodes::Image, ProsemirrorToHtml::Nodes::ListItem, ProsemirrorToHtml::Nodes::OrderedList, ProsemirrorToHtml::Nodes::Paragraph, # ProsemirrorToHtml::Nodes::Text, ProsemirrorToHtml::Nodes::User ] end |
Instance Method Details
#addMark(mark) ⇒ Object
58 59 60 |
# File 'lib/prosemirror_to_html.rb', line 58 def addMark(mark) @marks.push(mark) end |
#addMarks(marks) ⇒ Object
61 62 63 64 65 |
# File 'lib/prosemirror_to_html.rb', line 61 def addMarks(marks) marks.each do |mark| addMark(mark); end end |
#addNode(node) ⇒ Object
50 51 52 |
# File 'lib/prosemirror_to_html.rb', line 50 def addNode(node) @nodes.push(node) end |
#addNodes(nodes) ⇒ Object
53 54 55 56 57 |
# File 'lib/prosemirror_to_html.rb', line 53 def addNodes(nodes) nodes.each do |node| addNode(node); end end |
#render(hash) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/prosemirror_to_html.rb', line 67 def render(hash) html = "" json = hash.to_json object = JSON.parse(json, object_class: OpenStruct) object.content.each do |node| html += renderNode(node) end html end |