herbie 0.2.0 → 0.3.1
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 +14 -1
- data/spec/herbie_spec.rb +84 -0
- metadata +2 -2
data/lib/herbie.rb
CHANGED
data/lib/herbie/html_helpers.rb
CHANGED
@@ -12,7 +12,20 @@ module Herbie
|
|
12
12
|
"<#{name}#{' ' + attributes(attrs) unless attrs.empty?}>#{content}</#{name}>"
|
13
13
|
end
|
14
14
|
else
|
15
|
-
|
15
|
+
case name
|
16
|
+
when :select
|
17
|
+
option_tags = attrs.delete(:options).collect do |option|
|
18
|
+
if option.key? :label
|
19
|
+
option[:content] = option.delete(:options).collect {|o| tag :option, o}.join
|
20
|
+
tag :optgroup, option
|
21
|
+
else
|
22
|
+
tag :option, option
|
23
|
+
end
|
24
|
+
end.join
|
25
|
+
"<#{name}#{' ' + attributes(attrs) unless attrs.empty?}>#{option_tags}</#{name}>"
|
26
|
+
else
|
27
|
+
"<#{name}#{' ' + attributes(attrs) unless attrs.empty?}>"
|
28
|
+
end
|
16
29
|
end
|
17
30
|
end
|
18
31
|
|
data/spec/herbie_spec.rb
CHANGED
@@ -46,6 +46,90 @@ describe Herbie::Helpers do
|
|
46
46
|
|
47
47
|
tag(:meta, attrs).should == "<meta name=\"#{attrs[:name]}\" content=\"#{attrs[:content]}\">"
|
48
48
|
end
|
49
|
+
|
50
|
+
it "should output select tags with a supplied list of options" do
|
51
|
+
attrs = {
|
52
|
+
:name => "colour",
|
53
|
+
:options => [
|
54
|
+
{:content => "White", :value => :common},
|
55
|
+
{:content => "Green", :value => :uncommon},
|
56
|
+
{:content => "Blue", :value => :rare},
|
57
|
+
{:content => "Purple", :value => :epic},
|
58
|
+
{:content => "Orange", :value => :legendary}
|
59
|
+
]
|
60
|
+
}
|
61
|
+
|
62
|
+
tag(:select, attrs).should == "<select name=\"colour\"><option value=\"common\">White</option><option value=\"uncommon\">Green</option><option value=\"rare\">Blue</option><option value=\"epic\">Purple</option><option value=\"legendary\">Orange</option></select>"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should output select tags with a supplied list of optgroups" do
|
66
|
+
attrs = {
|
67
|
+
:name => "vehicles",
|
68
|
+
:options => [
|
69
|
+
{
|
70
|
+
:label => "Cars",
|
71
|
+
:options => [
|
72
|
+
{:content => "Ferrari", :value => :ferrari},
|
73
|
+
{:content => "Volkswagen", :value => :vw},
|
74
|
+
{:content => "Ford", :value => :ford}
|
75
|
+
]
|
76
|
+
},
|
77
|
+
{
|
78
|
+
:label => "Trucks",
|
79
|
+
:options => [
|
80
|
+
{:content => "Volvo", :value => :volvo},
|
81
|
+
{:content => "Toyota", :value => :toyota},
|
82
|
+
{:content => "General Motors", :value => :gm}
|
83
|
+
]
|
84
|
+
},
|
85
|
+
{
|
86
|
+
:label => "Bikes",
|
87
|
+
:options => [
|
88
|
+
{:content => "Suzuki", :value => :suzuki},
|
89
|
+
{:content => "Ducati", :value => :ducati},
|
90
|
+
{:content => "Kawasaki", :value => :kawasaki}
|
91
|
+
]
|
92
|
+
}
|
93
|
+
]
|
94
|
+
}
|
95
|
+
|
96
|
+
tag(:select, attrs).should == "<select name=\"vehicles\"><optgroup label=\"Cars\"><option value=\"ferrari\">Ferrari</option><option value=\"vw\">Volkswagen</option><option value=\"ford\">Ford</option></optgroup><optgroup label=\"Trucks\"><option value=\"volvo\">Volvo</option><option value=\"toyota\">Toyota</option><option value=\"gm\">General Motors</option></optgroup><optgroup label=\"Bikes\"><option value=\"suzuki\">Suzuki</option><option value=\"ducati\">Ducati</option><option value=\"kawasaki\">Kawasaki</option></optgroup></select>"
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should output select tags with a mixed list of optgroups and options" do
|
100
|
+
attrs = {
|
101
|
+
:name => "vehicles",
|
102
|
+
:options => [
|
103
|
+
{:content => "— Choose —"},
|
104
|
+
{
|
105
|
+
:label => "Cars",
|
106
|
+
:options => [
|
107
|
+
{:content => "Ferrari", :value => :ferrari},
|
108
|
+
{:content => "Volkswagen", :value => :vw},
|
109
|
+
{:content => "Ford", :value => :ford}
|
110
|
+
]
|
111
|
+
},
|
112
|
+
{
|
113
|
+
:label => "Trucks",
|
114
|
+
:options => [
|
115
|
+
{:content => "Volvo", :value => :volvo},
|
116
|
+
{:content => "Toyota", :value => :toyota},
|
117
|
+
{:content => "General Motors", :value => :gm}
|
118
|
+
]
|
119
|
+
},
|
120
|
+
{
|
121
|
+
:label => "Bikes",
|
122
|
+
:options => [
|
123
|
+
{:content => "Suzuki", :value => :suzuki},
|
124
|
+
{:content => "Ducati", :value => :ducati},
|
125
|
+
{:content => "Kawasaki", :value => :kawasaki}
|
126
|
+
]
|
127
|
+
}
|
128
|
+
]
|
129
|
+
}
|
130
|
+
|
131
|
+
tag(:select, attrs).should == "<select name=\"vehicles\"><option>— Choose —</option><optgroup label=\"Cars\"><option value=\"ferrari\">Ferrari</option><option value=\"vw\">Volkswagen</option><option value=\"ford\">Ford</option></optgroup><optgroup label=\"Trucks\"><option value=\"volvo\">Volvo</option><option value=\"toyota\">Toyota</option><option value=\"gm\">General Motors</option></optgroup><optgroup label=\"Bikes\"><option value=\"suzuki\">Suzuki</option><option value=\"ducati\">Ducati</option><option value=\"kawasaki\">Kawasaki</option></optgroup></select>"
|
132
|
+
end
|
49
133
|
|
50
134
|
it "should output tags mixed with ERB" do
|
51
135
|
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.3.1
|
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-06-
|
12
|
+
date: 2013-06-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: tilt
|