sinatra-formhelpers-huii 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a61ee9d516ea9200d8e977cf6c13e7dea468db16
4
- data.tar.gz: f770b7739bdded37177de9783bd3f4281403c9e2
3
+ metadata.gz: 66e3afa1fef5cdb894505740fc84cb2b947d34f2
4
+ data.tar.gz: 1736334d86153040c20804cc4984ce2fa24e9fa1
5
5
  SHA512:
6
- metadata.gz: 59bbde3ec8d1d62815c25081148a98294efc52deb8aa9b7684d8ea3d7213dd28d9c53ce80ea6f7e9138cc6bffa2cbbcf695ffde1fdfe1378189a5e5748e7049e
7
- data.tar.gz: 9eda4ae2240719dabad399327cb92a5eff5ce7a84ba5bab8eaa1f9ffe817d0e287905ef51ac6b5d98912f79f5c55ad10519ed15e08e76348e0414f42a6fa7c2b
6
+ metadata.gz: b7f35ade749d69b901ca5aafefb347be9eec5780ca0e0e8cb878c0aac4d795d6c29c309d63411c3b9ed9e9afc3ad3030aac61e02a6b7fb5866f8e77c0aefc0e3
7
+ data.tar.gz: fe25607005f012cc61d0ea4742e1806af91e72ef08432b1329dd871f243e944f1dc11693e965b32ddd5f58fe0ca75e6da1ccfc70701b4f7dbc1dfc7652bcb990
data/.travis.yml CHANGED
@@ -8,4 +8,9 @@ branches:
8
8
  only:
9
9
  - master
10
10
 
11
+ notifications:
12
+ email:
13
+ on_success: change
14
+ on_failure: always
15
+
11
16
  install: "bundle --jobs 4"
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Sinatra::FormHelpers - Lightweight form helpers for Sinatra
2
2
 
3
+ [![Build Status](https://travis-ci.org/ollie/sinatra-formhelpers-huii.png?branch=master)](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
@@ -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)
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module FormHelpers
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
@@ -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', :title => 'Google' %>"
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 = { :person => {"first_name" => "Tom"}}
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 = { :person => {"notes" => "This is a note"}}
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', :alt => 'Lolcatz' %>"
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 = { :person => {"relationship" => "CoWorker"}}
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, :value => 1 %>'
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, :size => 40) %>
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, :action => "/people/14") ).to eq(
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, :action => "/people") do |f|
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], :join => '<br />') ).to eq(
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 = {:user => {'devices' => ['iPhone', 'iPad'] }}
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.1
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-12 00:00:00.000000000 Z
14
+ date: 2014-02-17 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler