class ComponentDocitem < ExpressTemplates::Container
has_option :examples, "Examples. Keys are partial names. :assigns and :expected_output are passed to component_example.", type: :hash
# TODO: See if we could pull this from RDoc
has_option :description, "A description of the component."
prepends -> {
h3(style: 'text-transform: none') { component_class.to_s.demodulize }
h4 "General Information"
para(style: 'padding: 0 0.25rem 1rem 0.25rem', only_when: !!config[:description]) {
config[:description]
}
table {
tbody {
tr {
th(width: "25%", style: "text-transform: none") { "Builder Method" }
td {
code "#{builder_method}()"
}
}
tr {
th(width: "25%", style: "text-transform: none") { "Module" }
td { component_class.to_s.split("::")[0..-2].join("::") }
}
tr {
th(width: "25%", style: "text-transform: none") { "Ancestors" }
td { express_ancestors.join("
").html_safe }
}
tr {
th(width: "25%", style: "text-transform: none") { "Capabilities" }
td { express_capabilities.join("
").html_safe }
}
}
}
if component_class.respond_to?(:supported_arguments) &&
component_class.supported_arguments.any?
h4 "Supported Arguments"
table {
thead {
th { "option" }
th { "type" }
th { "default" }
th { "required" }
th { "Description" }
}
tbody {
component_class.supported_arguments.each do |arg, config|
tr {
td(style: "text-transform: none") {
code { arg.inspect }
}
td { pre { option_types(config[:type]) } }
td { pre { config[:default] } }
td { pre { config[:required] ? 'yes' : 'no' } }
td(width: "50%") {
config[:description].html_safe
}
}
end
}
}
end
if component_class.respond_to?(:supported_options)
h4 "Supported Options"
table {
thead {
th { "option" }
th { "type" }
th { "default" }
th { "required" }
th { "Description" }
}
tbody {
component_class.supported_options.each do |option, config|
tr {
td(style: "text-transform: none") {
code { option.inspect }
}
td { pre { option_types(config[:type]) } }
td { pre { config[:default] } }
td { pre { config[:required] ? 'yes' : 'no' } }
td(width: "50%") {
config[:description].html_safe
}
}
end
}
}
end
}
def component_class
ET::Components::Registry[builder_method]
end
def express_ancestors
(component_class.ancestors - [component_class])
.select { |c| c.to_s.match(/Express/) &&
!c.to_s.match(/Capabilities/) }
end
def express_capabilities
(component_class.ancestors - [component_class])
.map(&:to_s)
.select { |c| c.match /Capabilities/ }
.map(&:demodulize)
end
def builder_method
config[:id].to_s
end
def option_types(types)
case
when types.kind_of?(Hash)
types.keys.map(&:inspect).join(', ')
when config[:type].kind_of?(Array)
types.map(&:inspect).join(', ')
when types.nil?
''
else
types.inspect
end
end
end