Class: BookLab::SML::Renderer
- Inherits:
-
Object
- Object
- BookLab::SML::Renderer
- Includes:
- Utils
- Defined in:
- lib/booklab/sml/renderer.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#in_block ⇒ Object
For table, list for temp mark in block.
-
#sml ⇒ Object
Returns the value of attribute sml.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #children_to_html(node) ⇒ Object
- #children_to_text(node) ⇒ Object
-
#initialize(sml, options) ⇒ Renderer
constructor
A new instance of Renderer.
- #node_to_html(node, opts = {}) ⇒ Object
- #node_to_text(node, opts = {}) ⇒ Object
- #to_html ⇒ Object
- #to_s ⇒ Object
- #to_text ⇒ Object
Constructor Details
#initialize(sml, options) ⇒ Renderer
Returns a new instance of Renderer.
14 15 16 17 18 19 20 |
# File 'lib/booklab/sml/renderer.rb', line 14 def initialize(sml, ) @sml = sml @config = Config.new @config.plantuml_service_host = [:plantuml_service_host] @config.mathjax_service_host = [:mathjax_service_host] @value = YAML.load(sml) end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
9 10 11 |
# File 'lib/booklab/sml/renderer.rb', line 9 def config @config end |
#in_block ⇒ Object
For table, list for temp mark in block
12 13 14 |
# File 'lib/booklab/sml/renderer.rb', line 12 def in_block @in_block end |
#sml ⇒ Object
Returns the value of attribute sml.
9 10 11 |
# File 'lib/booklab/sml/renderer.rb', line 9 def sml @sml end |
#value ⇒ Object
Returns the value of attribute value.
9 10 11 |
# File 'lib/booklab/sml/renderer.rb', line 9 def value @value end |
Instance Method Details
#children_to_html(node) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/booklab/sml/renderer.rb', line 37 def children_to_html(node) return node if node.is_a?(String) children = self.class.get_children(node) children.each_with_index.map do |child, idx| prev_node = idx > 0 ? children[idx - 1] : nil next_node = idx < children.length ? children[idx + 1] : nil node_to_html(child, prev: prev_node, next: next_node) end.join("") end |
#children_to_text(node) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/booklab/sml/renderer.rb', line 59 def children_to_text(node) return node if node.is_a?(String) children = self.class.get_children(node) children.each_with_index.map do |child, idx| text = node_to_text(child, {}) text.blank? ? nil : text end.compact.join(" ") end |
#node_to_html(node, opts = {}) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/booklab/sml/renderer.rb', line 30 def node_to_html(node, opts = {}) opts[:renderer] = self rule = BookLab::SML::Rules::find_by_node(node) rule.to_html(node, opts) end |
#node_to_text(node, opts = {}) ⇒ Object
53 54 55 56 57 |
# File 'lib/booklab/sml/renderer.rb', line 53 def node_to_text(node, opts = {}) opts[:renderer] = self rule = BookLab::SML::Rules::find_by_node(node) rule.to_text(node, opts)&.strip end |
#to_html ⇒ Object
22 23 24 |
# File 'lib/booklab/sml/renderer.rb', line 22 def to_html node_to_html(self.value) end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/booklab/sml/renderer.rb', line 26 def to_s to_html end |
#to_text ⇒ Object
49 50 51 |
# File 'lib/booklab/sml/renderer.rb', line 49 def to_text node_to_text(self.value) end |