swiss_knife 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/Gemfile +1 -9
- data/Gemfile.lock +54 -60
- data/lib/swiss_knife/helpers.rb +103 -46
- data/lib/swiss_knife/version.rb +1 -1
- data/spec/helpers/helpers_spec.rb +104 -83
- data/spec/spec_helper.rb +2 -0
- data/swiss_knife.gemspec +4 -2
- metadata +31 -24
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--format=documentation
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,95 +1,90 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
swiss_knife (0.1.5)
|
5
|
+
rails (~> 3.0.0)
|
6
|
+
|
1
7
|
GEM
|
2
8
|
remote: http://rubygems.org/
|
3
9
|
specs:
|
4
10
|
abstract (1.0.0)
|
5
|
-
actionmailer (3.0.
|
6
|
-
actionpack (= 3.0.
|
7
|
-
mail (~> 2.2.
|
8
|
-
actionpack (3.0.
|
9
|
-
activemodel (= 3.0.
|
10
|
-
activesupport (= 3.0.
|
11
|
+
actionmailer (3.0.5)
|
12
|
+
actionpack (= 3.0.5)
|
13
|
+
mail (~> 2.2.15)
|
14
|
+
actionpack (3.0.5)
|
15
|
+
activemodel (= 3.0.5)
|
16
|
+
activesupport (= 3.0.5)
|
11
17
|
builder (~> 2.1.2)
|
12
18
|
erubis (~> 2.6.6)
|
13
19
|
i18n (~> 0.4)
|
14
20
|
rack (~> 1.2.1)
|
15
21
|
rack-mount (~> 0.6.13)
|
16
|
-
rack-test (~> 0.5.
|
22
|
+
rack-test (~> 0.5.7)
|
17
23
|
tzinfo (~> 0.3.23)
|
18
|
-
activemodel (3.0.
|
19
|
-
activesupport (= 3.0.
|
24
|
+
activemodel (3.0.5)
|
25
|
+
activesupport (= 3.0.5)
|
20
26
|
builder (~> 2.1.2)
|
21
27
|
i18n (~> 0.4)
|
22
|
-
activerecord (3.0.
|
23
|
-
activemodel (= 3.0.
|
24
|
-
activesupport (= 3.0.
|
28
|
+
activerecord (3.0.5)
|
29
|
+
activemodel (= 3.0.5)
|
30
|
+
activesupport (= 3.0.5)
|
25
31
|
arel (~> 2.0.2)
|
26
32
|
tzinfo (~> 0.3.23)
|
27
|
-
activeresource (3.0.
|
28
|
-
activemodel (= 3.0.
|
29
|
-
activesupport (= 3.0.
|
30
|
-
activesupport (3.0.
|
31
|
-
|
32
|
-
arel (2.0.4)
|
33
|
+
activeresource (3.0.5)
|
34
|
+
activemodel (= 3.0.5)
|
35
|
+
activesupport (= 3.0.5)
|
36
|
+
activesupport (3.0.5)
|
37
|
+
arel (2.0.9)
|
33
38
|
builder (2.1.2)
|
34
|
-
columnize (0.3.2)
|
35
39
|
diff-lcs (1.1.2)
|
36
40
|
erubis (2.6.6)
|
37
41
|
abstract (>= 1.0.0)
|
38
42
|
fakeweb (1.3.0)
|
39
|
-
i18n (0.
|
40
|
-
|
41
|
-
ruby_core_source (>= 0.1.4)
|
42
|
-
mail (2.2.10)
|
43
|
+
i18n (0.5.0)
|
44
|
+
mail (2.2.15)
|
43
45
|
activesupport (>= 2.3.6)
|
44
|
-
i18n (
|
46
|
+
i18n (>= 0.4.0)
|
45
47
|
mime-types (~> 1.16)
|
46
48
|
treetop (~> 1.4.8)
|
47
49
|
mime-types (1.16)
|
48
|
-
nokogiri (1.4.
|
50
|
+
nokogiri (1.4.4)
|
49
51
|
polyglot (0.3.1)
|
50
52
|
rack (1.2.1)
|
51
53
|
rack-mount (0.6.13)
|
52
54
|
rack (>= 1.0.0)
|
53
|
-
rack-test (0.5.
|
55
|
+
rack-test (0.5.7)
|
54
56
|
rack (>= 1.0)
|
55
|
-
rails (3.0.
|
56
|
-
actionmailer (= 3.0.
|
57
|
-
actionpack (= 3.0.
|
58
|
-
activerecord (= 3.0.
|
59
|
-
activeresource (= 3.0.
|
60
|
-
activesupport (= 3.0.
|
57
|
+
rails (3.0.5)
|
58
|
+
actionmailer (= 3.0.5)
|
59
|
+
actionpack (= 3.0.5)
|
60
|
+
activerecord (= 3.0.5)
|
61
|
+
activeresource (= 3.0.5)
|
62
|
+
activesupport (= 3.0.5)
|
61
63
|
bundler (~> 1.0)
|
62
|
-
railties (= 3.0.
|
63
|
-
railties (3.0.
|
64
|
-
actionpack (= 3.0.
|
65
|
-
activesupport (= 3.0.
|
64
|
+
railties (= 3.0.5)
|
65
|
+
railties (3.0.5)
|
66
|
+
actionpack (= 3.0.5)
|
67
|
+
activesupport (= 3.0.5)
|
66
68
|
rake (>= 0.8.7)
|
67
69
|
thor (~> 0.14.4)
|
68
70
|
rake (0.8.7)
|
69
|
-
rspec (2.
|
70
|
-
rspec-core (~> 2.
|
71
|
-
rspec-expectations (~> 2.
|
72
|
-
rspec-mocks (~> 2.
|
73
|
-
rspec-core (2.1
|
74
|
-
rspec-expectations (2.
|
71
|
+
rspec (2.5.0)
|
72
|
+
rspec-core (~> 2.5.0)
|
73
|
+
rspec-expectations (~> 2.5.0)
|
74
|
+
rspec-mocks (~> 2.5.0)
|
75
|
+
rspec-core (2.5.1)
|
76
|
+
rspec-expectations (2.5.0)
|
75
77
|
diff-lcs (~> 1.1.2)
|
76
|
-
rspec-mocks (2.
|
77
|
-
rspec-rails (2.
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
ruby_core_source (>= 0.1.4)
|
83
|
-
ruby-debug19 (0.11.6)
|
84
|
-
columnize (>= 0.3.1)
|
85
|
-
linecache19 (>= 0.5.11)
|
86
|
-
ruby-debug-base19 (>= 0.11.19)
|
87
|
-
ruby_core_source (0.1.4)
|
88
|
-
archive-tar-minitar (>= 0.5.2)
|
78
|
+
rspec-mocks (2.5.0)
|
79
|
+
rspec-rails (2.5.0)
|
80
|
+
actionpack (~> 3.0)
|
81
|
+
activesupport (~> 3.0)
|
82
|
+
railties (~> 3.0)
|
83
|
+
rspec (~> 2.5.0)
|
89
84
|
thor (0.14.6)
|
90
|
-
treetop (1.4.
|
85
|
+
treetop (1.4.9)
|
91
86
|
polyglot (>= 0.3.1)
|
92
|
-
tzinfo (0.3.
|
87
|
+
tzinfo (0.3.24)
|
93
88
|
|
94
89
|
PLATFORMS
|
95
90
|
ruby
|
@@ -97,6 +92,5 @@ PLATFORMS
|
|
97
92
|
DEPENDENCIES
|
98
93
|
fakeweb
|
99
94
|
nokogiri
|
100
|
-
rails (
|
101
|
-
|
102
|
-
ruby-debug19
|
95
|
+
rspec-rails (~> 2.5.0)
|
96
|
+
swiss_knife!
|
data/lib/swiss_knife/helpers.rb
CHANGED
@@ -49,17 +49,24 @@ module SwissKnife
|
|
49
49
|
image_tag url, { :class => "gravatar", :alt => options[:alt], :title => options[:title] }
|
50
50
|
end
|
51
51
|
|
52
|
+
# Display flash messages.
|
53
|
+
#
|
54
|
+
# flash_messages
|
55
|
+
# #=> '<p class="message alert">This is just an alert!</p>
|
56
|
+
#
|
52
57
|
def flash_messages
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
+
safe_buffer do |html|
|
59
|
+
flash.each do |name, message|
|
60
|
+
html << content_tag(:p, message, :class => "message #{name}")
|
61
|
+
flash.discard(name)
|
62
|
+
end
|
58
63
|
end
|
59
|
-
|
60
|
-
html.html_safe
|
61
64
|
end
|
62
65
|
|
66
|
+
# Create a meta tag for http://github.com/fnando/dispatcher-js.
|
67
|
+
#
|
68
|
+
# <%= dispatcher %>
|
69
|
+
#
|
63
70
|
def dispatcher_tag
|
64
71
|
controller_name = controller.class.name.underscore
|
65
72
|
controller_name.gsub!(/\//, "_")
|
@@ -68,12 +75,29 @@ module SwissKnife
|
|
68
75
|
%[<meta name="page" content="#{controller_name}##{controller.action_name}" />].html_safe
|
69
76
|
end
|
70
77
|
|
78
|
+
# Wrap the content in a <BODY> tag.
|
79
|
+
#
|
80
|
+
# <%= body do %>
|
81
|
+
# <h1>Hi there!</h1>
|
82
|
+
# <% end %>
|
83
|
+
#
|
84
|
+
# This will set some attributes like <tt>id</tt> and <tt>class</tt>,
|
85
|
+
# with controller and action name.
|
86
|
+
#
|
87
|
+
# You can set additional CSS classes by using the <tt>:append_class</tt> option.
|
88
|
+
#
|
89
|
+
# body(:append_class => "theme-red") { ...some content }
|
90
|
+
#
|
71
91
|
def body(options = {}, &block)
|
72
92
|
action_name = ACTION_ALIASES[controller.action_name] || controller.action_name
|
73
93
|
|
74
94
|
options = {
|
75
95
|
:id => "#{controller.controller_name}-page",
|
76
|
-
:class =>
|
96
|
+
:class => [
|
97
|
+
"#{controller.controller_name}-#{action_name}",
|
98
|
+
"#{controller.controller_name}-#{controller.action_name}",
|
99
|
+
I18n.locale
|
100
|
+
].join(" ")
|
77
101
|
}.merge(options)
|
78
102
|
|
79
103
|
options[:class] << (" " + options.delete(:append_class).to_s) if options[:append_class]
|
@@ -113,6 +137,12 @@ module SwissKnife
|
|
113
137
|
content_tag(tag, capture(&block), options)
|
114
138
|
end
|
115
139
|
|
140
|
+
# Create a encrypted mailto link.
|
141
|
+
# <b>THIS API IS NOT RAILS COMPLIANT.</b>
|
142
|
+
#
|
143
|
+
# mail_to "john@doe.com"
|
144
|
+
# mail_to "john@doe.com", "Contact me"
|
145
|
+
#
|
116
146
|
def mail_to(email, label = nil)
|
117
147
|
encrypt = proc do |text|
|
118
148
|
text.to_enum(:each_byte).collect {|c| sprintf("&#%d;", c) }.join
|
@@ -126,44 +156,42 @@ module SwissKnife
|
|
126
156
|
|
127
157
|
def javascript_includes(*args)
|
128
158
|
options = args.extract_options!
|
129
|
-
html = ""
|
130
|
-
|
131
|
-
args.each do |name|
|
132
|
-
bundle = SwissKnife::Assets.config["javascripts"][name.to_s] rescue nil
|
133
159
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
160
|
+
safe_buffer do |html|
|
161
|
+
args.each do |name|
|
162
|
+
bundle = SwissKnife::Assets.config["javascripts"][name.to_s] rescue nil
|
163
|
+
|
164
|
+
if SwissKnife::Assets.merge? && bundle
|
165
|
+
html << javascript_include_tag("#{name}_packaged".html_safe, options)
|
166
|
+
elsif bundle
|
167
|
+
bundle.each do |file|
|
168
|
+
html << javascript_include_tag(file.to_s.html_safe, options)
|
169
|
+
end
|
170
|
+
else
|
171
|
+
html << javascript_include_tag(name.to_s.html_safe, options)
|
139
172
|
end
|
140
|
-
else
|
141
|
-
html << javascript_include_tag(name.to_s.html_safe, options)
|
142
173
|
end
|
143
174
|
end
|
144
|
-
|
145
|
-
html.html_safe
|
146
175
|
end
|
147
176
|
|
148
177
|
def stylesheet_includes(*args)
|
149
178
|
options = args.extract_options!
|
150
|
-
html = ""
|
151
179
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
bundle
|
159
|
-
|
180
|
+
safe_buffer do |html|
|
181
|
+
args.each do |name|
|
182
|
+
bundle = SwissKnife::Assets.config["stylesheets"][name.to_s] rescue nil
|
183
|
+
|
184
|
+
if SwissKnife::Assets.merge? && bundle
|
185
|
+
html << stylesheet_link_tag("#{name}_packaged", options)
|
186
|
+
elsif bundle
|
187
|
+
bundle.each do |file|
|
188
|
+
html << stylesheet_link_tag("#{file}", options)
|
189
|
+
end
|
190
|
+
else
|
191
|
+
html << stylesheet_link_tag("#{name}", options)
|
160
192
|
end
|
161
|
-
else
|
162
|
-
html << stylesheet_link_tag("#{name}", options)
|
163
193
|
end
|
164
194
|
end
|
165
|
-
|
166
|
-
html.html_safe
|
167
195
|
end
|
168
196
|
|
169
197
|
def fieldset(legend, options = {}, &block)
|
@@ -187,11 +215,11 @@ module SwissKnife
|
|
187
215
|
def submit_or_cancel(url, options = {})
|
188
216
|
options.reverse_merge!(:button => :"swiss_knife.submit", :cancel => :"swiss_knife.cancel")
|
189
217
|
|
190
|
-
|
218
|
+
safe_buffer do |html|
|
191
219
|
html << submit_tag(t(options[:button], :default => options[:button]), :class => "button")
|
192
220
|
html << " "
|
193
221
|
html << link_to(t(options[:cancel], :default => options[:cancel]), url, :class => "cancel")
|
194
|
-
end
|
222
|
+
end
|
195
223
|
end
|
196
224
|
|
197
225
|
# Load jQuery from Google's CDN and if the world is collapsing and Google is down,
|
@@ -205,16 +233,45 @@ module SwissKnife
|
|
205
233
|
def jquery_script_tag(version = "1.4.4")
|
206
234
|
local_path = compute_public_path("jquery-#{version}.min.js", "javascripts")
|
207
235
|
remote_path = "#{request.protocol}ajax.googleapis.com/ajax/libs/jquery/#{version}/jquery.min.js"
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
236
|
+
|
237
|
+
safe_buffer do
|
238
|
+
%[
|
239
|
+
<script type="text/javascript" src="#{remote_path}"></script>
|
240
|
+
<script type="text/javascript">
|
241
|
+
if (typeof jQuery === "undefined") {
|
242
|
+
document.write(unescape("%3Cscript src='#{local_path}' type='text/javascript'%3E%3C/script%3E"));
|
243
|
+
};
|
244
|
+
</script>
|
245
|
+
]
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
# Return a string marked as safe html.
|
250
|
+
#
|
251
|
+
# Change the buffer object when block expects one argument.
|
252
|
+
#
|
253
|
+
# safe_buffer {|html| html << "<p>Some content</p>"}
|
254
|
+
#
|
255
|
+
# Use block's return when block expects no argument.
|
256
|
+
#
|
257
|
+
# safe_buffer { "<p>Some content</p>" }
|
258
|
+
#
|
259
|
+
# Get a safe buffer object.
|
260
|
+
#
|
261
|
+
# buffer = safe_buffer
|
262
|
+
#
|
263
|
+
def safe_buffer(&block)
|
264
|
+
buffer = ActiveSupport::SafeBuffer.new
|
265
|
+
|
266
|
+
if block_given?
|
267
|
+
if block.arity == 1
|
268
|
+
yield buffer
|
269
|
+
else
|
270
|
+
buffer = yield(buffer)
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
buffer.html_safe
|
218
275
|
end
|
219
276
|
end
|
220
277
|
end
|
data/lib/swiss_knife/version.rb
CHANGED
@@ -17,6 +17,8 @@ describe SwissKnife::Helpers do
|
|
17
17
|
|
18
18
|
subject { helper.flash_messages }
|
19
19
|
|
20
|
+
it { should be_html_safe }
|
21
|
+
|
20
22
|
it "should render multiple flash messages" do
|
21
23
|
subject.should have_tag("p.message", :count => 3)
|
22
24
|
end
|
@@ -36,41 +38,50 @@ describe SwissKnife::Helpers do
|
|
36
38
|
|
37
39
|
describe "block wrappers" do
|
38
40
|
context "body" do
|
39
|
-
|
40
|
-
html = helper.body { "Body" }
|
41
|
+
subject { helper.body { "Body" } }
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
it { should be_html_safe }
|
44
|
+
|
45
|
+
it "should use defaults" do
|
46
|
+
subject.should have_tag("body", :count => 1)
|
47
|
+
subject.should have_tag("body#sample-page")
|
48
|
+
subject.should have_tag("body.sample-index")
|
49
|
+
subject.should have_tag("body.en")
|
46
50
|
end
|
47
51
|
|
48
|
-
it "should use alias for action" do
|
52
|
+
it "should use alias for create action" do
|
49
53
|
@controller.stub(:action_name => "create")
|
50
|
-
helper.body { "Body" }
|
54
|
+
html = helper.body { "Body" }
|
55
|
+
|
56
|
+
html.should have_tag("body.sample-new")
|
57
|
+
html.should have_tag("body.sample-create")
|
58
|
+
end
|
51
59
|
|
60
|
+
it "should use alias for update action" do
|
52
61
|
@controller.stub(:action_name => "update")
|
53
62
|
helper.body { "Body" }.should have_tag("body.sample-edit")
|
63
|
+
end
|
54
64
|
|
65
|
+
it "should use alias for delete action" do
|
55
66
|
@controller.stub(:action_name => "destroy")
|
56
67
|
helper.body { "Body" }.should have_tag("body.sample-destroy")
|
57
68
|
end
|
58
69
|
|
59
70
|
it "should use custom settings" do
|
60
|
-
|
71
|
+
subject = helper.body(:id => "page", :class => "dark", :onload => "init();") { "Body" }
|
61
72
|
|
62
|
-
|
63
|
-
|
64
|
-
|
73
|
+
subject.should have_tag("body#page")
|
74
|
+
subject.should have_tag("body.dark")
|
75
|
+
subject.should have_tag("body[onload='init();']")
|
65
76
|
end
|
66
77
|
|
67
78
|
it "should append classes" do
|
68
|
-
|
79
|
+
subject = helper.body(:append_class => "more classes") { "Body" }
|
69
80
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
81
|
+
subject.should have_tag("body.more")
|
82
|
+
subject.should have_tag("body.classes")
|
83
|
+
subject.should have_tag("body.en")
|
84
|
+
subject.should have_tag("body.sample-index")
|
74
85
|
end
|
75
86
|
|
76
87
|
it "should not have append_class attribute" do
|
@@ -107,18 +118,22 @@ describe SwissKnife::Helpers do
|
|
107
118
|
end
|
108
119
|
|
109
120
|
it "should use other options like css class" do
|
110
|
-
|
111
|
-
|
121
|
+
subject = helper.wrapper(:div, :id => "container", :class => "rounded") { "Some content" }
|
122
|
+
subject.should have_tag("div#container.rounded", "Some content")
|
112
123
|
end
|
113
124
|
end
|
114
125
|
|
115
126
|
describe "#dispatcher_tag" do
|
127
|
+
it "should be html safe" do
|
128
|
+
helper.dispatcher_tag.should be_html_safe
|
129
|
+
end
|
130
|
+
|
116
131
|
it "should contain meta tag" do
|
117
132
|
@controller.class.stub!(:name).and_return("SampleController")
|
118
133
|
|
119
|
-
|
120
|
-
|
121
|
-
|
134
|
+
subject = helper.dispatcher_tag
|
135
|
+
subject.should have_tag("meta")
|
136
|
+
subject.should have_tag("meta[name=page][content='sample#index']")
|
122
137
|
end
|
123
138
|
|
124
139
|
it "should return normalized controller name for namespaced controller" do
|
@@ -130,6 +145,8 @@ describe SwissKnife::Helpers do
|
|
130
145
|
describe "#mail_to" do
|
131
146
|
subject { helper.mail_to("john@doe.com") }
|
132
147
|
|
148
|
+
it { should be_html_safe }
|
149
|
+
|
133
150
|
it "should be encrypted" do
|
134
151
|
subject.should_not match(/john@doe\.com/)
|
135
152
|
end
|
@@ -152,99 +169,101 @@ describe SwissKnife::Helpers do
|
|
152
169
|
|
153
170
|
describe "javascript includes" do
|
154
171
|
it "should use defaults" do
|
155
|
-
|
172
|
+
subject = helper.javascript_includes("application")
|
156
173
|
|
157
|
-
|
158
|
-
|
174
|
+
subject.should have_tag("script[type='text/javascript']", :count => 1)
|
175
|
+
subject.should match(%r{/javascripts/application.js(\?\d+)?})
|
159
176
|
end
|
160
177
|
|
161
178
|
it "should return several includes for bundle when not in production" do
|
162
179
|
SwissKnife::Assets.stub(:merge? => false)
|
163
|
-
|
180
|
+
subject = helper.javascript_includes(:base)
|
164
181
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
182
|
+
subject.should have_tag("script[type='text/javascript']", :count => 3)
|
183
|
+
subject.should match(%r{/javascripts/application.js(\?\d+)?})
|
184
|
+
subject.should match(%r{/javascripts/jquery.js(\?\d+)?})
|
185
|
+
subject.should match(%r{/javascripts/rails.js(\?\d+)?})
|
169
186
|
end
|
170
187
|
|
171
188
|
it "should return bundle only when in production" do
|
172
189
|
SwissKnife::Assets.stub(:merge? => true)
|
173
|
-
|
190
|
+
subject = helper.javascript_includes(:base)
|
174
191
|
|
175
|
-
|
176
|
-
|
192
|
+
subject.should have_tag("script[type='text/javascript']", :count => 1)
|
193
|
+
subject.should match(%r{/javascripts/base_packaged.js(\?\d+)?})
|
177
194
|
end
|
178
195
|
end
|
179
196
|
|
180
197
|
describe "stylesheet includes" do
|
181
198
|
it "should use defaults" do
|
182
|
-
|
199
|
+
subject = helper.stylesheet_includes("application")
|
183
200
|
|
184
|
-
|
185
|
-
|
201
|
+
subject.should have_tag("link[rel='stylesheet']", :count => 1)
|
202
|
+
subject.should match(%r{/stylesheets/application.css(\?\d+)?})
|
186
203
|
end
|
187
204
|
|
188
205
|
it "should return several includes for bundle when not in production" do
|
189
206
|
SwissKnife::Assets.stub(:merge? => false)
|
190
|
-
|
207
|
+
subject = helper.stylesheet_includes(:base)
|
191
208
|
|
192
|
-
|
193
|
-
|
194
|
-
|
209
|
+
subject.should have_tag("link[rel='stylesheet']", :count => 2)
|
210
|
+
subject.should match(%r{/stylesheets/reset.css(\?\d+)?})
|
211
|
+
subject.should match(%r{/stylesheets/main.css(\?\d+)?})
|
195
212
|
end
|
196
213
|
|
197
214
|
it "should return only bundle when in production" do
|
198
215
|
SwissKnife::Assets.stub(:merge? => true)
|
199
|
-
|
216
|
+
subject = helper.stylesheet_includes(:base)
|
200
217
|
|
201
|
-
|
202
|
-
|
218
|
+
subject.should have_tag("link[rel='stylesheet']", :count => 1)
|
219
|
+
subject.should match(%r{/stylesheets/base_packaged.css(\?\d+)?})
|
203
220
|
end
|
204
221
|
end
|
205
222
|
end
|
206
223
|
|
207
224
|
describe "#fieldset" do
|
208
|
-
|
209
|
-
|
210
|
-
|
225
|
+
subject { helper.fieldset("Nice legend", :class => "sample") { "<p>Fieldset</p>" } }
|
226
|
+
|
227
|
+
it { should be_html_safe }
|
211
228
|
|
212
229
|
it "should use provided options" do
|
213
|
-
|
230
|
+
subject.should have_tag("fieldset.sample", :count => 1)
|
214
231
|
end
|
215
232
|
|
216
233
|
it "should use legend as text" do
|
217
|
-
|
234
|
+
subject.should have_tag("fieldset > legend", "Nice legend")
|
218
235
|
end
|
219
236
|
|
220
237
|
it "should use translated legend" do
|
221
238
|
I18n.locale = :pt
|
222
239
|
I18n.backend.should_receive(:translations).and_return(:pt => {:sample => "Legenda"})
|
223
240
|
|
224
|
-
|
225
|
-
|
241
|
+
subject = helper.fieldset("sample") {}
|
242
|
+
subject.should have_tag("fieldset > legend", "Legenda")
|
226
243
|
end
|
227
244
|
|
228
245
|
it "should return content" do
|
229
|
-
|
246
|
+
subject.should have_tag("fieldset > p", "Fieldset")
|
230
247
|
end
|
231
248
|
end
|
232
249
|
|
233
250
|
describe "#gravatar_tag" do
|
234
251
|
before do
|
235
252
|
ActionController::Base.asset_host = "http://example.com"
|
236
|
-
@email = "john@doe.com"
|
237
253
|
end
|
238
254
|
|
255
|
+
let(:email) { "john@doe.com" }
|
256
|
+
subject { helper.gravatar_tag(email) }
|
257
|
+
|
239
258
|
it "should return an image" do
|
240
|
-
|
259
|
+
subject.should have_tag("img.gravatar", :count => 1)
|
241
260
|
end
|
242
261
|
|
243
262
|
it "should use default options" do
|
244
|
-
uri = uri_for(
|
263
|
+
uri = uri_for(subject)
|
245
264
|
uri.scheme.should == "http"
|
246
265
|
uri.host.should == "www.gravatar.com"
|
247
|
-
uri.path.should == "/avatar/#{Digest::MD5.hexdigest(
|
266
|
+
uri.path.should == "/avatar/#{Digest::MD5.hexdigest(email)}.jpg"
|
248
267
|
uri.params.should == {"s" => "32", "r" => "g", "d" => "http://example.com/images/gravatar.jpg"}
|
249
268
|
end
|
250
269
|
|
@@ -254,49 +273,49 @@ describe SwissKnife::Helpers do
|
|
254
273
|
end
|
255
274
|
|
256
275
|
it "should use custom default image" do
|
257
|
-
uri = uri_for(helper.gravatar_tag(
|
276
|
+
uri = uri_for(helper.gravatar_tag(email, :default => "custom.jpg"))
|
258
277
|
uri.params["d"].should == "http://example.com/images/custom.jpg"
|
259
278
|
end
|
260
279
|
|
261
280
|
it "should use custom default image" do
|
262
|
-
uri = uri_for(helper.gravatar_tag(
|
281
|
+
uri = uri_for(helper.gravatar_tag(email, :default => "custom.jpg"))
|
263
282
|
uri.params["d"].should == "http://example.com/images/custom.jpg"
|
264
283
|
end
|
265
284
|
|
266
285
|
it "should use predefined default image" do
|
267
|
-
uri = uri_for(helper.gravatar_tag(
|
286
|
+
uri = uri_for(helper.gravatar_tag(email, :default => :mm))
|
268
287
|
uri.params["d"].should == "mm"
|
269
288
|
end
|
270
289
|
|
271
290
|
it "should use custom size" do
|
272
|
-
uri = uri_for(helper.gravatar_tag(
|
291
|
+
uri = uri_for(helper.gravatar_tag(email, :size => 80))
|
273
292
|
uri.params["s"].should == "80"
|
274
293
|
end
|
275
294
|
|
276
295
|
it "should use custom rating" do
|
277
|
-
uri = uri_for(helper.gravatar_tag(
|
296
|
+
uri = uri_for(helper.gravatar_tag(email, :rating => "pg"))
|
278
297
|
uri.params["r"].should == "pg"
|
279
298
|
end
|
280
299
|
|
281
300
|
it "should use secure host when in a secure request" do
|
282
301
|
helper.request.should_receive(:ssl?).and_return(true)
|
283
|
-
uri = uri_for(helper.gravatar_tag(
|
302
|
+
uri = uri_for(helper.gravatar_tag(email))
|
284
303
|
uri.host.should == "secure.gravatar.com"
|
285
304
|
uri.scheme.should == "https"
|
286
305
|
end
|
287
306
|
|
288
307
|
it "should use secure host when using :ssl option" do
|
289
|
-
uri = uri_for(helper.gravatar_tag(
|
308
|
+
uri = uri_for(helper.gravatar_tag(email, :ssl => true))
|
290
309
|
uri.host.should == "secure.gravatar.com"
|
291
310
|
uri.scheme.should == "https"
|
292
311
|
end
|
293
312
|
|
294
313
|
it "should use alt" do
|
295
|
-
helper.gravatar_tag(
|
314
|
+
helper.gravatar_tag(email, :alt => "alt text").should match(/\balt="alt text"/)
|
296
315
|
end
|
297
316
|
|
298
317
|
it "should use title" do
|
299
|
-
helper.gravatar_tag(
|
318
|
+
helper.gravatar_tag(email, :title => "title text").should match(/\btitle="title text"/)
|
300
319
|
end
|
301
320
|
|
302
321
|
private
|
@@ -315,54 +334,56 @@ describe SwissKnife::Helpers do
|
|
315
334
|
|
316
335
|
describe "#submit_or_cancel" do
|
317
336
|
it "should use defaults" do
|
318
|
-
|
319
|
-
|
320
|
-
|
337
|
+
subject = helper.submit_or_cancel("/some/path")
|
338
|
+
subject.should have_tag("a.cancel[href='/some/path']", :text => "Cancel")
|
339
|
+
subject.should have_tag("input.button[type=submit][value=Submit]")
|
321
340
|
end
|
322
341
|
|
323
342
|
it "should use custom link text from I18n file" do
|
324
343
|
I18n.backend.stub :translations => {:en => {:go_back => "Go back"}}
|
325
|
-
|
326
|
-
|
344
|
+
subject = helper.submit_or_cancel("/some/path", :cancel => :go_back)
|
345
|
+
subject.should have_tag("a.cancel", :text => "Go back")
|
327
346
|
end
|
328
347
|
|
329
348
|
it "should use custom link text" do
|
330
|
-
|
331
|
-
|
349
|
+
subject = helper.submit_or_cancel("/some/path", :cancel => "Go back")
|
350
|
+
subject.should have_tag("a.cancel", :text => "Go back")
|
332
351
|
end
|
333
352
|
|
334
353
|
it "should use custom button text from I18n file" do
|
335
354
|
I18n.backend.stub :translations => {:en => {:send => "Send"}}
|
336
|
-
|
337
|
-
|
355
|
+
subject = helper.submit_or_cancel("/some/path", :button => :send)
|
356
|
+
subject.should have_tag("input[type=submit][value=Send]")
|
338
357
|
end
|
339
358
|
|
340
359
|
it "should use custom button text" do
|
341
|
-
|
342
|
-
|
360
|
+
subject = helper.submit_or_cancel("/some/path", :button => "Send")
|
361
|
+
subject.should have_tag("input[type=submit][value=Send]")
|
343
362
|
end
|
344
363
|
end
|
345
364
|
|
346
365
|
describe "#jquery_script_tag" do
|
366
|
+
subject { helper.jquery_script_tag }
|
367
|
+
|
368
|
+
it { should be_html_safe }
|
369
|
+
|
347
370
|
it "should default to version 1.4.4" do
|
348
|
-
|
349
|
-
html.should have_tag("script[src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js']")
|
371
|
+
subject.should have_tag("script[src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js']")
|
350
372
|
end
|
351
373
|
|
352
374
|
it "should use specified version" do
|
353
|
-
|
354
|
-
|
375
|
+
subject = helper.jquery_script_tag("1.2.3")
|
376
|
+
subject.should have_tag("script[src='http://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js']")
|
355
377
|
end
|
356
378
|
|
357
379
|
it "should use https protocol" do
|
358
380
|
helper.request.stub :protocol => "https://"
|
359
|
-
|
360
|
-
|
381
|
+
subject = helper.jquery_script_tag
|
382
|
+
subject.should have_tag("script[src='https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js']")
|
361
383
|
end
|
362
384
|
|
363
385
|
it "should set fallback path" do
|
364
|
-
|
365
|
-
html.should match(%r[src='http://example.com/javascripts/jquery-1.4.4.min.js'])
|
386
|
+
subject.should match(%r[src='http://example.com/javascripts/jquery-1.4.4.min.js'])
|
366
387
|
end
|
367
388
|
end
|
368
389
|
end
|
data/spec/spec_helper.rb
CHANGED
data/swiss_knife.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_dependency "rails", "
|
22
|
-
s.add_development_dependency "rspec", "
|
21
|
+
s.add_dependency "rails", "~> 3.0.0"
|
22
|
+
s.add_development_dependency "rspec-rails", "~> 2.5.0"
|
23
|
+
s.add_development_dependency "nokogiri"
|
24
|
+
s.add_development_dependency "fakeweb"
|
23
25
|
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swiss_knife
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 4
|
9
|
-
version: 0.1.4
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.5
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Nando Vieira
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date:
|
13
|
+
date: 2011-03-14 00:00:00 -03:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -23,30 +19,44 @@ dependencies:
|
|
23
19
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
20
|
none: false
|
25
21
|
requirements:
|
26
|
-
- -
|
22
|
+
- - ~>
|
27
23
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 3
|
30
|
-
- 0
|
31
|
-
- 0
|
32
24
|
version: 3.0.0
|
33
25
|
type: :runtime
|
34
26
|
version_requirements: *id001
|
35
27
|
- !ruby/object:Gem::Dependency
|
36
|
-
name: rspec
|
28
|
+
name: rspec-rails
|
37
29
|
prerelease: false
|
38
30
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
31
|
none: false
|
40
32
|
requirements:
|
41
|
-
- -
|
33
|
+
- - ~>
|
42
34
|
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
- 2
|
45
|
-
- 0
|
46
|
-
- 0
|
47
|
-
version: 2.0.0
|
35
|
+
version: 2.5.0
|
48
36
|
type: :development
|
49
37
|
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: nokogiri
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: fakeweb
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
50
60
|
description: Several helpers for Rails 3
|
51
61
|
email:
|
52
62
|
- fnando.vieira@gmail.com
|
@@ -58,6 +68,7 @@ extra_rdoc_files: []
|
|
58
68
|
|
59
69
|
files:
|
60
70
|
- .gitignore
|
71
|
+
- .rspec
|
61
72
|
- Gemfile
|
62
73
|
- Gemfile.lock
|
63
74
|
- README.rdoc
|
@@ -126,21 +137,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
137
|
requirements:
|
127
138
|
- - ">="
|
128
139
|
- !ruby/object:Gem::Version
|
129
|
-
segments:
|
130
|
-
- 0
|
131
140
|
version: "0"
|
132
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
142
|
none: false
|
134
143
|
requirements:
|
135
144
|
- - ">="
|
136
145
|
- !ruby/object:Gem::Version
|
137
|
-
segments:
|
138
|
-
- 0
|
139
146
|
version: "0"
|
140
147
|
requirements: []
|
141
148
|
|
142
149
|
rubyforge_project:
|
143
|
-
rubygems_version: 1.
|
150
|
+
rubygems_version: 1.6.0
|
144
151
|
signing_key:
|
145
152
|
specification_version: 3
|
146
153
|
summary: Several helpers for Rails 3
|