css3buttons 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/css3buttons/helpers/button_helper.rb +16 -2
- data/lib/css3buttons/version.rb +1 -1
- data/readme.md +29 -2
- data/spec/button_helper_spec.rb +116 -11
- metadata +4 -4
data/Gemfile.lock
CHANGED
@@ -4,11 +4,11 @@ module Css3buttons
|
|
4
4
|
include ActionView::Helpers::UrlHelper
|
5
5
|
include ActionView::Helpers::FormTagHelper
|
6
6
|
def method_missing(method, *args)
|
7
|
-
if method
|
7
|
+
if is_link_method?(method) || is_submit_method?(method) || is_button_method?(method)
|
8
8
|
qualifiers = ["primary", "big", "positive", "negative", "pill", "danger", "safe", "button"]
|
9
9
|
color_map = {"positive" => "safe", "negative" => "danger"}
|
10
10
|
|
11
|
-
method_qualifiers = method.
|
11
|
+
method_qualifiers = strip_method_name(method).split("_") + ["button"]
|
12
12
|
method_qualifiers.map! do |qualifier|
|
13
13
|
if color_map.has_key?(qualifier)
|
14
14
|
qualifier = color_map[qualifier]
|
@@ -31,6 +31,8 @@ module Css3buttons
|
|
31
31
|
|
32
32
|
if is_link_method?(method)
|
33
33
|
link_to(label, link, options)
|
34
|
+
elsif is_button_method?(method)
|
35
|
+
content_tag :button, label, { "type" => "submit", "name" => "commit", "value" => "commit" }.merge(options.stringify_keys)
|
34
36
|
else
|
35
37
|
submit_tag(label, options)
|
36
38
|
end
|
@@ -74,6 +76,18 @@ module Css3buttons
|
|
74
76
|
def is_link_method?(method)
|
75
77
|
method.to_s.index("button_link_to")
|
76
78
|
end
|
79
|
+
|
80
|
+
def is_button_method?(method)
|
81
|
+
method.to_s.index("button_tag")
|
82
|
+
end
|
83
|
+
|
84
|
+
def is_submit_method?(method)
|
85
|
+
method.to_s.index("button_submit_tag")
|
86
|
+
end
|
87
|
+
|
88
|
+
def strip_method_name(method)
|
89
|
+
method.to_s.gsub("button_link_to", "").gsub("button_tag", "").gsub("button_submit_tag", "")
|
90
|
+
end
|
77
91
|
end
|
78
92
|
end
|
79
93
|
end
|
data/lib/css3buttons/version.rb
CHANGED
data/readme.md
CHANGED
@@ -108,12 +108,39 @@ And, of course, minor groups:
|
|
108
108
|
You know the drill by now.
|
109
109
|
<% end %>
|
110
110
|
|
111
|
-
## Other stuff
|
112
111
|
|
113
|
-
Submit tags
|
112
|
+
## Submit tags, button tags and using icons on form buttons
|
113
|
+
|
114
|
+
Submit tags were ushered in with version 0.9.2. Everything works as it does above, except instead of `button_link_to` it's `button_submit_tag`. Example:
|
114
115
|
|
115
116
|
<%= positive_button_submit_tag "Publish" %>
|
116
117
|
|
118
|
+
Keep in mind however, that icons do not work on `<submit>` tags. If you're wanting to include icons in your forms there is also a helper method to insert `<button>` tags instead. The method suffix in this case is `button_tag`. Examples:
|
119
|
+
|
120
|
+
<%= approve_button_tag "Update profile" %>
|
121
|
+
<%= negative_trash_button_tag "Deactivate account" %>
|
122
|
+
|
123
|
+
|
124
|
+
# Formtastic compatibility
|
125
|
+
|
126
|
+
If you're using
|
127
|
+
[formtastic](https://github.com/justinfrench/formtastic), you may
|
128
|
+
experience issues with using css3buttons in your forms, due to the
|
129
|
+
way the built-in formtastic styles modify default form buttons. In this
|
130
|
+
instance, you can insert the following into your
|
131
|
+
`formtastic_changes.css` stylesheet.
|
132
|
+
|
133
|
+
form.formtastic input.button, form.formtastic.button.button {
|
134
|
+
height: 25px;
|
135
|
+
padding: 0.2em 1em 0.2em 2.5em;
|
136
|
+
font-family: sans-serif;
|
137
|
+
font-size: 11px;
|
138
|
+
margin-left: 5px;
|
139
|
+
}
|
140
|
+
|
141
|
+
CSS Snippet courtesy of [vitobotta](https://github.com/vitobotta).
|
142
|
+
|
143
|
+
|
117
144
|
|
118
145
|
# What's missing?
|
119
146
|
|
data/spec/button_helper_spec.rb
CHANGED
@@ -10,6 +10,8 @@ describe Css3buttons::Helpers::ButtonHelper do
|
|
10
10
|
@path = "/search/site"
|
11
11
|
end
|
12
12
|
|
13
|
+
#--- basic buttons
|
14
|
+
|
13
15
|
it "should create basic buttons" do
|
14
16
|
link = html(button_link_to(@label, @path))
|
15
17
|
|
@@ -18,15 +20,23 @@ describe Css3buttons::Helpers::ButtonHelper do
|
|
18
20
|
link.should_not have_selector("a.#{qualifier}")
|
19
21
|
end
|
20
22
|
end
|
21
|
-
|
22
23
|
it "should create basic submit buttons" do
|
23
24
|
button = html(button_submit_tag(@label))
|
24
|
-
|
25
|
+
|
25
26
|
button.should have_selector("input.button[type='submit']")
|
26
27
|
@qualifiers.each do |qualifier|
|
27
28
|
button.should_not have_selector("input.#{qualifier}")
|
28
29
|
end
|
29
30
|
end
|
31
|
+
it "should create basic button tags" do
|
32
|
+
button = html(button_tag(@label))
|
33
|
+
button.should have_selector("button.button")
|
34
|
+
@qualifiers.each do |qualifier|
|
35
|
+
button.should_not have_selector("button.#{qualifier}")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
#--- basic buttons with icons
|
30
40
|
|
31
41
|
it "should create basic buttons with valid icons" do
|
32
42
|
@icons.each do |icon|
|
@@ -34,7 +44,15 @@ describe Css3buttons::Helpers::ButtonHelper do
|
|
34
44
|
link.should have_selector("a.button.icon.#{icon}[href='#{@path}']")
|
35
45
|
end
|
36
46
|
end
|
37
|
-
|
47
|
+
it "should create basic button tags with valid icons" do
|
48
|
+
@icons.each do |icon|
|
49
|
+
button = html(send(:"#{icon}_button_tag", @label))
|
50
|
+
button.should have_selector("button.button.icon.#{icon}[type='submit']")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
#--- positive buttons
|
55
|
+
|
38
56
|
it "should create positive buttons" do
|
39
57
|
link = html(positive_button_link_to(@label, @path))
|
40
58
|
link.should have_selector("a.button.safe[href='#{@path}']")
|
@@ -42,7 +60,6 @@ describe Css3buttons::Helpers::ButtonHelper do
|
|
42
60
|
link.should_not have_selector("a.#{qualifier}") unless qualifier == "safe"
|
43
61
|
end
|
44
62
|
end
|
45
|
-
|
46
63
|
it "should create positive submit buttons" do
|
47
64
|
button = html(positive_button_submit_tag(@label))
|
48
65
|
button.should have_selector("input.button.safe[type='submit']")
|
@@ -50,6 +67,15 @@ describe Css3buttons::Helpers::ButtonHelper do
|
|
50
67
|
button.should_not have_selector("input.#{qualifier}") unless qualifier == "safe"
|
51
68
|
end
|
52
69
|
end
|
70
|
+
it "should create positive button tags" do
|
71
|
+
button = html(positive_button_tag(@label))
|
72
|
+
button.should have_selector("button.button.safe[type='submit']")
|
73
|
+
@qualifiers.each do |qualifier|
|
74
|
+
button.should_not have_selector("button.#{qualifier}") unless qualifier == "safe"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
#--- negative buttons
|
53
79
|
|
54
80
|
it "should create negative buttons" do
|
55
81
|
link = html(negative_button_link_to(@label, @path))
|
@@ -58,14 +84,22 @@ describe Css3buttons::Helpers::ButtonHelper do
|
|
58
84
|
link.should_not have_selector("a.#{qualifier}") unless qualifier == "danger"
|
59
85
|
end
|
60
86
|
end
|
61
|
-
|
62
|
-
it "should create positive submit buttons" do
|
87
|
+
it "should create negative submit buttons" do
|
63
88
|
button = html(negative_button_submit_tag(@label))
|
64
89
|
button.should have_selector("input.button.danger[type='submit']")
|
65
90
|
@qualifiers.each do |qualifier|
|
66
|
-
button.should_not have_selector("
|
91
|
+
button.should_not have_selector("input.#{qualifier}") unless qualifier == "danger"
|
67
92
|
end
|
68
93
|
end
|
94
|
+
it "should create negative button tags" do
|
95
|
+
button = html(negative_button_tag(@label))
|
96
|
+
button.should have_selector("button.button.danger[type='submit']")
|
97
|
+
@qualifiers.each do |qualifier|
|
98
|
+
button.should_not have_selector("button.#{qualifier}") unless qualifier == "danger"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
#--- positive buttons with icons
|
69
103
|
|
70
104
|
it "should create positive buttons with valid icons" do
|
71
105
|
@icons.each do |icon|
|
@@ -76,6 +110,17 @@ describe Css3buttons::Helpers::ButtonHelper do
|
|
76
110
|
end
|
77
111
|
end
|
78
112
|
end
|
113
|
+
it "should create positive button tags with valid icons" do
|
114
|
+
@icons.each do |icon|
|
115
|
+
button = html(send(:"positive_#{icon}_button_tag", @label))
|
116
|
+
button.should have_selector("button.button.safe.icon.#{icon}[type='submit']")
|
117
|
+
@qualifiers.each do |qualifier|
|
118
|
+
button.should_not have_selector("button.#{qualifier}") unless qualifier == "safe"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
#--- negative buttons with icons
|
79
124
|
|
80
125
|
it "should create negative buttons with valid icons" do
|
81
126
|
@icons.each do |icon|
|
@@ -86,6 +131,17 @@ describe Css3buttons::Helpers::ButtonHelper do
|
|
86
131
|
end
|
87
132
|
end
|
88
133
|
end
|
134
|
+
it "should create negative button tags with valid icons" do
|
135
|
+
@icons.each do |icon|
|
136
|
+
button = html(send(:"negative_#{icon}_button_tag"))
|
137
|
+
button.should have_selector("button.button.danger.icon.#{icon}[type='submit']")
|
138
|
+
@qualifiers.each do |qualifier|
|
139
|
+
button.should_not have_selector("button.#{qualifier}") unless qualifier == "danger"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
#--- pill buttons
|
89
145
|
|
90
146
|
it "should create pill buttons" do
|
91
147
|
link = html(pill_button_link_to(@label, @path))
|
@@ -94,7 +150,6 @@ describe Css3buttons::Helpers::ButtonHelper do
|
|
94
150
|
link.should_not have_selector("a.#{qualifier}") unless qualifier == "pill"
|
95
151
|
end
|
96
152
|
end
|
97
|
-
|
98
153
|
it "should create pill submit buttons" do
|
99
154
|
button = html(pill_button_submit_tag(@label))
|
100
155
|
button.should have_selector("input.button.pill[type='submit']")
|
@@ -102,6 +157,15 @@ describe Css3buttons::Helpers::ButtonHelper do
|
|
102
157
|
button.should_not have_selector("input.#{qualifier}") unless qualifier == "pill"
|
103
158
|
end
|
104
159
|
end
|
160
|
+
it "should create pill button tags" do
|
161
|
+
button = html(pill_button_tag(@label))
|
162
|
+
button.should have_selector("button.button.pill[type='submit']")
|
163
|
+
@qualifiers.each do |qualifier|
|
164
|
+
button.should_not have_selector("button.#{qualifier}") unless qualifier == "pill"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
#--- pill buttons with icons
|
105
169
|
|
106
170
|
it "should create pill buttons with valid icons" do
|
107
171
|
@icons.each do |icon|
|
@@ -112,30 +176,53 @@ describe Css3buttons::Helpers::ButtonHelper do
|
|
112
176
|
end
|
113
177
|
end
|
114
178
|
end
|
179
|
+
it "should create pill button tags with valid icons" do
|
180
|
+
@icons.each do |icon|
|
181
|
+
button = html(send(:"pill_#{icon}_button_tag", @label))
|
182
|
+
button.should have_selector("button.button.pill.icon.#{icon}[type='submit']")
|
183
|
+
@qualifiers.each do |qualifier|
|
184
|
+
button.should_not have_selector("button.#{qualifier}") unless qualifier == "pill"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
#--- positive pill buttons
|
115
190
|
|
116
191
|
it "should create positive pill buttons" do
|
117
192
|
link = html(positive_pill_button_link_to(@label, @path))
|
118
193
|
link.should have_selector("a.button.pill.safe[href='#{@path}']")
|
119
194
|
link.should_not have_selector("a.danger")
|
120
195
|
end
|
121
|
-
|
122
196
|
it "should create positive pill submit buttons" do
|
123
197
|
button = html(positive_pill_button_submit_tag(@label))
|
124
198
|
button.should have_selector("input.button.pill.safe[type='submit']")
|
125
199
|
button.should_not have_selector("input.danger")
|
126
200
|
end
|
201
|
+
it "should create positive pill button tags" do
|
202
|
+
button = html(positive_pill_button_tag(@label))
|
203
|
+
button.should have_selector("button.button.pill.safe[type='submit']")
|
204
|
+
button.should_not have_selector("button.danger")
|
205
|
+
end
|
206
|
+
|
207
|
+
#--- negative pill buttons
|
127
208
|
|
128
209
|
it "should create negative pill buttons" do
|
129
210
|
link = html(negative_pill_button_link_to(@label, @path))
|
130
211
|
link.should have_selector("a.button.pill.danger[href='#{@path}']")
|
131
212
|
link.should_not have_selector("a.safe")
|
132
213
|
end
|
133
|
-
|
134
214
|
it "should create negative pill submit buttons" do
|
135
215
|
button = html(negative_pill_button_submit_tag(@label))
|
136
216
|
button.should have_selector("input.button.pill.danger[type='submit']")
|
137
217
|
button.should_not have_selector("input.safe")
|
138
218
|
end
|
219
|
+
it "should create negative pill button tags" do
|
220
|
+
button = html(negative_pill_button_tag(@label))
|
221
|
+
button.should have_selector("button.button.pill.danger[type='submit']")
|
222
|
+
button.should_not have_selector("button.safe")
|
223
|
+
end
|
224
|
+
|
225
|
+
#--- positive pill buttons with icons
|
139
226
|
|
140
227
|
it "should create positive pill buttons with valid icons" do
|
141
228
|
@icons.each do |icon|
|
@@ -144,14 +231,32 @@ describe Css3buttons::Helpers::ButtonHelper do
|
|
144
231
|
link.should_not have_selector("a.danger")
|
145
232
|
end
|
146
233
|
end
|
234
|
+
it "should create positive pill button tags with valid icons" do
|
235
|
+
@icons.each do |icon|
|
236
|
+
button = html(send(:"positive_pill_#{icon}_button_tag", @label))
|
237
|
+
button.should have_selector("button.button.safe.pill.icon.#{icon}[type='submit']")
|
238
|
+
button.should_not have_selector("button.danger")
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
#--- negative pill buttons with icons
|
147
243
|
|
148
244
|
it "should create negative pill buttons with valid icons" do
|
149
245
|
@icons.each do |icon|
|
150
246
|
link = html(send(:"negative_pill_#{icon}_button_link_to", @label, @path))
|
151
247
|
link.should have_selector("a.button.danger.pill.icon.#{icon}[href='#{@path}']")
|
152
|
-
link.should_not have_selector("a.
|
248
|
+
link.should_not have_selector("a.safe")
|
153
249
|
end
|
154
250
|
end
|
251
|
+
it "should create negative pill button tags with valid icons" do
|
252
|
+
@icons.each do |icon|
|
253
|
+
button = html(send(:"negative_pill_#{icon}_button_tag", @label))
|
254
|
+
button.should have_selector("button.button.danger.pill.icon.#{icon}[type='submit']")
|
255
|
+
button.should_not have_selector("button.safe")
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
#--- end
|
155
260
|
|
156
261
|
def html(text)
|
157
262
|
Capybara::string(text)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: css3buttons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 51
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 4
|
10
|
+
version: 0.9.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nicholas Bruning
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-05-03 00:00:00 +10:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|