herbie 0.1.6 → 0.2.0
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.
- data/lib/herbie/html_helpers.rb +8 -1
- data/lib/herbie.rb +1 -1
- data/spec/herbie_spec.rb +8 -0
- metadata +3 -2
data/lib/herbie/html_helpers.rb
CHANGED
@@ -40,7 +40,7 @@ module Herbie
|
|
40
40
|
result
|
41
41
|
end
|
42
42
|
|
43
|
-
def script(source=nil, &block)
|
43
|
+
def script(source=nil, options={}, &block)
|
44
44
|
attrs = {
|
45
45
|
:type => "text/javascript",
|
46
46
|
:charset => "utf-8"
|
@@ -50,6 +50,7 @@ module Herbie
|
|
50
50
|
erb_concat "#{tag :script, attrs}\n#{capture_erb(&block)}\n</script>"
|
51
51
|
else
|
52
52
|
source = "/javascripts/#{source}" unless source.nil? || source.match(/^\/{1,2}|^http:\/\/|^https:\/\//)
|
53
|
+
source = source.sub(/.js$/, '.min.js') if source && options[:minified] && !source.match(/.min.js$/)
|
53
54
|
attrs = attrs.merge({:src => source})
|
54
55
|
"#{tag :script, attrs}</script>"
|
55
56
|
end
|
@@ -66,6 +67,12 @@ module Herbie
|
|
66
67
|
erb_concat "#{tag :style, default_attrs.merge(attrs)}\n#{capture_erb(&block)}\n</style>"
|
67
68
|
else
|
68
69
|
href = "/stylesheets/#{href}" unless href.match(/^\/{1,2}|^http:\/\/|^https:\/\//)
|
70
|
+
|
71
|
+
if attrs[:minified]
|
72
|
+
attrs.delete :minified
|
73
|
+
href = href.sub(/.css$/, '.min.css') if href && !href.match(/.min.css$/)
|
74
|
+
end
|
75
|
+
|
69
76
|
attrs = default_attrs.merge({:href => href}.merge(attrs))
|
70
77
|
"#{tag :link, attrs}"
|
71
78
|
end
|
data/lib/herbie.rb
CHANGED
data/spec/herbie_spec.rb
CHANGED
@@ -129,6 +129,10 @@ MARKUP
|
|
129
129
|
script("https://code.jquery.com/jquery.js").should == "<script type=\"text/javascript\" charset=\"utf-8\" src=\"https://code.jquery.com/jquery.js\"></script>" and
|
130
130
|
script("//code.jquery.com/jquery.js").should == "<script type=\"text/javascript\" charset=\"utf-8\" src=\"//code.jquery.com/jquery.js\"></script>"
|
131
131
|
end
|
132
|
+
|
133
|
+
it "should output a modified URL with .min.js as the file extension when the minified option is true" do
|
134
|
+
script("/path/to/script.js", :minified => true).should == "<script type=\"text/javascript\" charset=\"utf-8\" src=\"/path/to/script.min.js\"></script>"
|
135
|
+
end
|
132
136
|
|
133
137
|
it "should output a script element with arbitrary javascript content provided by a block" do
|
134
138
|
pending "Need a mechanism for capturing erb output within a passed block"
|
@@ -162,6 +166,10 @@ MARKUP
|
|
162
166
|
media = "screen and (min-width:500px)"
|
163
167
|
style("/style/foo.css", :media => media).should == "<link rel=\"stylesheet\" type=\"text/css\" href=\"/style/foo.css\" media=\"#{media}\">"
|
164
168
|
end
|
169
|
+
|
170
|
+
it "should output a modified URL with .min.css as the file extension when the minified option is true" do
|
171
|
+
style("/style/foo.css", :minified => true).should == "<link rel=\"stylesheet\" type=\"text/css\" href=\"/style/foo.min.css\">"
|
172
|
+
end
|
165
173
|
|
166
174
|
it "should output a style element with arbitrary content provided by a block" do
|
167
175
|
pending "Need a mechanism for capturing erb output within a passed block"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: herbie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: tilt
|
@@ -114,3 +114,4 @@ summary: herbie
|
|
114
114
|
test_files:
|
115
115
|
- spec/herbie_spec.rb
|
116
116
|
- spec/spec_helper.rb
|
117
|
+
has_rdoc:
|