module Jekyll class ConfigurationBlock < Liquid::Block TYPE_LINKS = { 'action' => '/docs/scripts/', 'device_class' => '/components/%{component}/#device-class', 'template' => '/docs/configuration/templating/', } def initialize(tag_name, text, tokens) super @component, @platform = text.strip.split('.', 2) end def slug(key) key.downcase.strip.gsub(' ', '-').gsub(/[^\w\-]/, '') end def type_class(type) ((type.is_a? Array) ? type.join(' ') : type).downcase end def type_link(type, component: nil) if type.include? ',' type = type.split(',') end if type.is_a? Array return (type.map { |t| type_link(t, component: component) }).join(' | ') end type.strip! if TYPE_LINKS.include? type.downcase url = TYPE_LINKS[type.downcase] % {component: component} "[%s](%s)" % [type, url] else type end end def required_value(value) if value === true "Required" elsif value === false "Optional" else value.strip.titlecase end end def render_config_vars(vars:, component:, platform:, classes: nil) result = Array.new result << "
" if attr.key? 'type' markup << "(" markup << "#{type_link(attr['type'], component: component)})" end if attr.key? 'required' markup << "(#{required_value(attr['required'])})" end if attr.key? 'description' markup << "#{attr['description']}" end markup << "
" if attr.key? 'default' markup << "Default value: #{attr['default']}
" end markup << "