diff --git a/CHANGELOG b/CHANGELOG index 4bc07e0..4971515 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ === HEAD +* Make table inputs_wrapper accept a :labels option and automatically set up th tags with the labels for each column (jeremyevans) + * Form#inputs now accepts a :nested_inputs_wrapper option to set default inputs_wrapper transformer inside the block (jeremyevans) * Add tr inputs_wrapper and td wrapper, for horizontal layout of inputs inside a table (jeremyevans) diff --git a/lib/forme.rb b/lib/forme.rb index 56f5fb9..1f703d9 100644 --- a/lib/forme.rb +++ b/lib/forme.rb @@ -1265,13 +1265,16 @@ class InputsWrapper::Table # Wrap the inputs in a table tag. def call(form, opts, &block) attr = opts[:attr] ? opts[:attr].dup : {} - if legend = opts[:legend] - form.tag(:table, attr) do + form.tag(:table, attr) do + if legend = opts[:legend] form.emit(form.tag(:caption, opts[:legend_attr], legend)) - yield end - else - form.tag(:table, attr, &Proc.new) + + if labels = opts[:labels] + form.emit(form.tag(:tr, {}, labels.map{|l| form._tag(:th, {}, l)})) + end + + yield end end end diff --git a/spec/forme_spec.rb b/spec/forme_spec.rb index f2d4fb1..de23a60 100644 --- a/spec/forme_spec.rb +++ b/spec/forme_spec.rb @@ -711,6 +711,10 @@ def o.foo(t) t.form.tag(:input, :class=>t.attr[:class]) end Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea], :legend=>'Inputs', :legend_attr=>{:class=>'foo'}).to_s.should == '
Inputs
' end + specify "inputs_wrapper: table accepts a :labels option" do + Forme::Form.new(:inputs_wrapper=>:table).inputs(:labels=>%w'A B C').to_s.should == '
ABC
' + end + specify "serializer: html_usa formats dates and datetimes in American format without timezones" do Forme::Form.new(:serializer=>:html_usa).tag(:div, :foo=>Date.new(2011, 6, 5)).to_s.should == '
' Forme::Form.new(:serializer=>:html_usa).tag(:div, :foo=>DateTime.new(2011, 6, 5, 16, 3, 2)).to_s.should == '
'