class Madman::YAMLDoc
Attributes
title[R]
yaml[R]
Public Class Methods
new(yaml, title: nil)
click to toggle source
# File lib/madman/yamldoc.rb, line 11 def initialize(yaml, title: nil) @yaml = yaml @title = title end
Public Instance Methods
render()
click to toggle source
# File lib/madman/yamldoc.rb, line 16 def render slim.render self end
slim()
click to toggle source
# File lib/madman/yamldoc.rb, line 24 def slim @slim ||= Slim::Template.new template, slim_options end
slim_options()
click to toggle source
# File lib/madman/yamldoc.rb, line 28 def slim_options { pretty: true, disable_escape: true } end
template()
click to toggle source
# File lib/madman/yamldoc.rb, line 20 def template File.expand_path '../views/yamldoc.slim', __dir__ end
tree()
click to toggle source
# File lib/madman/yamldoc.rb, line 32 def tree @tree ||= tree! end
Private Instance Methods
counter()
click to toggle source
# File lib/madman/yamldoc.rb, line 38 def counter @counter ||= 0 @counter += 1 end
render_pair(key, value, indent, caption)
click to toggle source
# File lib/madman/yamldoc.rb, line 55 def render_pair(key, value, indent, caption) slug = "#{key.slug}-#{counter}" space = ' ' result = [] if key[0] == '_' result.push "#{space * indent}<div>" else result.push "#{space * indent}<h#{caption}><a href='##{slug}' class='clickable'>#{key}</a></h#{caption}>" result.push "#{space * indent}<div class='hidden' id='#{slug}'>" end if value.is_a? Hash result.push tree!(value, indent+1, caption+1) elsif value result.push "#{space * (indent+1)}#{value.to_html}" end result.push "#{space * indent}</div>" result end
tree!(data=nil, indent=0, caption=2)
click to toggle source
# File lib/madman/yamldoc.rb, line 43 def tree!(data=nil, indent=0, caption=2) data ||= yaml result = [] caption = 6 if caption > 6 data.each do |key, value| result.push render_pair key, value, indent, caption end result.join "\n" end