class Beryl::HTMLRenderer
Public Instance Methods
render(element)
click to toggle source
# File lib/beryl/html_renderer.rb, line 3 def render(element) return element[:props][:nodeValue] if element[:type] == 'text' "#{open_tag(element)}#{children(element)}#{close_tag(element)}" end
Private Instance Methods
children(element)
click to toggle source
# File lib/beryl/html_renderer.rb, line 10 def children(element) element[:children].each_with_object('') do |child, html| html << render(child) end end
close_tag(element)
click to toggle source
# File lib/beryl/html_renderer.rb, line 16 def close_tag(element) "</#{element[:type]}>" end
open_tag(element)
click to toggle source
# File lib/beryl/html_renderer.rb, line 20 def open_tag(element) "<#{element[:type]}#{props(element[:props])}>" end
props(props)
click to toggle source
# File lib/beryl/html_renderer.rb, line 24 def props(props) props.each_with_object('') do |(key, value), html| html << " #{key}=\"#{value}\"" end end