Permalink
Browse files

Fix Rails integration with fieldset_ol inputs wrapper

This is a quick hack to work around the problem.  A more general
fix may come later.
  • Loading branch information...
1 parent 8f4fee8 commit ae150afcdaf2ecd95db7f6a1ef6764eb4ee9333a @jeremyevans committed May 2, 2012
Showing with 44 additions and 9 deletions.
  1. +5 −1 lib/forme.rb
  2. +11 −8 lib/forme/rails.rb
  3. +14 −0 spec/rails_integration_spec.rb
  4. +14 −0 spec/sinatra_integration_spec.rb
View
@@ -402,6 +402,10 @@ def tag(*a, &block)
tag
end
+ def tag_(*a, &block)
+ tag(*a, &block)
+ end
+
# Creates a :submit +Input+ with the given opts, adding it to the list
# of children for the currently open tag.
def button(opts={})
@@ -1032,7 +1036,7 @@ class InputsWrapper::FieldSetOL < InputsWrapper
# Wrap the inputs in an ol tag
def call(form, opts)
- super(form, opts){form.tag(:ol){yield}}
+ super(form, opts){form.tag_(:ol){yield}}
end
end
View
@@ -49,19 +49,22 @@ def input(*)
# output of the tag goes into that buffer, and return the buffer.
# Otherwise, just return a string version of the tag that is already
# marked as safe.
- def tag(type, attr={}, children=[])
- tag = _tag(type, attr, children)
+ def tag(type, attr={}, children=[], &block)
if block_given?
- template.send(:with_output_buffer) do
- emit(serializer.serialize_open(tag)) if serializer.respond_to?(:serialize_open)
- Array(children).each{|c| emit(c)}
- yield self if block_given?
- emit(serializer.serialize_close(tag)) if serializer.respond_to?(:serialize_close)
- end
+ template.send(:with_output_buffer){tag_(type, attr, children, &block)}
else
+ tag = _tag(type, attr, children)
template.raw(tag.to_s)
end
end
+
+ def tag_(type, attr={}, children=[])
+ tag = _tag(type, attr, children)
+ emit(serializer.serialize_open(tag)) if serializer.respond_to?(:serialize_open)
+ Array(children).each{|c| emit(c)}
+ yield self if block_given?
+ emit(serializer.serialize_close(tag)) if serializer.respond_to?(:serialize_close)
+ end
end
module ERB
@@ -36,6 +36,16 @@ def inputs_block
END
end
+ def inputs_block_wrapper
+ render :inline => <<END
+<%= forme([:foo, :bar], {:action=>'/baz'}, :inputs_wrapper=>:fieldset_ol) do |f| %>
+ <%= f.inputs(:legend=>'FBB') do %>
+ <%= f.input(:last) %>
+ <% end %>
+<% end %>
+END
+ end
+
def nest
render :inline => <<END
<%= forme([:foo, :bar], :action=>'/baz') do |f| %>
@@ -150,6 +160,10 @@ def o.puts(*) end
sin_get('/inputs_block').should == '<form action="/baz"> <fieldset class="inputs"><legend>FBB</legend> <input id="last" name="last" type="text" value="bar"/> </fieldset></form>'
end
+ specify "#form should have inputs with fieldset_ol wrapper work with block" do
+ sin_get('/inputs_block_wrapper').should == '<form action="/baz"> <fieldset class="inputs"><legend>FBB</legend><ol> <input id="last" name="last" type="text" value="bar"/> </ol></fieldset></form>'
+ end
+
specify "#form should add start and end tags and yield Forme::Form instance" do
sin_get('/nest').should == '<form action="/baz"> <p>FBB</p> <div> <input id="first" name="first" type="text" value="foo"/> <input id="last" name="last" type="text" value="bar"/> </div> </form>'
end
@@ -31,6 +31,16 @@ class FormeSinatraTest < Sinatra::Base
END
end
+ get '/inputs_block_wrapper' do
+ erb <<END
+<% form([:foo, :bar], {:action=>'/baz'}, :inputs_wrapper=>:fieldset_ol) do |f| %>
+ <% f.inputs(:legend=>'FBB') do %>
+ <%= f.input(:last) %>
+ <% end %>
+<% end %>
+END
+ end
+
get '/nest' do
erb <<END
<% form([:foo, :bar], :action=>'/baz') do |f| %>
@@ -143,6 +153,10 @@ def o.puts(*) end
sin_get('/inputs_block').should == '<form action="/baz"><fieldset class="inputs"><legend>FBB</legend> <input id="last" name="last" type="text" value="bar"/> </fieldset></form>'
end
+ specify "#form should have inputs with fieldset_ol wrapper work with block" do
+ sin_get('/inputs_block_wrapper').should == '<form action="/baz"><fieldset class="inputs"><legend>FBB</legend><ol> <input id="last" name="last" type="text" value="bar"/> </ol></fieldset></form>'
+ end
+
specify "#form should add start and end tags and yield Forme::Form instance" do
sin_get('/nest').should == '<form action="/baz"> <p>FBB</p> <div> <input id="first" name="first" type="text" value="foo"/> <input id="last" name="last" type="text" value="bar"/> </div> </form>'
end

0 comments on commit ae150af

Please sign in to comment.