cml 1.4.2

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.
Files changed (61) hide show
  1. data/.document +5 -0
  2. data/.gitignore +5 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +18 -0
  5. data/Rakefile +56 -0
  6. data/VERSION +1 -0
  7. data/cml.gemspec +129 -0
  8. data/lib/cml/converters/jsawesome.rb +103 -0
  9. data/lib/cml/gold.rb +33 -0
  10. data/lib/cml/liquid_filters.rb +13 -0
  11. data/lib/cml/parser.rb +160 -0
  12. data/lib/cml/tag.rb +308 -0
  13. data/lib/cml/tags/checkbox.rb +77 -0
  14. data/lib/cml/tags/checkboxes.rb +38 -0
  15. data/lib/cml/tags/group.rb +25 -0
  16. data/lib/cml/tags/hidden.rb +17 -0
  17. data/lib/cml/tags/iterate.rb +86 -0
  18. data/lib/cml/tags/meta.rb +12 -0
  19. data/lib/cml/tags/multiple_text.rb +11 -0
  20. data/lib/cml/tags/option.rb +29 -0
  21. data/lib/cml/tags/radio.rb +48 -0
  22. data/lib/cml/tags/radios.rb +36 -0
  23. data/lib/cml/tags/ratings.rb +61 -0
  24. data/lib/cml/tags/search.rb +97 -0
  25. data/lib/cml/tags/select.rb +50 -0
  26. data/lib/cml/tags/text.rb +45 -0
  27. data/lib/cml/tags/textarea.rb +45 -0
  28. data/lib/cml/tags/thumb.rb +25 -0
  29. data/lib/cml/tags/unknown.rb +21 -0
  30. data/lib/cml.rb +15 -0
  31. data/spec/complex_spec.rb +127 -0
  32. data/spec/converters/jsawesome_spec.rb +75 -0
  33. data/spec/fixtures/complex.cml +23 -0
  34. data/spec/fixtures/html.cml +34 -0
  35. data/spec/fixtures/invalid.cml +10 -0
  36. data/spec/fixtures/script-style.cml +12 -0
  37. data/spec/fixtures/segfault.cml +1 -0
  38. data/spec/gold_spec.rb +29 -0
  39. data/spec/meta_spec.rb +47 -0
  40. data/spec/normalize_spec.rb +214 -0
  41. data/spec/show_data_spec.rb +308 -0
  42. data/spec/sorta_match.rb +41 -0
  43. data/spec/spec_helper.rb +26 -0
  44. data/spec/tags/checkbox_spec.rb +155 -0
  45. data/spec/tags/checkboxes_spec.rb +171 -0
  46. data/spec/tags/group_spec.rb +108 -0
  47. data/spec/tags/hidden_spec.rb +17 -0
  48. data/spec/tags/iterate_spec.rb +259 -0
  49. data/spec/tags/meta_spec.rb +14 -0
  50. data/spec/tags/multiple_text_spec.rb +40 -0
  51. data/spec/tags/radios_spec.rb +81 -0
  52. data/spec/tags/ratings_spec.rb +79 -0
  53. data/spec/tags/search_spec.rb +132 -0
  54. data/spec/tags/select_spec.rb +76 -0
  55. data/spec/tags/tag_spec.rb +93 -0
  56. data/spec/tags/text_spec.rb +66 -0
  57. data/spec/tags/textarea_spec.rb +58 -0
  58. data/spec/tags/thumb_spec.rb +20 -0
  59. data/spec/tags/unknown_spec.rb +19 -0
  60. data/spec/validation_spec.rb +62 -0
  61. metadata +182 -0
@@ -0,0 +1,308 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "CML Show Data" do
4
+
5
+ def get_parser(data)
6
+ Parser.new(<<-HTML, {:prefix => "unit[data]", :show_data => true, :data => data})
7
+ <cml:text label="The dude abides?" validates="required"/>
8
+ <cml:textarea label="What do you do for recreation?" name="recreation" />
9
+ <cml:checkbox label="I need my fucking johnson!" name="johnson_needed" />
10
+ <cml:checkboxes label="What do you need?">
11
+ <cml:checkbox label="Toe"/>
12
+ <cml:checkbox label="{{ opt1 }}"/>
13
+ <cml:checkbox label="Sympathy"/>
14
+ </cml:checkboxes>
15
+ <cml:radios label="Different mothers?">
16
+ <cml:radio label="Yes"/>
17
+ <cml:radio label="No"/>
18
+ <cml:radio label="Unknown"/>
19
+ </cml:radios>
20
+ <cml:select validates="required" label="My special lady friend should be:">
21
+ <cml:option label="Stayed away from"/>
22
+ <cml:option label="Approached"/>
23
+ </cml:select>
24
+ <cml:ratings from="Sucked" to="Really tied the room together" label="That rug:"/>​
25
+ HTML
26
+ end
27
+
28
+ before(:each) do
29
+ @full_p = get_parser({
30
+ "the_dude_abides" => "Verily",
31
+ "recreation" => "Bowl.",
32
+ "johnson_needed" => "true",
33
+ "what_do_you_need" => ["Johnson", "Toe"],
34
+ "opt1" => "Johnson",
35
+ "different_mothers" => ["No"],
36
+ "my_special_lady_friend_should_be" => "Stayed away from",
37
+ "that_rug" => "4"
38
+ })
39
+ @partial_p = get_parser({
40
+ "the_dude_abides" => "Verily",
41
+ "johnson_needed" => "true",
42
+ "different_mothers" => ["No"],
43
+ "that_rug" => "4",
44
+ "opt1" => "Johnson",
45
+ "vietnam" => "No fucking connection."
46
+ })
47
+ @empty_p = get_parser({})
48
+ end
49
+
50
+ it "preloads full data" do
51
+ @full_p.to_html.should sorta_match(<<-HTML)
52
+ <div class="cml" id="unit[data]">
53
+ <div class="text cml_field">
54
+ <label class="legend">The dude abides?</label>
55
+ <div class="cml_row">
56
+ <input name="unit[data][the_dude_abides]" type="text" value="Verily" class="the_dude_abides validates-required cml_data_preloaded" />
57
+ </div>
58
+ </div>
59
+ <div class="textarea cml_field">
60
+ <label class="legend">What do you do for recreation?</label>
61
+ <div class="cml_row">
62
+ <textarea name="unit[data][recreation]" class="recreation cml_data_preloaded">Bowl.</textarea>
63
+ </div>
64
+ </div>
65
+ <div class="checkbox cml_field">
66
+ <div class="cml_row">
67
+ <label class="">
68
+ <input name="unit[data][johnson_needed]" type="checkbox" value="true" class="johnson_needed cml_data_preloaded" checked="checked" /> I need my fucking johnson!</label>
69
+ </div>
70
+ </div>
71
+ <div class="checkboxes cml_field">
72
+ <h2 class="legend">What do you need?</h2>
73
+ <div class="cml_row">
74
+ <label class=""><input name="unit[data][what_do_you_need][]" type="checkbox" value="Toe" class="what_do_you_need cml_data_preloaded" checked="checked" /> Toe</label>
75
+ </div>
76
+ <div class="cml_row">
77
+ <label class=""><input name="unit[data][what_do_you_need][]" type="checkbox" value="Johnson" class="what_do_you_need cml_data_preloaded" checked="checked" /> Johnson</label>
78
+ </div>
79
+ <div class="cml_row">
80
+ <label class=""><input name="unit[data][what_do_you_need][]" type="checkbox" value="Sympathy" class="what_do_you_need cml_data_preloaded" /> Sympathy</label>
81
+ </div>
82
+ </div>
83
+ <div class="radios cml_field">
84
+ <h2 class="legend">Different mothers?</h2>
85
+ <div class="cml_row">
86
+ <label class=""><input name="unit[data][different_mothers]" type="radio" value="Yes" class="different_mothers cml_data_preloaded" /> Yes</label>
87
+ </div>
88
+ <div class="cml_row">
89
+ <label class=""><input name="unit[data][different_mothers]" type="radio" value="No" class="different_mothers cml_data_preloaded" checked="checked" /> No</label>
90
+ </div>
91
+ <div class="cml_row">
92
+ <label class=""><input name="unit[data][different_mothers]" type="radio" value="Unknown" class="different_mothers cml_data_preloaded" /> Unknown</label>
93
+ </div>
94
+ </div>
95
+ <div class="select cml_field">
96
+ <label class="legend">My special lady friend should be:</label>
97
+ <div class="cml_row">
98
+ <select name="unit[data][my_special_lady_friend_should_be]" class="my_special_lady_friend_should_be validates-required cml_data_preloaded">
99
+ <option value="">Select one</option>
100
+ <option selected="selected">Stayed away from</option>
101
+ <option>Approached</option>
102
+ </select>
103
+ </div>
104
+ </div>
105
+ <div class="ratings cml_field">
106
+ <h2 class="legend">That rug:</h2>
107
+ <div class="cml_row">
108
+ <table>
109
+ <thead>
110
+ <tr>
111
+ <th></th>
112
+ <th class="">1</th>
113
+ <th class="">2</th>
114
+ <th class="">3</th>
115
+ <th class="">4</th>
116
+ <th></th>
117
+ </tr>
118
+ </thead>
119
+ <tbody>
120
+ <tr>
121
+ <td>Sucked</td>
122
+ <td class=""><input name="unit[data][that_rug]" type="radio" value="1" class="that_rug cml_data_preloaded" /></td>
123
+ <td class=""><input name="unit[data][that_rug]" type="radio" value="2" class="that_rug cml_data_preloaded" /></td>
124
+ <td class=""><input name="unit[data][that_rug]" type="radio" value="3" class="that_rug cml_data_preloaded" /></td>
125
+ <td class=""><input name="unit[data][that_rug]" type="radio" value="4" class="that_rug cml_data_preloaded" checked="checked" /></td>
126
+ <td>Really tied the room together</td>
127
+ </tr>
128
+ </tbody>
129
+ </table>
130
+ </div>
131
+ </div>
132
+ </div>
133
+ HTML
134
+ end
135
+
136
+ it "preloads partial data" do
137
+ @partial_p.to_html.should sorta_match(<<-HTML)
138
+ <div class="cml" id="unit[data]">
139
+ <div class="text cml_field">
140
+ <label class="legend">The dude abides?</label>
141
+ <div class="cml_row">
142
+ <input name="unit[data][the_dude_abides]" type="text" value="Verily" class="the_dude_abides validates-required cml_data_preloaded" />
143
+ </div>
144
+ </div>
145
+ <div class="textarea cml_field">
146
+ <label class="legend">What do you do for recreation?</label>
147
+ <div class="cml_row">
148
+ <textarea name="unit[data][recreation]" class="recreation"></textarea>
149
+ </div>
150
+ </div>
151
+ <div class="checkbox cml_field">
152
+ <div class="cml_row">
153
+ <label class="">
154
+ <input name="unit[data][johnson_needed]" type="checkbox" value="true" class="johnson_needed cml_data_preloaded" checked="checked" /> I need my fucking johnson!</label>
155
+ </div>
156
+ </div>
157
+ <div class="checkboxes cml_field">
158
+ <h2 class="legend">What do you need?</h2>
159
+ <div class="cml_row">
160
+ <label class=""><input name="unit[data][what_do_you_need][]" type="checkbox" value="Toe" class="what_do_you_need" /> Toe</label>
161
+ </div>
162
+ <div class="cml_row">
163
+ <label class=""><input name="unit[data][what_do_you_need][]" type="checkbox" value="Johnson" class="what_do_you_need" /> Johnson</label>
164
+ </div>
165
+ <div class="cml_row">
166
+ <label class=""><input name="unit[data][what_do_you_need][]" type="checkbox" value="Sympathy" class="what_do_you_need" /> Sympathy</label>
167
+ </div>
168
+ </div>
169
+ <div class="radios cml_field">
170
+ <h2 class="legend">Different mothers?</h2>
171
+ <div class="cml_row">
172
+ <label class=""><input name="unit[data][different_mothers]" type="radio" value="Yes" class="different_mothers cml_data_preloaded" /> Yes</label>
173
+ </div>
174
+ <div class="cml_row">
175
+ <label class=""><input name="unit[data][different_mothers]" type="radio" value="No" class="different_mothers cml_data_preloaded" checked="checked" /> No</label>
176
+ </div>
177
+ <div class="cml_row">
178
+ <label class=""><input name="unit[data][different_mothers]" type="radio" value="Unknown" class="different_mothers cml_data_preloaded" /> Unknown</label>
179
+ </div>
180
+ </div>
181
+ <div class="select cml_field">
182
+ <label class="legend">My special lady friend should be:</label>
183
+ <div class="cml_row">
184
+ <select name="unit[data][my_special_lady_friend_should_be]" class="my_special_lady_friend_should_be validates-required">
185
+ <option value="">Select one</option>
186
+ <option>Stayed away from</option>
187
+ <option>Approached</option>
188
+ </select>
189
+ </div>
190
+ </div>
191
+ <div class="ratings cml_field">
192
+ <h2 class="legend">That rug:</h2>
193
+ <div class="cml_row">
194
+ <table>
195
+ <thead>
196
+ <tr>
197
+ <th></th>
198
+ <th class="">1</th>
199
+ <th class="">2</th>
200
+ <th class="">3</th>
201
+ <th class="">4</th>
202
+ <th></th>
203
+ </tr>
204
+ </thead>
205
+ <tbody>
206
+ <tr>
207
+ <td>Sucked</td>
208
+ <td class=""><input name="unit[data][that_rug]" type="radio" value="1" class="that_rug cml_data_preloaded" /></td>
209
+ <td class=""><input name="unit[data][that_rug]" type="radio" value="2" class="that_rug cml_data_preloaded" /></td>
210
+ <td class=""><input name="unit[data][that_rug]" type="radio" value="3" class="that_rug cml_data_preloaded" /></td>
211
+ <td class=""><input name="unit[data][that_rug]" type="radio" value="4" class="that_rug cml_data_preloaded" checked="checked" /></td>
212
+ <td>Really tied the room together</td>
213
+ </tr>
214
+ </tbody>
215
+ </table>
216
+ </div>
217
+ </div>
218
+ </div>
219
+ HTML
220
+ end
221
+
222
+ it "doesn't touch anything when given empty data" do
223
+ @empty_p.to_html.should sorta_match(<<-HTML)
224
+ <div class="cml" id="unit[data]">
225
+ <div class="text cml_field">
226
+ <label class="legend">The dude abides?</label>
227
+ <div class="cml_row">
228
+ <input name="unit[data][the_dude_abides]" type="text" value="" class="the_dude_abides validates-required" />
229
+ </div>
230
+ </div>
231
+ <div class="textarea cml_field">
232
+ <label class="legend">What do you do for recreation?</label>
233
+ <div class="cml_row">
234
+ <textarea name="unit[data][recreation]" class="recreation"></textarea>
235
+ </div>
236
+ </div>
237
+ <div class="checkbox cml_field">
238
+ <div class="cml_row">
239
+ <label class="">
240
+ <input name="unit[data][johnson_needed]" type="checkbox" value="true" class="johnson_needed" /> I need my fucking johnson!</label>
241
+ </div>
242
+ </div>
243
+ <div class="checkboxes cml_field">
244
+ <h2 class="legend">What do you need?</h2>
245
+ <div class="cml_row">
246
+ <label class=""><input name="unit[data][what_do_you_need][]" type="checkbox" value="Toe" class="what_do_you_need" /> Toe</label>
247
+ </div>
248
+ <div class="cml_row">
249
+ <label class=""><input name="unit[data][what_do_you_need][]" type="checkbox" value="" class="what_do_you_need" /> {{ opt1 }}</label>
250
+ </div>
251
+ <div class="cml_row">
252
+ <label class=""><input name="unit[data][what_do_you_need][]" type="checkbox" value="Sympathy" class="what_do_you_need" /> Sympathy</label>
253
+ </div>
254
+ </div>
255
+ <div class="radios cml_field">
256
+ <h2 class="legend">Different mothers?</h2>
257
+ <div class="cml_row">
258
+ <label class=""><input name="unit[data][different_mothers]" type="radio" value="Yes" class="different_mothers" /> Yes</label>
259
+ </div>
260
+ <div class="cml_row">
261
+ <label class=""><input name="unit[data][different_mothers]" type="radio" value="No" class="different_mothers" /> No</label>
262
+ </div>
263
+ <div class="cml_row">
264
+ <label class=""><input name="unit[data][different_mothers]" type="radio" value="Unknown" class="different_mothers" /> Unknown</label>
265
+ </div>
266
+ </div>
267
+ <div class="select cml_field">
268
+ <label class="legend">My special lady friend should be:</label>
269
+ <div class="cml_row">
270
+ <select name="unit[data][my_special_lady_friend_should_be]" class="my_special_lady_friend_should_be validates-required">
271
+ <option value="">Select one</option>
272
+ <option>Stayed away from</option>
273
+ <option>Approached</option>
274
+ </select>
275
+ </div>
276
+ </div>
277
+ <div class="ratings cml_field">
278
+ <h2 class="legend">That rug:</h2>
279
+ <div class="cml_row">
280
+ <table>
281
+ <thead>
282
+ <tr>
283
+ <th></th>
284
+ <th class="">1</th>
285
+ <th class="">2</th>
286
+ <th class="">3</th>
287
+ <th class="">4</th>
288
+ <th></th>
289
+ </tr>
290
+ </thead>
291
+ <tbody>
292
+ <tr>
293
+ <td>Sucked</td>
294
+ <td class=""><input name="unit[data][that_rug]" type="radio" value="1" class="that_rug" /></td>
295
+ <td class=""><input name="unit[data][that_rug]" type="radio" value="2" class="that_rug" /></td>
296
+ <td class=""><input name="unit[data][that_rug]" type="radio" value="3" class="that_rug" /></td>
297
+ <td class=""><input name="unit[data][that_rug]" type="radio" value="4" class="that_rug" /></td>
298
+ <td>Really tied the room together</td>
299
+ </tr>
300
+ </tbody>
301
+ </table>
302
+ </div>
303
+ </div>
304
+ </div>
305
+ HTML
306
+ end
307
+
308
+ end
@@ -0,0 +1,41 @@
1
+ class SortaMatch
2
+ def initialize(dom1,dom2)
3
+ @nodes1 = Nokogiri::HTML(dom1).xpath("//*").to_a
4
+ @nodes2 = Nokogiri::HTML(dom2).xpath("//*").to_a
5
+ @children = []
6
+ @nodes1.each_with_index { |d,i| @children << [d,@nodes2[i]] }
7
+ end
8
+
9
+ def missed
10
+ [present(@nodes1[@i]), present(@nodes2[@i])]
11
+ end
12
+
13
+ def present(node)
14
+ node ? "<#{node.name}#{node.attributes.map {|k,v| " #{k}=\"#{v}\""}}>#{node.children.first if first_text?(node)}" : @why
15
+ end
16
+
17
+ def first_text?(node)
18
+ node.children.first && node.children.first.text?
19
+ end
20
+
21
+ def matches?
22
+ @i = 0
23
+ @children.detect do |a,b|
24
+ if a.nil? || b.nil?
25
+ @why = "missing"
26
+ elsif !a.text?
27
+ if a.name != b.name
28
+ @why = "tag"
29
+ elsif a.attributes.map {|k,v| [k.to_s,v.to_s]}.sort != b.attributes.map {|k,v| [k.to_s,v.to_s]}.sort
30
+ @why = "attributes"
31
+ elsif first_text?(b) && a.children.first.to_s.strip != b.children.first.to_s.strip
32
+ @why = "text"
33
+ end
34
+ else
35
+ @why = nil
36
+ end
37
+ @i += 1 unless @why
38
+ @why
39
+ end.nil?
40
+ end
41
+ end
@@ -0,0 +1,26 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'cml'
4
+ require 'spec'
5
+ require 'sorta_match'
6
+ #require 'spec/autorun'
7
+ include CML
8
+
9
+ Spec::Runner.configure do |config|
10
+
11
+ end
12
+
13
+ Spec::Matchers.define :sorta_match do |expected|
14
+ match do |actual|
15
+ @sm = SortaMatch.new(expected, actual)
16
+ @sm.matches?
17
+ end
18
+
19
+ failure_message_for_should do |actual|
20
+ "Expected DOM's to sorta match but they had these differences:\n #{@sm.missed.inspect}"
21
+ end
22
+ end
23
+
24
+ def convert(html)
25
+ Nokogiri::HTML.fragment(html)
26
+ end
@@ -0,0 +1,155 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "CML Radio" do
4
+ it "should render basic checkbox" do
5
+ cml = <<-HTML
6
+ <cml:checkbox label="Check"/>
7
+ HTML
8
+ @p = Parser.new(cml, :prefix => "u12345")
9
+ @p.to_html.should sorta_match(<<-HTML)
10
+ <div class="cml" id="u12345">
11
+ <div class="checkbox cml_field">
12
+ <div class="cml_row"><label class="">
13
+ <input type="checkbox" value="true" name="u12345[check]" class="check"/> Check</label></div>
14
+ </div>
15
+ </div>
16
+ HTML
17
+ end
18
+
19
+ it "should render checkbox custom value" do
20
+ cml = <<-HTML
21
+ <cml:checkbox label="Check" value="yes"/>
22
+ HTML
23
+ @p = Parser.new(cml, :prefix => "u12345")
24
+ @p.to_html.should sorta_match(<<-HTML)
25
+ <div class="cml" id="u12345">
26
+ <div class="checkbox cml_field">
27
+ <div class="cml_row"><label class="">
28
+ <input type="checkbox" value="yes" name="u12345[check]" class="check"/> Check</label></div>
29
+ </div>
30
+ </div>
31
+ HTML
32
+ end
33
+
34
+ it "should render default checkbox" do
35
+ cml = <<-HTML
36
+ <cml:checkbox label="Check" default="false"/>
37
+ HTML
38
+ @p = Parser.new(cml, :prefix => "u12345")
39
+ @p.to_html.should sorta_match(<<-HTML)
40
+ <div class="cml" id="u12345">
41
+ <div class="checkbox cml_field">
42
+ <div class="cml_row"><label class="">
43
+ <input type="hidden" value="false" name="u12345[check]" class="check"/>
44
+ <input type="checkbox" value="true" name="u12345[check]" class="check"/> Check</label></div>
45
+ </div>
46
+ </div>
47
+ HTML
48
+ end
49
+
50
+ it "should render default checkbox when normalized" do
51
+ cml = <<-HTML
52
+ <cml:checkbox label="Check" default="false" gold="true"/>
53
+ HTML
54
+ @p = Parser.new(cml, :prefix => "u12345", :normalize => true, :data => {"check_gold" => "false"})
55
+ #puts Parser.escape(@p.to_html).gsub(/\n/,"<br/>")
56
+ @p.to_html.should sorta_match(<<-HTML)
57
+ <div class="cml" id="u12345">
58
+ <div class="checkbox cml_field">
59
+ <div class="cml_row"><label class="">
60
+ <input checked="checked" name="u12345[check_gold][]" class="check_gold cml_gold_loaded" value="false" type="checkbox" />
61
+ Default value: false
62
+ </label></div>
63
+ <div class="cml_row"><label class="">
64
+ <input name="u12345[check_gold][]" class="check_gold" value="true" type="checkbox" />
65
+ Check
66
+ </label></div>
67
+ <div class="cml_gold_reason">
68
+ <label class="legend">Reason</label>
69
+ <textarea name="u12345[check_gold_reason]"></textarea>
70
+ </div>
71
+ </div>
72
+ </div>
73
+ HTML
74
+ end
75
+
76
+ it "should render default checkbox when normalized and funky gold variable" do
77
+ cml = <<-HTML
78
+ <cml:checkbox label="Check" default="false" gold="funky"/>
79
+ HTML
80
+ @p = Parser.new(cml, :prefix => "u12345", :normalize => true, :data => {"funky" => "false"})
81
+ #puts Parser.escape(@p.to_html).gsub(/\n/,"<br/>")
82
+ @p.to_html.should sorta_match(<<-HTML)
83
+ <div class="cml" id="u12345">
84
+ <div class="checkbox cml_field">
85
+ <div class="cml_row"><label class="">
86
+ <input checked="checked" name="u12345[funky][]" class="funky cml_gold_loaded" value="false" type="checkbox" />
87
+ Default value: false
88
+ </label></div>
89
+ <div class="cml_row"><label class="">
90
+ <input name="u12345[funky][]" class="funky" value="true" type="checkbox" />
91
+ Check
92
+ </label></div>
93
+ <div class="cml_gold_reason">
94
+ <label class="legend">Reason</label>
95
+ <textarea name="u12345[funky_reason]"></textarea>
96
+ </div>
97
+ </div>
98
+ </div>
99
+ HTML
100
+ end
101
+
102
+ it "should render checkbox with instructions attribute" do
103
+ cml = <<-HTML
104
+ <cml:checkbox label="Rad" instructions="Please be careful when you are selecting these."/>
105
+ HTML
106
+ @p = Parser.new(cml, :prefix => "u12345")
107
+ @p.to_html.should sorta_match(<<-HTML)
108
+ <div class="cml" id="u12345">
109
+ <div class="checkbox cml_field">
110
+ <div class="cml_row"><label class="">
111
+ <input type="checkbox" value="true" name="u12345[rad]" class="rad"/> Rad
112
+ </label></div>
113
+ <p class="instructions">Please be careful when you are selecting these.</p>
114
+ </div>
115
+ </div>
116
+ HTML
117
+ end
118
+
119
+ it "should render gold" do
120
+ cml = <<-HTML
121
+ <cml:checkbox label="Rad">
122
+ <cml:gold src="rad_gold"/>
123
+ </cml:checkbox>
124
+ HTML
125
+ @p = Parser.new(cml, :prefix => "u12345")
126
+ @p.tags[0].should be_gold
127
+ @p.to_html.should sorta_match(<<-HTML)
128
+ <div class="cml" id="u12345">
129
+ <div class="checkbox cml_field">
130
+ <div class="cml_row"><label class="">
131
+ <input type="checkbox" value="true" name="u12345[rad]" class="rad"/> Rad</label></div>
132
+ </div>
133
+ </div>
134
+ HTML
135
+ end
136
+
137
+ it "should render checkbox nested" do
138
+ cml = <<-HTML
139
+ <div class="rando">
140
+ <cml:checkbox label="Rad"/>
141
+ </div>
142
+ HTML
143
+ @p = Parser.new(cml, :prefix => "u12345")
144
+ @p.to_html.should sorta_match(<<-HTML)
145
+ <div class="cml" id="u12345">
146
+ <div class="rando">
147
+ <div class="checkbox cml_field">
148
+ <div class="cml_row"><label class="">
149
+ <input type="checkbox" value="true" name="u12345[rad]" class="rad"/> Rad</label></div>
150
+ </div>
151
+ </div>
152
+ </div>
153
+ HTML
154
+ end
155
+ end