lib/yaks/format/html.rb in yaks-html-0.8.3 vs lib/yaks/format/html.rb in yaks-html-0.9.0
- old
+ new
@@ -95,12 +95,15 @@
form = form.attr('method', form_control.method) if form_control.method
form = form.attr('action', form_control.action) if form_control.action
form = form.attr('enctype', form_control.media_type) if form_control.media_type
rows = form_control.fields.map(&method(:render_field))
+ rows << H[:tr, H[:td], H[:td, H[:input, {type: 'submit'}]]]
- form.content(H[:table, H[:h4, form_control.title || form_control.name.to_s], *rows, H[:tr, H[:td], H[:td, H[:input, {type: 'submit'}]]]])
+ H[:div,
+ H[:h4, form_control.title || form_control.name.to_s],
+ form.content(H[:table, rows])]
end
def render_field(field)
return render_fieldset(field) if field.type == :fieldset
extra_info = reject_keys(field.to_h_compact, :type, :name, :value, :label, :options)
@@ -125,10 +128,15 @@
H[:td, extra_info.empty? ? '' : extra_info.inspect]
]
end
def render_fieldset(fieldset)
- H[:fieldset, fieldset.fields.map(&method(:render_field))]
+ legend = fieldset.fields.select {|field|field.type == :legend}.first
+ legend = legend ? legend.name : ''
+
+ H[:tr,
+ H[:th, legend],
+ H[:td, H[:fieldset, H[:table, fieldset.fields.map(&method(:render_field))]]]]
end
def render_select_options(options)
options.map do |o|
H[:option, reject_keys(o.to_h_compact, :label), o.label]