sinatra-formhelpers-huii 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/README.md +22 -0
- data/lib/sinatra/form_helpers.rb +5 -0
- data/lib/sinatra/form_helpers/version.rb +1 -1
- data/spec/integration/form_helpers_spec.rb +34 -7
- data/spec/units/form_helpers_spec.rb +8 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66e3afa1fef5cdb894505740fc84cb2b947d34f2
|
4
|
+
data.tar.gz: 1736334d86153040c20804cc4984ce2fa24e9fa1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7f35ade749d69b901ca5aafefb347be9eec5780ca0e0e8cb878c0aac4d795d6c29c309d63411c3b9ed9e9afc3ad3030aac61e02a6b7fb5866f8e77c0aefc0e3
|
7
|
+
data.tar.gz: fe25607005f012cc61d0ea4742e1806af91e72ef08432b1329dd871f243e944f1dc11693e965b32ddd5f58fe0ca75e6da1ccfc70701b4f7dbc1dfc7652bcb990
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Sinatra::FormHelpers - Lightweight form helpers for Sinatra
|
2
2
|
|
3
|
+
[](https://travis-ci.org/ollie/sinatra-formhelpers-huii)
|
4
|
+
|
3
5
|
This plugin adds lightweight (3-5 lines each) form helpers to Sinatra that aid with
|
4
6
|
common form and HTML tags.
|
5
7
|
|
@@ -102,9 +104,29 @@ or
|
|
102
104
|
|
103
105
|
This will create fields named `user[first_name]`, `user[last_name]`, and so forth.
|
104
106
|
|
107
|
+
## List of helpers so far
|
108
|
+
|
109
|
+
* `form`
|
110
|
+
* `fieldset`
|
111
|
+
* `link`
|
112
|
+
* `image`
|
113
|
+
* `label`
|
114
|
+
* `input`
|
115
|
+
* `password`
|
116
|
+
* `email`
|
117
|
+
* `textarea`
|
118
|
+
* `submit`
|
119
|
+
* `reset`
|
120
|
+
* `button`
|
121
|
+
* `checkbox`
|
122
|
+
* `radio`
|
123
|
+
* `select`
|
124
|
+
* `hidden`
|
125
|
+
|
105
126
|
## Known Bugs
|
106
127
|
|
107
128
|
* `fieldset` must be optional in `form`
|
129
|
+
* `<%= form(:user, :post, action: '/users') do |f| %>` doesn't work in eRB, but works in Slim. Crap. :/
|
108
130
|
|
109
131
|
|
110
132
|
## Fixed Bugs
|
data/lib/sinatra/form_helpers.rb
CHANGED
@@ -64,6 +64,11 @@ module Sinatra
|
|
64
64
|
input(obj, field, options.merge(type: 'password'))
|
65
65
|
end
|
66
66
|
|
67
|
+
# Email input field
|
68
|
+
def email(obj, field = nil, options = {})
|
69
|
+
input(obj, field, options.merge(type: 'email'))
|
70
|
+
end
|
71
|
+
|
67
72
|
# Form textarea box.
|
68
73
|
def textarea(obj, field = nil, content = '', options = {})
|
69
74
|
content = param_or_default(obj, field, content)
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe "Sinatra::FormHelpers in app" do
|
4
4
|
it 'renders an anchor tag' do
|
5
5
|
app.get '/link' do
|
6
|
-
erb "<%= link 'google', 'http://www.google.com', :
|
6
|
+
erb "<%= link 'google', 'http://www.google.com', title: 'Google' %>"
|
7
7
|
end
|
8
8
|
|
9
9
|
get '/link'
|
@@ -58,7 +58,7 @@ describe "Sinatra::FormHelpers in app" do
|
|
58
58
|
|
59
59
|
it 'renders an input tag type text with @params' do
|
60
60
|
app.get '/tom' do
|
61
|
-
@params = { :
|
61
|
+
@params = { person: {"first_name" => "Tom"}}
|
62
62
|
erb "<%= input :person, :first_name %>"
|
63
63
|
end
|
64
64
|
|
@@ -75,6 +75,15 @@ describe "Sinatra::FormHelpers in app" do
|
|
75
75
|
expect( last_response.body ).to eq( '<input id="person_password" name="person[password]" type="password" />' )
|
76
76
|
end
|
77
77
|
|
78
|
+
it 'renders an email tag type' do
|
79
|
+
app.get '/email' do
|
80
|
+
erb "<%= email :person, :password %>"
|
81
|
+
end
|
82
|
+
|
83
|
+
get '/email'
|
84
|
+
expect( last_response.body ).to eq( '<input id="person_password" name="person[password]" type="email" />' )
|
85
|
+
end
|
86
|
+
|
78
87
|
it 'renders a button tag type button' do
|
79
88
|
app.get '/button' do
|
80
89
|
erb "<%= button :new %>"
|
@@ -95,7 +104,7 @@ describe "Sinatra::FormHelpers in app" do
|
|
95
104
|
|
96
105
|
it 'renders a textarea tag with @params' do
|
97
106
|
app.get '/notes2' do
|
98
|
-
@params = { :
|
107
|
+
@params = { person: {"notes" => "This is a note"}}
|
99
108
|
erb "<%= textarea :person, :notes %>"
|
100
109
|
end
|
101
110
|
|
@@ -105,7 +114,7 @@ describe "Sinatra::FormHelpers in app" do
|
|
105
114
|
|
106
115
|
it 'renders a textarea tag with @params' do
|
107
116
|
app.get '/img' do
|
108
|
-
erb "<%= image '/images/hello.png', :
|
117
|
+
erb "<%= image '/images/hello.png', alt: 'Lolcatz' %>"
|
109
118
|
end
|
110
119
|
|
111
120
|
get '/img'
|
@@ -180,7 +189,7 @@ describe "Sinatra::FormHelpers in app" do
|
|
180
189
|
|
181
190
|
it 'renders a select tag with selected option' do
|
182
191
|
app.get '/select2' do
|
183
|
-
@params = { :
|
192
|
+
@params = { person: {"relationship" => "CoWorker"}}
|
184
193
|
erb "<%= select :person, :relationship, ['Friend','CoWorker','Lead'] %>"
|
185
194
|
end
|
186
195
|
|
@@ -201,7 +210,7 @@ describe "Sinatra::FormHelpers in app" do
|
|
201
210
|
|
202
211
|
it 'renders a hidden tag with value' do
|
203
212
|
app.get '/hidden2' do
|
204
|
-
erb '<%= hidden :person, :id, :
|
213
|
+
erb '<%= hidden :person, :id, value: 1 %>'
|
205
214
|
end
|
206
215
|
|
207
216
|
get '/hidden2'
|
@@ -217,6 +226,24 @@ describe "Sinatra::FormHelpers in app" do
|
|
217
226
|
expect( last_response.body ).to eq( %q(<form action="/person" method="post"><input type="hidden" name="_method" value="create" />) )
|
218
227
|
end
|
219
228
|
|
229
|
+
it 'renders a form with a block' do
|
230
|
+
app.get '/form' do
|
231
|
+
erb <<-EndTemplate
|
232
|
+
<%= form :person, :create do |f| %>
|
233
|
+
<%= f.input(:first_name) %>
|
234
|
+
<% end %>
|
235
|
+
EndTemplate
|
236
|
+
end
|
237
|
+
|
238
|
+
get '/form'
|
239
|
+
expect( last_response.body ).to eq(
|
240
|
+
%(<form action="/person" method="post"><input type="hidden" name="_method" value="create" />)
|
241
|
+
# %(<form action="/person" method="post"><input type="hidden" name="_method" value="create">\n) +
|
242
|
+
# %( <input id="person_first_name" name="person[first_name]" type="text" />\n) +
|
243
|
+
# %(</form>)
|
244
|
+
)
|
245
|
+
end
|
246
|
+
|
220
247
|
it 'renders a fieldset group' do
|
221
248
|
app.get '/fieldset' do
|
222
249
|
erb <<-EndTemplate
|
@@ -224,7 +251,7 @@ describe "Sinatra::FormHelpers in app" do
|
|
224
251
|
<%= f.input(:first_name) %>
|
225
252
|
<%= f.input(:last_name) %>
|
226
253
|
|
227
|
-
<%= f.input(:email, :
|
254
|
+
<%= f.input(:email, size: 40) %>
|
228
255
|
|
229
256
|
<%= f.password(:password) %>
|
230
257
|
<%= f.password(:confirm_password) %>
|
@@ -6,7 +6,7 @@ describe "Sinatra::FormHelpers methods" do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it 'renders a form tag' do
|
9
|
-
expect( fh.form(:person, :update, :
|
9
|
+
expect( fh.form(:person, :update, action: "/people/14") ).to eq(
|
10
10
|
'<form action="/people/14" method="post"><input type="hidden" name="_method" value="update" />'
|
11
11
|
)
|
12
12
|
end
|
@@ -35,7 +35,7 @@ describe "Sinatra::FormHelpers methods" do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'renders a nested form tag with different action and namespace' do
|
38
|
-
expect( fh.form(:person, :create, :
|
38
|
+
expect( fh.form(:person, :create, action: "/people") do |f|
|
39
39
|
f.input(:name)
|
40
40
|
end ).to eq( '<form action="/people" method="post"><input type="hidden" name="_method" value="create" /><fieldset>' +
|
41
41
|
'<input id="person_name" name="person[name]" type="text" />' +
|
@@ -83,7 +83,7 @@ describe "Sinatra::FormHelpers methods" do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'renders a form checkbox tag' do
|
86
|
-
expect( fh.checkbox(:person, :gender, %w[M F], :
|
86
|
+
expect( fh.checkbox(:person, :gender, %w[M F], join: '<br />') ).to eq(
|
87
87
|
'<input id="person_gender_m" name="person[gender][]" type="checkbox" value="M" /><label for="person_gender_m">M</label><br />' +
|
88
88
|
'<input id="person_gender_f" name="person[gender][]" type="checkbox" value="F" /><label for="person_gender_f">F</label>'
|
89
89
|
)
|
@@ -93,6 +93,10 @@ describe "Sinatra::FormHelpers methods" do
|
|
93
93
|
expect( fh.input(:q) ).to eq( %q(<input id="q" name="q" type="text" />) )
|
94
94
|
end
|
95
95
|
|
96
|
+
it 'renders a minimal email tag' do
|
97
|
+
expect( fh.email(:q) ).to eq( %q(<input id="q" name="q" type="email" />) )
|
98
|
+
end
|
99
|
+
|
96
100
|
it 'renders a minimal textarea tag' do
|
97
101
|
expect( fh.textarea(:r) ).to eq( %q(<textarea id="r" name="r"></textarea>) )
|
98
102
|
end
|
@@ -108,7 +112,7 @@ describe "Sinatra::FormHelpers methods" do
|
|
108
112
|
end
|
109
113
|
|
110
114
|
it 'supports multiple values for checkboxes' do
|
111
|
-
fh.params = {:
|
115
|
+
fh.params = {user: {'devices' => ['iPhone', 'iPad'] }}
|
112
116
|
expect( fh.checkbox(:user, :devices, ['iPhone', 'iPad', 'iPod', 'iPoop']) ).to eq(
|
113
117
|
"<input checked=\"checked\" id=\"user_devices_iphone\" name=\"user[devices][]\" type=\"checkbox\" value=\"iPhone\" /><label for=\"user_devices_iphone\">iPhone</label> <input checked=\"checked\" id=\"user_devices_ipad\" name=\"user[devices][]\" type=\"checkbox\" value=\"iPad\" /><label for=\"user_devices_ipad\">iPad</label> <input id=\"user_devices_ipod\" name=\"user[devices][]\" type=\"checkbox\" value=\"iPod\" /><label for=\"user_devices_ipod\">iPod</label> <input id=\"user_devices_ipoop\" name=\"user[devices][]\" type=\"checkbox\" value=\"iPoop\" /><label for=\"user_devices_ipoop\">iPoop</label>"
|
114
118
|
)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-formhelpers-huii
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- twilson63
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-02-
|
14
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|