forme 1.12.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +54 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +228 -206
- data/Rakefile +1 -7
- data/lib/forme/bs3.rb +23 -9
- data/lib/forme/erb.rb +13 -25
- data/lib/forme/form.rb +146 -149
- data/lib/forme/input.rb +1 -1
- data/lib/forme/rails.rb +39 -83
- data/lib/forme/raw.rb +2 -2
- data/lib/forme/tag.rb +3 -12
- data/lib/forme/template.rb +110 -0
- data/lib/forme/transformers/error_handler.rb +10 -10
- data/lib/forme/transformers/formatter.rb +32 -34
- data/lib/forme/transformers/helper.rb +0 -1
- data/lib/forme/transformers/inputs_wrapper.rb +4 -4
- data/lib/forme/version.rb +2 -2
- data/lib/forme.rb +13 -2
- data/lib/roda/plugins/forme.rb +1 -1
- data/lib/roda/plugins/forme_erubi_capture.rb +57 -0
- data/lib/roda/plugins/forme_route_csrf.rb +16 -34
- data/lib/roda/plugins/forme_set.rb +39 -76
- data/lib/sequel/plugins/forme.rb +45 -54
- data/lib/sequel/plugins/forme_i18n.rb +3 -1
- data/lib/sequel/plugins/forme_set.rb +2 -4
- data/spec/all.rb +1 -1
- data/spec/bs3_reference_spec.rb +291 -314
- data/spec/bs3_sequel_plugin_spec.rb +155 -155
- data/spec/bs3_spec.rb +247 -206
- data/spec/erb_helper.rb +69 -58
- data/spec/erubi_capture_helper.rb +198 -0
- data/spec/forme_coverage.rb +1 -0
- data/spec/forme_spec.rb +438 -377
- data/spec/rails_integration_spec.rb +21 -11
- data/spec/roda_integration_spec.rb +136 -70
- data/spec/sequel_helper.rb +3 -2
- data/spec/sequel_i18n_helper.rb +1 -1
- data/spec/sequel_i18n_plugin_spec.rb +6 -6
- data/spec/sequel_plugin_spec.rb +262 -150
- data/spec/sequel_set_plugin_spec.rb +9 -3
- data/spec/shared_erb_specs.rb +71 -0
- data/spec/sinatra_integration_spec.rb +31 -6
- data/spec/spec_helper.rb +21 -8
- metadata +8 -6
- data/lib/forme/erb_form.rb +0 -74
- data/lib/forme/sinatra.rb +0 -17
data/spec/erb_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative 'shared_erb_specs'
|
2
|
+
|
1
3
|
ERB_BLOCK = lambda do |r|
|
2
4
|
r.get '' do
|
3
5
|
erb <<END
|
@@ -65,6 +67,29 @@ END
|
|
65
67
|
END
|
66
68
|
end
|
67
69
|
|
70
|
+
r.get 'nest_seq_simple' do
|
71
|
+
@album = Album.load(:name=>'N', :copies_sold=>2, :id=>1)
|
72
|
+
@album.associations[:artist] = Artist.load(:name=>'A', :id=>2)
|
73
|
+
@nest = <<END
|
74
|
+
n1
|
75
|
+
<% f.subform(:artist) do %>
|
76
|
+
n2
|
77
|
+
<%= f.input(:name2) %>
|
78
|
+
n3
|
79
|
+
<% end %>
|
80
|
+
n4
|
81
|
+
END
|
82
|
+
erb <<END
|
83
|
+
0
|
84
|
+
<% form(@album, :action=>'/baz') do |f| %>
|
85
|
+
1
|
86
|
+
<%= erb(@nest, :locals=>{:f=>f}) %>
|
87
|
+
3
|
88
|
+
<% end %>
|
89
|
+
4
|
90
|
+
END
|
91
|
+
end
|
92
|
+
|
68
93
|
r.get 'nest_seq' do
|
69
94
|
@album = Album.load(:name=>'N', :copies_sold=>2, :id=>1)
|
70
95
|
@album.associations[:artist] = Artist.load(:name=>'A', :id=>2)
|
@@ -92,6 +117,50 @@ END
|
|
92
117
|
END
|
93
118
|
end
|
94
119
|
|
120
|
+
r.get 'grid-block' do
|
121
|
+
@album = Album.load(:name=>'N', :copies_sold=>2, :id=>1)
|
122
|
+
@album.associations[:artist] = Artist.load(:name=>'A', :id=>2)
|
123
|
+
erb <<END
|
124
|
+
0
|
125
|
+
<% form(@album, {:action=>'/baz'}, :button=>'Sub') do |f| %>
|
126
|
+
1
|
127
|
+
<% f.subform(:artist, :inputs=>[:name], :legend=>'Foo', :grid=>true, :labels=>%w'Name') do %>
|
128
|
+
2
|
129
|
+
<% end %>
|
130
|
+
3
|
131
|
+
<% end %>
|
132
|
+
4
|
133
|
+
END
|
134
|
+
end
|
135
|
+
|
136
|
+
r.get 'grid-noblock' do
|
137
|
+
@album = Album.load(:name=>'N', :copies_sold=>2, :id=>1)
|
138
|
+
@album.associations[:artist] = Artist.load(:name=>'A', :id=>2)
|
139
|
+
erb <<END
|
140
|
+
0
|
141
|
+
<% form(@album, {:action=>'/baz'}, :button=>'Sub') do |f| %>
|
142
|
+
1
|
143
|
+
<%= f.subform(:artist, :inputs=>[:name], :legend=>'Foo', :grid=>true, :labels=>%w'Name') %>
|
144
|
+
2
|
145
|
+
<% end %>
|
146
|
+
3
|
147
|
+
END
|
148
|
+
end
|
149
|
+
|
150
|
+
r.get 'grid-noblock-multiple' do
|
151
|
+
@artist = Artist.load(:name=>'A', :id=>2)
|
152
|
+
@artist.associations[:albums] = [Album.load(:name=>'N', :copies_sold=>2, :id=>1)]
|
153
|
+
erb <<END
|
154
|
+
0
|
155
|
+
<% form(@artist, {:action=>'/baz'}, :button=>'Sub') do |f| %>
|
156
|
+
1
|
157
|
+
<%= f.subform(:albums, :inputs=>[:name, :copies_sold], :legend=>'Foo', :grid=>true, :labels=>%w'Name Copies') %>
|
158
|
+
2
|
159
|
+
<% end %>
|
160
|
+
3
|
161
|
+
END
|
162
|
+
end
|
163
|
+
|
95
164
|
r.get 'hash' do
|
96
165
|
erb "<% form({:action=>'/baz'}, :obj=>[:foo]) do |f| %> <%= f.input(:first) %> <% end %>"
|
97
166
|
end
|
@@ -127,61 +196,3 @@ END
|
|
127
196
|
erb "<%= form(:action=>'/baz') %>"
|
128
197
|
end
|
129
198
|
end
|
130
|
-
|
131
|
-
module FormeErbSpecs
|
132
|
-
extend Minitest::Spec::DSL
|
133
|
-
|
134
|
-
before do
|
135
|
-
o = Object.new
|
136
|
-
def o.puts(*) end
|
137
|
-
@rack = {'rack.input'=>'', 'REQUEST_METHOD'=>'GET', 'rack.errors'=>o, 'SCRIPT_NAME'=>''}
|
138
|
-
end
|
139
|
-
|
140
|
-
it "#form should add start and end tags and yield Forme::Form instance" do
|
141
|
-
sin_get('/').must_equal '<form action="/baz"> <p>FBB</p> <input id="first" name="first" type="text" value="foo"/> <input id="last" name="last" type="text" value="bar"/> <input type="submit" value="Save"/> </form>'
|
142
|
-
end
|
143
|
-
|
144
|
-
it "#form should have inputs work with a block" do
|
145
|
-
sin_get('/inputs_block').must_equal '<form action="/baz"><fieldset class="inputs"><legend>FBB</legend> <input id="last" name="last" type="text" value="bar"/> </fieldset></form>'
|
146
|
-
end
|
147
|
-
|
148
|
-
it "#form should have inputs with fieldset_ol wrapper work with block" do
|
149
|
-
sin_get('/inputs_block_wrapper').must_equal '<form action="/baz"><fieldset class="inputs"><legend>FBB</legend><ol> <input id="last" name="last" type="text" value="bar"/> </ol></fieldset></form>'
|
150
|
-
end
|
151
|
-
|
152
|
-
it "#form should add start and end tags and yield Forme::Form instance" do
|
153
|
-
sin_get('/nest').must_equal '<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>'
|
154
|
-
end
|
155
|
-
|
156
|
-
it "#form should correctly handle situation where multiple templates are used with same form object" do
|
157
|
-
sin_get('/nest_sep').must_equal '0 <form action="/baz"> 1 <p>FBB</p> 2 n1 <div> n2 <input id="first" name="first" type="text" value="foo"/> <input id="last" name="last" type="text" value="bar"/> n3 </div> n4 <fieldset class="inputs"><legend>Foo</legend><input id="first" name="first" type="text" value="foo"/><input id="last" name="last" type="text" value="bar"/></fieldset> n5 3 </form>4'
|
158
|
-
end
|
159
|
-
|
160
|
-
it "#form should correctly handle situation Sequel integration with subforms where multiple templates are used with same form object" do
|
161
|
-
sin_get('/nest_seq').sub(%r{<input name="_csrf" type="hidden" value="([^"]+)"/>}, '<input name="_csrf" type="hidden" value="csrf"/>').must_equal '0 <form action="/baz" class="forme album" method="post"><input name="_csrf" type="hidden" value="csrf"/> 1 <input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Foo</legend><label>Name: <input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="A"/></label></fieldset> 2 n1 <input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Artist</legend> n2 <label>Name2: <input id="album_artist_attributes_name2" name="album[artist_attributes][name2]" type="text" value="A2"/></label> n3 </fieldset> n4 <input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Bar</legend><label>Name3: <input id="album_artist_attributes_name3" name="album[artist_attributes][name3]" type="text" value="A3"/></label></fieldset> n5 3 </form>4'
|
162
|
-
end
|
163
|
-
|
164
|
-
it "#form should accept two hashes instead of requiring obj as first argument" do
|
165
|
-
sin_get('/hash').must_equal '<form action="/baz"> <input id="first" name="first" type="text" value="foo"/> </form>'
|
166
|
-
end
|
167
|
-
|
168
|
-
it "#form should deal with emitted code" do
|
169
|
-
sin_get('/legend').must_equal '<form action="/baz"> <p>FBB</p> <fieldset class="inputs"><legend>Foo</legend><input id="first" name="first" type="text" value="foo"/><input id="last" name="last" type="text" value="bar"/></fieldset> <p>FBB2</p> </form>'
|
170
|
-
end
|
171
|
-
|
172
|
-
it "#form should work with :inputs, :button, and :legend options" do
|
173
|
-
sin_get('/combined').must_equal '<form action="/baz"><fieldset class="inputs"><legend>123</legend><input id="first" name="first" type="text" value="foo"/></fieldset> <p>FBB</p> <input id="last" name="last" type="text" value="bar"/> <input type="submit" value="xyz"/></form>'
|
174
|
-
end
|
175
|
-
|
176
|
-
it "#form should work without a block" do
|
177
|
-
sin_get('/noblock').must_equal '<form action="/baz"><fieldset class="inputs"><legend>123</legend><input id="first" name="first" type="text" value="foo"/></fieldset><input type="submit" value="xyz"/></form>'
|
178
|
-
end
|
179
|
-
|
180
|
-
it "#form should work without a block and still have hidden tags emitted" do
|
181
|
-
sin_get('/noblock_post').sub(%r{<input name=\"_csrf\" type=\"hidden\" value=\"([^\"]+)\"/>}, "<input name=\"_csrf\" type=\"hidden\" value=\"csrf\"/>").must_equal '<form method="post"><input name="_csrf" type="hidden" value="csrf"/><input type="submit" value="xyz"/></form>'
|
182
|
-
end
|
183
|
-
|
184
|
-
it "#form with an empty form should work" do
|
185
|
-
sin_get('/noblock_empty').must_equal '<form action="/baz"></form>'
|
186
|
-
end
|
187
|
-
end
|
@@ -0,0 +1,198 @@
|
|
1
|
+
require_relative 'shared_erb_specs'
|
2
|
+
|
3
|
+
ERUBI_CAPTURE_BLOCK = lambda do |r|
|
4
|
+
r.get '' do
|
5
|
+
erb <<END
|
6
|
+
<%|= form([:foo, :bar], :action=>'/baz') do |f| %>
|
7
|
+
<p>FBB</p>
|
8
|
+
<%= f.input(:first) %>
|
9
|
+
<%= f.input(:last) %>
|
10
|
+
<%= f.button('Save') %>
|
11
|
+
<%| end %>
|
12
|
+
END
|
13
|
+
end
|
14
|
+
|
15
|
+
r.get 'inputs_block' do
|
16
|
+
erb <<END
|
17
|
+
<%|= form([:foo, :bar], :action=>'/baz') do |f| %><%|= f.inputs(:legend=>'FBB') do %>
|
18
|
+
<%= f.input(:last) %>
|
19
|
+
<%| end %><%| end %>
|
20
|
+
END
|
21
|
+
end
|
22
|
+
|
23
|
+
r.get 'inputs_block_wrapper' do
|
24
|
+
erb <<END
|
25
|
+
<%|= form([:foo, :bar], {:action=>'/baz'}, :inputs_wrapper=>:fieldset_ol) do |f| %><%|= f.inputs(:legend=>'FBB') do %>
|
26
|
+
<%= f.input(:last) %>
|
27
|
+
<%| end %><%| end %>
|
28
|
+
END
|
29
|
+
end
|
30
|
+
|
31
|
+
r.get 'nest' do
|
32
|
+
erb <<END
|
33
|
+
<%|= form([:foo, :bar], :action=>'/baz') do |f| %>
|
34
|
+
<%= f.tag(:p, {}, 'FBB') %>
|
35
|
+
<%|= f.tag(:div) do %>
|
36
|
+
<%= f.input(:first) %>
|
37
|
+
<%= f.input(:last) %>
|
38
|
+
<%| end %>
|
39
|
+
|
40
|
+
<%| end %>
|
41
|
+
END
|
42
|
+
end
|
43
|
+
|
44
|
+
r.get 'nest_sep' do
|
45
|
+
@nest = <<END
|
46
|
+
n1
|
47
|
+
<%|= f.tag(:div) do %>
|
48
|
+
n2
|
49
|
+
<%= f.input(:first) %>
|
50
|
+
<%= f.input(:last) %>
|
51
|
+
n3
|
52
|
+
<%| end %>
|
53
|
+
n4
|
54
|
+
<%= f.inputs([:first, :last], :legend=>'Foo') %>
|
55
|
+
n5
|
56
|
+
END
|
57
|
+
erb <<END
|
58
|
+
0
|
59
|
+
<%|= form([:foo, :bar], :action=>'/baz') do |f| %>
|
60
|
+
1
|
61
|
+
<%= f.tag(:p, {}, 'FBB') %>
|
62
|
+
2
|
63
|
+
<%= erb(@nest, :locals=>{:f=>f}) %>
|
64
|
+
3
|
65
|
+
<%| end %>
|
66
|
+
4
|
67
|
+
END
|
68
|
+
end
|
69
|
+
|
70
|
+
r.get 'nest_seq_simple' do
|
71
|
+
@album = Album.load(:name=>'N', :copies_sold=>2, :id=>1)
|
72
|
+
@album.associations[:artist] = Artist.load(:name=>'A', :id=>2)
|
73
|
+
@nest = <<END
|
74
|
+
n1
|
75
|
+
<%|= f.subform(:artist) do %>
|
76
|
+
n2
|
77
|
+
<%= f.input(:name2) %>
|
78
|
+
n3
|
79
|
+
<%| end %>
|
80
|
+
n4
|
81
|
+
END
|
82
|
+
erb <<END
|
83
|
+
0
|
84
|
+
<%|= form(@album, :action=>'/baz') do |f| %>
|
85
|
+
1
|
86
|
+
<%= erb(@nest, :locals=>{:f=>f}) %>
|
87
|
+
3
|
88
|
+
<%| end %>
|
89
|
+
4
|
90
|
+
END
|
91
|
+
end
|
92
|
+
|
93
|
+
r.get 'nest_seq' do
|
94
|
+
@album = Album.load(:name=>'N', :copies_sold=>2, :id=>1)
|
95
|
+
@album.associations[:artist] = Artist.load(:name=>'A', :id=>2)
|
96
|
+
@nest = <<END
|
97
|
+
n1
|
98
|
+
<%|= f.subform(:artist) do %>
|
99
|
+
n2
|
100
|
+
<%= f.input(:name2) %>
|
101
|
+
n3
|
102
|
+
<%| end %>
|
103
|
+
n4
|
104
|
+
<%= f.subform(:artist, :inputs=>[:name3], :legend=>'Bar') %>
|
105
|
+
n5
|
106
|
+
END
|
107
|
+
erb <<END
|
108
|
+
0
|
109
|
+
<%|= form(@album, :action=>'/baz') do |f| %>
|
110
|
+
1
|
111
|
+
<%= f.subform(:artist, :inputs=>[:name], :legend=>'Foo') %>
|
112
|
+
2
|
113
|
+
<%= erb(@nest, :locals=>{:f=>f}) %>
|
114
|
+
3
|
115
|
+
<%| end %>
|
116
|
+
4
|
117
|
+
END
|
118
|
+
end
|
119
|
+
|
120
|
+
r.get 'grid-block' do
|
121
|
+
@album = Album.load(:name=>'N', :copies_sold=>2, :id=>1)
|
122
|
+
@album.associations[:artist] = Artist.load(:name=>'A', :id=>2)
|
123
|
+
erb <<END
|
124
|
+
0
|
125
|
+
<%|= form(@album, {:action=>'/baz'}, :button=>'Sub') do |f| %>
|
126
|
+
1
|
127
|
+
<%|= f.subform(:artist, :inputs=>[:name], :legend=>'Foo', :grid=>true, :labels=>%w'Name') do %>
|
128
|
+
2
|
129
|
+
<%| end %>
|
130
|
+
3
|
131
|
+
<%| end %>
|
132
|
+
4
|
133
|
+
END
|
134
|
+
end
|
135
|
+
|
136
|
+
r.get 'grid-noblock' do
|
137
|
+
@album = Album.load(:name=>'N', :copies_sold=>2, :id=>1)
|
138
|
+
@album.associations[:artist] = Artist.load(:name=>'A', :id=>2)
|
139
|
+
erb <<END
|
140
|
+
0
|
141
|
+
<%|= form(@album, {:action=>'/baz'}, :button=>'Sub') do |f| %>
|
142
|
+
1
|
143
|
+
<%= f.subform(:artist, :inputs=>[:name], :legend=>'Foo', :grid=>true, :labels=>%w'Name') %>
|
144
|
+
2
|
145
|
+
<%| end %>
|
146
|
+
3
|
147
|
+
END
|
148
|
+
end
|
149
|
+
|
150
|
+
r.get 'grid-noblock-multiple' do
|
151
|
+
@artist = Artist.load(:name=>'A', :id=>2)
|
152
|
+
@artist.associations[:albums] = [Album.load(:name=>'N', :copies_sold=>2, :id=>1)]
|
153
|
+
erb <<END
|
154
|
+
0
|
155
|
+
<%|= form(@artist, {:action=>'/baz'}, :button=>'Sub') do |f| %>
|
156
|
+
1
|
157
|
+
<%= f.subform(:albums, :inputs=>[:name, :copies_sold], :legend=>'Foo', :grid=>true, :labels=>%w'Name Copies') %>
|
158
|
+
2
|
159
|
+
<%| end %>
|
160
|
+
3
|
161
|
+
END
|
162
|
+
end
|
163
|
+
|
164
|
+
r.get 'hash' do
|
165
|
+
erb "<%|= form({:action=>'/baz'}, :obj=>[:foo]) do |f| %> <%= f.input(:first) %> <%| end %>"
|
166
|
+
end
|
167
|
+
|
168
|
+
r.get 'legend' do
|
169
|
+
erb <<END
|
170
|
+
<%|= form([:foo, :bar], :action=>'/baz') do |f| %>
|
171
|
+
<p>FBB</p>
|
172
|
+
<%= f.inputs([:first, :last], :legend=>'Foo') %>
|
173
|
+
<p>FBB2</p>
|
174
|
+
<%| end %>
|
175
|
+
END
|
176
|
+
end
|
177
|
+
|
178
|
+
r.get 'combined' do
|
179
|
+
erb <<END
|
180
|
+
<%|= form([:foo, :bar], {:action=>'/baz'}, :inputs=>[:first], :button=>'xyz', :legend=>'123') do |f| %>
|
181
|
+
<p>FBB</p>
|
182
|
+
<%= f.input(:last) %>
|
183
|
+
<%| end %>
|
184
|
+
END
|
185
|
+
end
|
186
|
+
|
187
|
+
r.get 'noblock' do
|
188
|
+
erb "<%= form([:foo, :bar], {:action=>'/baz'}, :inputs=>[:first], :button=>'xyz', :legend=>'123') %>"
|
189
|
+
end
|
190
|
+
|
191
|
+
r.get 'noblock_post' do
|
192
|
+
erb "<%= form({:method=>:post}, :button=>'xyz') %>"
|
193
|
+
end
|
194
|
+
|
195
|
+
r.get 'noblock_empty' do
|
196
|
+
erb "<%= form(:action=>'/baz') %>"
|
197
|
+
end
|
198
|
+
end
|
data/spec/forme_coverage.rb
CHANGED