Class: Storyblok::Richtext::HtmlRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/storyblok/richtext/html_renderer.rb

Instance Method Summary collapse

Constructor Details

#initializeHtmlRenderer

Returns a new instance of HtmlRenderer.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/storyblok/richtext/html_renderer.rb', line 29

def initialize
  @marks = [
    Storyblok::Richtext::Marks::Bold,
    Storyblok::Richtext::Marks::Strike,
    Storyblok::Richtext::Marks::Underline,
    Storyblok::Richtext::Marks::Strong,
    Storyblok::Richtext::Marks::Code,
    Storyblok::Richtext::Marks::Italic,
    Storyblok::Richtext::Marks::Link
  ]
  @nodes = [
    Storyblok::Richtext::Nodes::HorizontalRule,
    Storyblok::Richtext::Nodes::Blockquote,
    Storyblok::Richtext::Nodes::BulletList,
    Storyblok::Richtext::Nodes::CodeBlock,
    Storyblok::Richtext::Nodes::HardBreak,
    Storyblok::Richtext::Nodes::Heading,
    Storyblok::Richtext::Nodes::Image,
    Storyblok::Richtext::Nodes::ListItem,
    Storyblok::Richtext::Nodes::OrderedList,
    Storyblok::Richtext::Nodes::Paragraph,
    Storyblok::Richtext::Nodes::Text,
    Storyblok::Richtext::Nodes::Blok
  ]
end

Instance Method Details

#add_mark(mark) ⇒ Object



63
64
65
# File 'lib/storyblok/richtext/html_renderer.rb', line 63

def add_mark(mark)
  @marks.push(mark)
end

#add_node(node) ⇒ Object



59
60
61
# File 'lib/storyblok/richtext/html_renderer.rb', line 59

def add_node(node)
  @nodes.push(node)
end

#render(data) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/storyblok/richtext/html_renderer.rb', line 67

def render(data)
  html = ""
  data['content'].each do |node|
    html += render_node(node)
  end

  html
end

#set_component_resolver(component_resolver) ⇒ Object



55
56
57
# File 'lib/storyblok/richtext/html_renderer.rb', line 55

def set_component_resolver(component_resolver)
  Storyblok::Richtext::Nodes::Blok.define_method :component_resolver, component_resolver
end