app/components/component_docitem.rb in express_ui-0.1.2 vs app/components/component_docitem.rb in express_ui-0.1.3
- old
+ new
@@ -1,14 +1,23 @@
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 }
- h5 "General Information"
+ h4 "General Information"
+ para(style: 'padding: 0 0.25rem 1rem 0.25rem', only_when: !!config[:description]) {
+ config[:description]
+ }
+
table {
- tbody {
+ tbody {
tr {
th(width: "25%", style: "text-transform: none") { "Builder Method" }
td {
code "#{builder_method}()"
}
@@ -26,41 +35,66 @@
td { express_capabilities.join("<br>").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)
- h5 "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(width: "25%", style: "text-transform: none") {
- code {
- option.inspect
- }
+ td(style: "text-transform: none") {
+ code { option.inspect }
}
- td {
- pre {
- option_types(config[:type])
- }
+ td { pre { option_types(config[:type]) } }
+ td { pre { config[:default] } }
+ td { pre { config[:required] ? 'yes' : 'no' } }
+ td(width: "50%") {
+ config[:description].html_safe
}
- td {
- pre {
- config[:default]
- }
- }
- td {
- config[:description]
- }
}
end
}
}
@@ -93,9 +127,11 @@
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
\ No newline at end of file