herbie 0.1.3 → 0.1.5
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.rb +1 -1
- data/lib/herbie/html_helpers.rb +17 -3
- data/spec/herbie_spec.rb +30 -3
- metadata +2 -2
data/lib/herbie.rb
CHANGED
data/lib/herbie/html_helpers.rb
CHANGED
@@ -2,7 +2,7 @@ module Herbie
|
|
2
2
|
module Helpers
|
3
3
|
def tag(name, attrs={}, &block)
|
4
4
|
if block_given?
|
5
|
-
erb_concat "<#{name}#{' ' + attributes(attrs) unless attrs.nil? || attrs.empty?}
|
5
|
+
erb_concat "<#{name}#{' ' + attributes(attrs) unless attrs.nil? || attrs.empty?}>\n#{capture_erb(&block)}\n</#{name}>"
|
6
6
|
elsif !attrs[:content].nil?
|
7
7
|
content = attrs.delete :content
|
8
8
|
"<#{name}#{' ' + attributes(attrs) unless attrs.empty?}>#{content}</#{name}>"
|
@@ -44,7 +44,7 @@ module Herbie
|
|
44
44
|
if block_given?
|
45
45
|
erb_concat "#{tag :script, attrs}\n#{capture_erb(&block)}\n</script>"
|
46
46
|
else
|
47
|
-
source = "/javascripts/#{source}" unless source.nil? || source.match(
|
47
|
+
source = "/javascripts/#{source}" unless source.nil? || source.match(/^\/{1,2}|^http:\/\/|^https:\/\//)
|
48
48
|
attrs = attrs.merge({:src => source})
|
49
49
|
"#{tag :script, attrs}</script>"
|
50
50
|
end
|
@@ -60,7 +60,7 @@ module Herbie
|
|
60
60
|
default_attrs.delete :rel
|
61
61
|
erb_concat "#{tag :style, default_attrs.merge(attrs)}\n#{capture_erb(&block)}\n</style>"
|
62
62
|
else
|
63
|
-
href = "/stylesheets/#{href}" unless href.match(
|
63
|
+
href = "/stylesheets/#{href}" unless href.match(/^\/{1,2}|^http:\/\/|^https:\/\//)
|
64
64
|
attrs = default_attrs.merge({:href => href}.merge(attrs))
|
65
65
|
"#{tag :link, attrs}"
|
66
66
|
end
|
@@ -75,5 +75,19 @@ module Herbie
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
+
def content_for(name, content=nil, &block)
|
79
|
+
@captured_content ||= {}
|
80
|
+
|
81
|
+
if content || block_given?
|
82
|
+
if @captured_content.key? name
|
83
|
+
@capured_content[name] += content || capture_erb(&block)
|
84
|
+
else
|
85
|
+
@capured_content[name] = content || capture_erb(&block)
|
86
|
+
end
|
87
|
+
else
|
88
|
+
@captured_content[name]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
78
92
|
end
|
79
93
|
end
|
data/spec/herbie_spec.rb
CHANGED
@@ -58,7 +58,7 @@ HTML
|
|
58
58
|
|
59
59
|
it "should output all nested tag method calls" do
|
60
60
|
pending "Need a mechanism for capturing erb output within a passed block"
|
61
|
-
markup = "<div class=\"container\"
|
61
|
+
markup = "<div class=\"container\">\n<h1>Status Report</h1>\n</div>"
|
62
62
|
result = tag :div, :class => "container" do
|
63
63
|
tag :h1, :content => "Status Report"
|
64
64
|
end
|
@@ -115,8 +115,10 @@ MARKUP
|
|
115
115
|
script("/path/to/script.js").should == "<script type=\"text/javascript\" charset=\"utf-8\" src=\"/path/to/script.js\"></script>"
|
116
116
|
end
|
117
117
|
|
118
|
-
it "should output a script with an absolute path to the script if the path provided begins with http" do
|
119
|
-
script("http://code.jquery.com/jquery.js").should == "<script type=\"text/javascript\" charset=\"utf-8\" src=\"http://code.jquery.com/jquery.js\"></script>"
|
118
|
+
it "should output a script with an absolute path to the script if the path provided begins with http://, https:// or //" do
|
119
|
+
script("http://code.jquery.com/jquery.js").should == "<script type=\"text/javascript\" charset=\"utf-8\" src=\"http://code.jquery.com/jquery.js\"></script>" and
|
120
|
+
script("https://code.jquery.com/jquery.js").should == "<script type=\"text/javascript\" charset=\"utf-8\" src=\"https://code.jquery.com/jquery.js\"></script>" and
|
121
|
+
script("//code.jquery.com/jquery.js").should == "<script type=\"text/javascript\" charset=\"utf-8\" src=\"//code.jquery.com/jquery.js\"></script>"
|
120
122
|
end
|
121
123
|
|
122
124
|
it "should output a script element with arbitrary javascript content provided by a block" do
|
@@ -124,6 +126,12 @@ MARKUP
|
|
124
126
|
script_block = Proc.new { "function hello_world(){ console.log(\"hello world!\"); }" }
|
125
127
|
script(&script_block).should == "<script type=\"text/javascript\" charset=\"utf-8\">\n#{capture_erb(&script_block)}\n</script>"
|
126
128
|
end
|
129
|
+
|
130
|
+
it "should output a jQuery script include with the specified options" do
|
131
|
+
pending "NYI"
|
132
|
+
|
133
|
+
jquery(:version => "1.5.0", :min => false, :cdn => :google).should == "<script type=\"text/javascript\" charset=\"utf-8\" src=\"\"></script>"
|
134
|
+
end
|
127
135
|
end
|
128
136
|
|
129
137
|
describe "stylesheet helpers" do
|
@@ -135,6 +143,12 @@ MARKUP
|
|
135
143
|
style("/style/foo.css").should == "<link rel=\"stylesheet\" type=\"text/css\" href=\"/style/foo.css\">"
|
136
144
|
end
|
137
145
|
|
146
|
+
it "should output a link element with the absolute path to the stylesheet if the path provided starts with http://, https:// or //" do
|
147
|
+
style("http://foo.com/style/bar.css").should == "<link rel=\"stylesheet\" type=\"text/css\" href=\"http://foo.com/style/bar.css\">" and
|
148
|
+
style("https://foo.com/style/bar.css").should == "<link rel=\"stylesheet\" type=\"text/css\" href=\"https://foo.com/style/bar.css\">" and
|
149
|
+
style("//foo.com/style/bar.css").should == "<link rel=\"stylesheet\" type=\"text/css\" href=\"//foo.com/style/bar.css\">"
|
150
|
+
end
|
151
|
+
|
138
152
|
it "should output a link element with appropriate media query attribute if provided" do
|
139
153
|
media = "screen and (min-width:500px)"
|
140
154
|
style("/style/foo.css", :media => media).should == "<link rel=\"stylesheet\" type=\"text/css\" href=\"/style/foo.css\" media=\"#{media}\">"
|
@@ -181,4 +195,17 @@ MARKUP
|
|
181
195
|
link_to(href, text, attrs, &markup_block).should == "<a href=\"#{href}\" class=\"#{attrs[:class]}\">#{capture_erb(&markup_block)}</a>"
|
182
196
|
end
|
183
197
|
end
|
198
|
+
|
199
|
+
describe "content helpers" do
|
200
|
+
it "should accept a named block of content which can then be displayed elsewhere later" do
|
201
|
+
pending "Need a mechanism for capturing erb output within a passed block"
|
202
|
+
|
203
|
+
content_for :script do
|
204
|
+
"<script type=\"text/javascript\" charset=\"utf-8\" src=\"/application.js\">"
|
205
|
+
# Tilt['erb'].new { "%><%= script 'application.js' %><%" }
|
206
|
+
end
|
207
|
+
|
208
|
+
content_for(:script).should == "<script type=\"text/javascript\" charset=\"utf-8\" src=\"/application.js\">"
|
209
|
+
end
|
210
|
+
end
|
184
211
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: herbie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ben Darlow
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-12-08 00:00:00 +00:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|