Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed table render style

  • Loading branch information...
commit 4699d39225b18d4675e9fe555a70af5d31e3b1d4 1 parent b23e0b1
Tangerine Cat authored
4 lib/ream/form/dsl.rb
View
@@ -5,8 +5,8 @@ def text( name = nil, value = "", opts = {} )
self << Text.new( name, value, opts )
end
- def password( name = nil, value = "", opts = {} )
- self << Password.new( name, value, opts )
+ def password( name = nil, opts = {} )
+ self << Password.new( name, opts )
end
def hidden( name = nil, value = "", opts = {} )
5 lib/ream/form/input_group.rb
View
@@ -30,7 +30,10 @@ def render_with_style
end
def render_items
- @inputs.map{|i|render_style.render_input_group_item( i.render, @opts )}
+ @inputs.map do |i|
+ opts = @opts.merge( :last => @inputs.last.object_id == i.object_id )
+ render_style.render_input_group_item( i.render, opts )
+ end
end
def render_without_style
2  lib/ream/form/render_style/table.rb
View
@@ -35,7 +35,7 @@ def render_input_group( raw_html, opts = {} )
end
def render_input_group_item( raw_html, opts = {} )
- raw_html
+ raw_html + ( opts[ :last ] ? "" : "<br />" )
end
end
11 sandbox/login_form.rb
View
@@ -1,9 +1,11 @@
+$:.unshift( File.join( File.dirname( __FILE__ ), "../lib" ) )
+
require 'ream/form'
class LoginForm < Ream::Form::Form
def initialize( user_object = nil )
super( "/login" ) do |f|
- f.text( "login[name]", user_object.name, :id => "login_id", :label => "Login" )
+ f.text( "login[name]", ( user_object.name rescue "" ), :id => "login_id", :label => "Login" )
f.password( "login[password]", :id => "login_password", :label => "Password" )
f.submit( "Ok" )
end
@@ -19,3 +21,10 @@ def render_style
# in controller: @form = LoginForm.new( user )
#
# in view: = @form.render
+
+if $0 == __FILE__
+ require 'ream/form/render_style'
+ require 'ostruct'
+
+ puts LoginForm.new( OpenStruct.new( "name" => "user_name" ) ).render
+end
21 test/test_table_render_style.rb
View
@@ -63,7 +63,6 @@
setup do
@form = ::TestFormWithInputGroup.new( RenderStyle::Table.new )
@doc = Nokogiri::XML( @form.render )
-puts @form.render.inspect
end
it "should contain form" do
@@ -76,7 +75,25 @@
end
it "should contain several inputs" do
- @td.xpath( "//input" ).size.should.be > 1
+ @td.xpath( "//input" ).size.should.be == 3
+ end
+
+ it "should have inputs with type checkbox" do
+ @td.xpath( "//input" )[rand(3)][ "type" ].should == "checkbox"
+ end
+
+ it "should have 5 subnodes" do
+ @td.xpath( "*" ).size.should == 5
+ end
+
+ it "should contain inputs in even places (0, 2, 4)" do
+ nodes = @td.xpath( "*" )
+ assert( [ 0, 2, 4 ].map{|i|nodes[i].name}.all?{|s| s == "input" } )
+ end
+
+ it "should contain br in odd places (1, 3)" do
+ nodes = @td.xpath( "*" )
+ assert( [ 1, 3 ].map{|i|nodes[i].name}.all?{|s| s == "br" } )
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.