herbie 0.3.2 → 0.3.3
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/generic_helpers.rb +9 -5
- data/lib/herbie/html_helpers.rb +6 -6
- data/lib/herbie.rb +1 -1
- data/spec/herbie_spec.rb +8 -0
- metadata +1 -1
@@ -9,12 +9,16 @@ module Herbie
|
|
9
9
|
|
10
10
|
def attributes(hash)
|
11
11
|
a = []
|
12
|
-
hash.each_pair do |
|
13
|
-
unless
|
14
|
-
if
|
15
|
-
a.push "#{snake_case(
|
12
|
+
hash.each_pair do |attribute, value|
|
13
|
+
unless value.nil?
|
14
|
+
if value === true
|
15
|
+
a.push "#{snake_case(attribute.to_s).sub(/^(.{1,1})/) { |m| m.downcase }}"
|
16
16
|
else
|
17
|
-
|
17
|
+
if attribute == :class && value.class == Array
|
18
|
+
a.push "#{snake_case(attribute.to_s).sub(/^(.{1,1})/) { |m| m.downcase }}=\"#{value.join(' ')}\""
|
19
|
+
else
|
20
|
+
a.push "#{snake_case(attribute.to_s).sub(/^(.{1,1})/) { |m| m.downcase }}=\"#{value}\""
|
21
|
+
end
|
18
22
|
end
|
19
23
|
end
|
20
24
|
end
|
data/lib/herbie/html_helpers.rb
CHANGED
@@ -2,14 +2,14 @@ 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?}>\n#{capture_erb(&block)}\n</#{name}>\n"
|
5
|
+
erb_concat "<#{name}#{' ' + attributes(attrs) unless attrs.nil? || attrs.empty? || attributes(attrs).empty?}>\n#{capture_erb(&block)}\n</#{name}>\n"
|
6
6
|
elsif !attrs[:content].nil?
|
7
7
|
case name
|
8
8
|
when :meta
|
9
|
-
"<#{name}#{' ' + attributes(attrs) unless attrs.empty?}>"
|
9
|
+
"<#{name}#{' ' + attributes(attrs) unless attrs.empty? || attributes(attrs).empty?}>"
|
10
10
|
else
|
11
11
|
content = attrs.delete :content
|
12
|
-
"<#{name}#{' ' + attributes(attrs) unless attrs.empty?}>#{content}</#{name}>"
|
12
|
+
"<#{name}#{' ' + attributes(attrs) unless attrs.empty? || attributes(attrs).empty?}>#{content}</#{name}>"
|
13
13
|
end
|
14
14
|
else
|
15
15
|
case name
|
@@ -22,11 +22,11 @@ module Herbie
|
|
22
22
|
tag :option, option
|
23
23
|
end
|
24
24
|
end.join
|
25
|
-
"<#{name}#{' ' + attributes(attrs) unless attrs.empty?}>#{option_tags}</#{name}>"
|
25
|
+
"<#{name}#{' ' + attributes(attrs) unless attrs.empty? || attributes(attrs).empty?}>#{option_tags}</#{name}>"
|
26
26
|
when :span
|
27
|
-
"<#{name}#{' ' + attributes(attrs) unless attrs.empty?}></#{name}>"
|
27
|
+
"<#{name}#{' ' + attributes(attrs) unless attrs.empty? || attributes(attrs).empty?}></#{name}>"
|
28
28
|
else
|
29
|
-
"<#{name}#{' ' + attributes(attrs) unless attrs.empty?}>"
|
29
|
+
"<#{name}#{' ' + attributes(attrs) unless attrs.empty? || attributes(attrs).empty?}>"
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
data/lib/herbie.rb
CHANGED
data/spec/herbie_spec.rb
CHANGED
@@ -48,6 +48,14 @@ describe Herbie::Helpers do
|
|
48
48
|
tag(:meta, attrs).should == "<meta name=\"#{attrs[:name]}\" content=\"#{attrs[:content]}\">"
|
49
49
|
end
|
50
50
|
|
51
|
+
it "should ignore passed attributes with a nil value" do
|
52
|
+
tag(:div, :class => nil, :content => "They have absolutely no class, and they're always on the hustle.").should == "<div>They have absolutely no class, and they're always on the hustle.</div>"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should output all class names supplied as an array" do
|
56
|
+
tag(:div, :class => [:foo, :bar], :content => "hello world").should == "<div class=\"foo bar\">hello world</div>"
|
57
|
+
end
|
58
|
+
|
51
59
|
it "should automatically close span tags when no content is supplied" do
|
52
60
|
tag(:span).should == "<span></span>"
|
53
61
|
end
|