hamlit 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +34 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +23 -0
  7. data/README.md +45 -0
  8. data/Rakefile +34 -0
  9. data/benchmarks/benchmark.rb +94 -0
  10. data/benchmarks/context.rb +13 -0
  11. data/benchmarks/view.erb +23 -0
  12. data/benchmarks/view.haml +18 -0
  13. data/benchmarks/view.rbhtml +23 -0
  14. data/benchmarks/view.slim +17 -0
  15. data/bin/hamlit +6 -0
  16. data/hamlit.gemspec +40 -0
  17. data/lib/hamlit/attribute.rb +31 -0
  18. data/lib/hamlit/cli.rb +89 -0
  19. data/lib/hamlit/compiler.rb +24 -0
  20. data/lib/hamlit/compilers/attributes.rb +78 -0
  21. data/lib/hamlit/compilers/comment.rb +13 -0
  22. data/lib/hamlit/compilers/doctype.rb +39 -0
  23. data/lib/hamlit/compilers/dynamic.rb +9 -0
  24. data/lib/hamlit/compilers/filter.rb +53 -0
  25. data/lib/hamlit/compilers/new_attribute.rb +107 -0
  26. data/lib/hamlit/compilers/old_attribute.rb +147 -0
  27. data/lib/hamlit/compilers/preserve.rb +10 -0
  28. data/lib/hamlit/compilers/script.rb +31 -0
  29. data/lib/hamlit/compilers/strip.rb +30 -0
  30. data/lib/hamlit/compilers/text.rb +15 -0
  31. data/lib/hamlit/concerns/attribute_builder.rb +21 -0
  32. data/lib/hamlit/concerns/balanceable.rb +59 -0
  33. data/lib/hamlit/concerns/deprecation.rb +20 -0
  34. data/lib/hamlit/concerns/error.rb +27 -0
  35. data/lib/hamlit/concerns/escapable.rb +17 -0
  36. data/lib/hamlit/concerns/included.rb +28 -0
  37. data/lib/hamlit/concerns/indentable.rb +53 -0
  38. data/lib/hamlit/concerns/line_reader.rb +60 -0
  39. data/lib/hamlit/concerns/registerable.rb +24 -0
  40. data/lib/hamlit/concerns/ripperable.rb +20 -0
  41. data/lib/hamlit/concerns/string_interpolation.rb +48 -0
  42. data/lib/hamlit/engine.rb +42 -0
  43. data/lib/hamlit/filters/base.rb +44 -0
  44. data/lib/hamlit/filters/coffee.rb +12 -0
  45. data/lib/hamlit/filters/css.rb +34 -0
  46. data/lib/hamlit/filters/erb.rb +11 -0
  47. data/lib/hamlit/filters/escaped.rb +19 -0
  48. data/lib/hamlit/filters/javascript.rb +34 -0
  49. data/lib/hamlit/filters/less.rb +12 -0
  50. data/lib/hamlit/filters/markdown.rb +11 -0
  51. data/lib/hamlit/filters/plain.rb +21 -0
  52. data/lib/hamlit/filters/preserve.rb +11 -0
  53. data/lib/hamlit/filters/ruby.rb +11 -0
  54. data/lib/hamlit/filters/sass.rb +12 -0
  55. data/lib/hamlit/filters/scss.rb +12 -0
  56. data/lib/hamlit/filters/tilt.rb +41 -0
  57. data/lib/hamlit/helpers.rb +38 -0
  58. data/lib/hamlit/html/pretty.rb +49 -0
  59. data/lib/hamlit/html/ugly.rb +10 -0
  60. data/lib/hamlit/parser.rb +123 -0
  61. data/lib/hamlit/parsers/attribute.rb +52 -0
  62. data/lib/hamlit/parsers/comment.rb +27 -0
  63. data/lib/hamlit/parsers/doctype.rb +18 -0
  64. data/lib/hamlit/parsers/filter.rb +18 -0
  65. data/lib/hamlit/parsers/multiline.rb +54 -0
  66. data/lib/hamlit/parsers/script.rb +93 -0
  67. data/lib/hamlit/parsers/tag.rb +71 -0
  68. data/lib/hamlit/parsers/text.rb +11 -0
  69. data/lib/hamlit/parsers/whitespace.rb +38 -0
  70. data/lib/hamlit/railtie.rb +21 -0
  71. data/lib/hamlit/template.rb +9 -0
  72. data/lib/hamlit/version.rb +3 -0
  73. data/lib/hamlit.rb +8 -0
  74. data/spec/Rakefile +79 -0
  75. data/spec/hamlit/compilers/script_spec.rb +46 -0
  76. data/spec/hamlit/engine/comment_spec.rb +29 -0
  77. data/spec/hamlit/engine/doctype_spec.rb +19 -0
  78. data/spec/hamlit/engine/error_spec.rb +47 -0
  79. data/spec/hamlit/engine/multiline_spec.rb +44 -0
  80. data/spec/hamlit/engine/new_attribute_spec.rb +19 -0
  81. data/spec/hamlit/engine/old_attributes_spec.rb +85 -0
  82. data/spec/hamlit/engine/preservation_spec.rb +11 -0
  83. data/spec/hamlit/engine/script_spec.rb +87 -0
  84. data/spec/hamlit/engine/silent_script_spec.rb +135 -0
  85. data/spec/hamlit/engine/tag_spec.rb +210 -0
  86. data/spec/hamlit/engine/text_spec.rb +29 -0
  87. data/spec/hamlit/engine_spec.rb +20 -0
  88. data/spec/hamlit/filters/coffee_spec.rb +41 -0
  89. data/spec/hamlit/filters/css_spec.rb +33 -0
  90. data/spec/hamlit/filters/erb_spec.rb +16 -0
  91. data/spec/hamlit/filters/javascript_spec.rb +82 -0
  92. data/spec/hamlit/filters/less_spec.rb +22 -0
  93. data/spec/hamlit/filters/markdown_spec.rb +28 -0
  94. data/spec/hamlit/filters/ruby_spec.rb +24 -0
  95. data/spec/hamlit/filters/sass_spec.rb +37 -0
  96. data/spec/hamlit/filters/scss_spec.rb +21 -0
  97. data/spec/hamlit/ugly_spec.rb +912 -0
  98. data/spec/rails/.gitignore +17 -0
  99. data/spec/rails/.rspec +2 -0
  100. data/spec/rails/Gemfile +19 -0
  101. data/spec/rails/Gemfile.lock +177 -0
  102. data/spec/rails/README.rdoc +28 -0
  103. data/spec/rails/Rakefile +6 -0
  104. data/spec/rails/app/assets/images/.keep +0 -0
  105. data/spec/rails/app/assets/javascripts/application.js +15 -0
  106. data/spec/rails/app/assets/stylesheets/application.css +15 -0
  107. data/spec/rails/app/controllers/application_controller.rb +8 -0
  108. data/spec/rails/app/controllers/concerns/.keep +0 -0
  109. data/spec/rails/app/controllers/users_controller.rb +20 -0
  110. data/spec/rails/app/helpers/application_helper.rb +2 -0
  111. data/spec/rails/app/mailers/.keep +0 -0
  112. data/spec/rails/app/models/.keep +0 -0
  113. data/spec/rails/app/models/concerns/.keep +0 -0
  114. data/spec/rails/app/views/application/index.html.haml +15 -0
  115. data/spec/rails/app/views/layouts/application.html.haml +12 -0
  116. data/spec/rails/app/views/users/capture.html.haml +5 -0
  117. data/spec/rails/app/views/users/capture_haml.html.haml +5 -0
  118. data/spec/rails/app/views/users/form.html.haml +2 -0
  119. data/spec/rails/app/views/users/helpers.html.haml +1 -0
  120. data/spec/rails/app/views/users/index.html.haml +9 -0
  121. data/spec/rails/app/views/users/safe_buffer.html.haml +4 -0
  122. data/spec/rails/bin/bundle +3 -0
  123. data/spec/rails/bin/rails +8 -0
  124. data/spec/rails/bin/rake +8 -0
  125. data/spec/rails/bin/setup +29 -0
  126. data/spec/rails/bin/spring +15 -0
  127. data/spec/rails/config/application.rb +34 -0
  128. data/spec/rails/config/boot.rb +3 -0
  129. data/spec/rails/config/database.yml +25 -0
  130. data/spec/rails/config/environment.rb +5 -0
  131. data/spec/rails/config/environments/development.rb +41 -0
  132. data/spec/rails/config/environments/production.rb +79 -0
  133. data/spec/rails/config/environments/test.rb +42 -0
  134. data/spec/rails/config/initializers/assets.rb +11 -0
  135. data/spec/rails/config/initializers/backtrace_silencers.rb +7 -0
  136. data/spec/rails/config/initializers/cookies_serializer.rb +3 -0
  137. data/spec/rails/config/initializers/filter_parameter_logging.rb +4 -0
  138. data/spec/rails/config/initializers/inflections.rb +16 -0
  139. data/spec/rails/config/initializers/mime_types.rb +4 -0
  140. data/spec/rails/config/initializers/session_store.rb +3 -0
  141. data/spec/rails/config/initializers/wrap_parameters.rb +14 -0
  142. data/spec/rails/config/locales/en.yml +23 -0
  143. data/spec/rails/config/routes.rb +13 -0
  144. data/spec/rails/config/secrets.yml +22 -0
  145. data/spec/rails/config.ru +4 -0
  146. data/spec/rails/db/schema.rb +16 -0
  147. data/spec/rails/db/seeds.rb +7 -0
  148. data/spec/rails/lib/assets/.keep +0 -0
  149. data/spec/rails/lib/tasks/.keep +0 -0
  150. data/spec/rails/log/.keep +0 -0
  151. data/spec/rails/public/404.html +67 -0
  152. data/spec/rails/public/422.html +67 -0
  153. data/spec/rails/public/500.html +66 -0
  154. data/spec/rails/public/favicon.ico +0 -0
  155. data/spec/rails/public/robots.txt +5 -0
  156. data/spec/rails/spec/hamlit_spec.rb +87 -0
  157. data/spec/rails/spec/rails_helper.rb +56 -0
  158. data/spec/rails/spec/spec_helper.rb +91 -0
  159. data/spec/rails/vendor/assets/javascripts/.keep +0 -0
  160. data/spec/rails/vendor/assets/stylesheets/.keep +0 -0
  161. data/spec/spec_helper.rb +48 -0
  162. metadata +560 -0
@@ -0,0 +1,912 @@
1
+ require "haml"
2
+
3
+ # This is a spec converted by haml-spec.
4
+ # See: https://github.com/haml/haml-spec
5
+ describe "haml ugly mode" do
6
+ def assert_pretty(haml, locals, options)
7
+ engine = Haml::Engine.new(haml, options)
8
+ hamlit = Hamlit::Template.new(options) { haml }
9
+ expect(hamlit.render(Object.new, locals)).to eq(engine.render(Object.new, locals))
10
+ end
11
+
12
+ def assert_ugly(haml, locals, options)
13
+ assert_pretty(haml, locals, { ugly: true }.merge(options))
14
+ end
15
+
16
+ context "headers" do
17
+ specify "an XHTML XML prolog" do
18
+ haml = %q{!!! XML}
19
+ html = %q{<?xml version='1.0' encoding='utf-8' ?>}
20
+ locals = {}
21
+ options = {:format=>:xhtml}
22
+ assert_ugly(haml, locals, options)
23
+ end
24
+
25
+ specify "an XHTML default (transitional) doctype" do
26
+ haml = %q{!!!}
27
+ html = %q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">}
28
+ locals = {}
29
+ options = {:format=>:xhtml}
30
+ assert_ugly(haml, locals, options)
31
+ end
32
+
33
+ specify "an XHTML 1.1 doctype" do
34
+ haml = %q{!!! 1.1}
35
+ html = %q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">}
36
+ locals = {}
37
+ options = {:format=>:xhtml}
38
+ assert_ugly(haml, locals, options)
39
+ end
40
+
41
+ specify "an XHTML 1.2 mobile doctype" do
42
+ haml = %q{!!! mobile}
43
+ html = %q{<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">}
44
+ locals = {}
45
+ options = {:format=>:xhtml}
46
+ assert_ugly(haml, locals, options)
47
+ end
48
+
49
+ specify "an XHTML 1.1 basic doctype" do
50
+ haml = %q{!!! basic}
51
+ html = %q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">}
52
+ locals = {}
53
+ options = {:format=>:xhtml}
54
+ assert_ugly(haml, locals, options)
55
+ end
56
+
57
+ specify "an XHTML 1.0 frameset doctype" do
58
+ haml = %q{!!! frameset}
59
+ html = %q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">}
60
+ locals = {}
61
+ options = {:format=>:xhtml}
62
+ assert_ugly(haml, locals, options)
63
+ end
64
+
65
+ specify "an HTML 5 doctype with XHTML syntax" do
66
+ haml = %q{!!! 5}
67
+ html = %q{<!DOCTYPE html>}
68
+ locals = {}
69
+ options = {:format=>:xhtml}
70
+ assert_ugly(haml, locals, options)
71
+ end
72
+
73
+ specify "an HTML 5 XML prolog (silent)" do
74
+ haml = %q{!!! XML}
75
+ html = %q{}
76
+ locals = {}
77
+ options = {:format=>:html5}
78
+ assert_ugly(haml, locals, options)
79
+ end
80
+
81
+ specify "an HTML 5 doctype" do
82
+ haml = %q{!!!}
83
+ html = %q{<!DOCTYPE html>}
84
+ locals = {}
85
+ options = {:format=>:html5}
86
+ assert_ugly(haml, locals, options)
87
+ end
88
+
89
+ specify "an HTML 4 XML prolog (silent)" do
90
+ haml = %q{!!! XML}
91
+ html = %q{}
92
+ locals = {}
93
+ options = {:format=>:html4}
94
+ assert_ugly(haml, locals, options)
95
+ end
96
+
97
+ specify "an HTML 4 default (transitional) doctype" do
98
+ haml = %q{!!!}
99
+ html = %q{<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">}
100
+ locals = {}
101
+ options = {:format=>:html4}
102
+ assert_ugly(haml, locals, options)
103
+ end
104
+
105
+ specify "an HTML 4 frameset doctype" do
106
+ haml = %q{!!! frameset}
107
+ html = %q{<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">}
108
+ locals = {}
109
+ options = {:format=>:html4}
110
+ assert_ugly(haml, locals, options)
111
+ end
112
+
113
+ specify "an HTML 4 strict doctype" do
114
+ haml = %q{!!! strict}
115
+ html = %q{<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">}
116
+ locals = {}
117
+ options = {:format=>:html4}
118
+ assert_ugly(haml, locals, options)
119
+ end
120
+ end
121
+
122
+ context "basic Haml tags and CSS" do
123
+ specify "a simple Haml tag" do
124
+ haml = %q{%p}
125
+ html = %q{<p></p>}
126
+ locals = {}
127
+ options = {}
128
+ assert_ugly(haml, locals, options)
129
+ end
130
+
131
+ specify "a self-closing tag (XHTML)" do
132
+ haml = %q{%meta}
133
+ html = %q{<meta />}
134
+ locals = {}
135
+ options = {:format=>:xhtml}
136
+ assert_ugly(haml, locals, options)
137
+ end
138
+
139
+ specify "a self-closing tag (HTML4)" do
140
+ haml = %q{%meta}
141
+ html = %q{<meta>}
142
+ locals = {}
143
+ options = {:format=>:html4}
144
+ assert_ugly(haml, locals, options)
145
+ end
146
+
147
+ specify "a self-closing tag (HTML5)" do
148
+ haml = %q{%meta}
149
+ html = %q{<meta>}
150
+ locals = {}
151
+ options = {:format=>:html5}
152
+ assert_ugly(haml, locals, options)
153
+ end
154
+
155
+ specify "a self-closing tag ('/' modifier + XHTML)" do
156
+ haml = %q{%zzz/}
157
+ html = %q{<zzz />}
158
+ locals = {}
159
+ options = {:format=>:xhtml}
160
+ assert_ugly(haml, locals, options)
161
+ end
162
+
163
+ specify "a self-closing tag ('/' modifier + HTML5)" do
164
+ haml = %q{%zzz/}
165
+ html = %q{<zzz>}
166
+ locals = {}
167
+ options = {:format=>:html5}
168
+ assert_ugly(haml, locals, options)
169
+ end
170
+
171
+ specify "a tag with a CSS class" do
172
+ haml = %q{%p.class1}
173
+ html = %q{<p class='class1'></p>}
174
+ locals = {}
175
+ options = {}
176
+ assert_ugly(haml, locals, options)
177
+ end
178
+
179
+ specify "a tag with multiple CSS classes" do
180
+ haml = %q{%p.class1.class2}
181
+ html = %q{<p class='class1 class2'></p>}
182
+ locals = {}
183
+ options = {}
184
+ assert_ugly(haml, locals, options)
185
+ end
186
+
187
+ specify "a tag with a CSS id" do
188
+ haml = %q{%p#id1}
189
+ html = %q{<p id='id1'></p>}
190
+ locals = {}
191
+ options = {}
192
+ assert_ugly(haml, locals, options)
193
+ end
194
+
195
+ specify "a tag with multiple CSS id's" do
196
+ haml = %q{%p#id1#id2}
197
+ html = %q{<p id='id2'></p>}
198
+ locals = {}
199
+ options = {}
200
+ assert_ugly(haml, locals, options)
201
+ end
202
+
203
+ specify "a tag with a class followed by an id" do
204
+ haml = %q{%p.class1#id1}
205
+ html = %q{<p class='class1' id='id1'></p>}
206
+ locals = {}
207
+ options = {}
208
+ assert_ugly(haml, locals, options)
209
+ end
210
+
211
+ specify "a tag with an id followed by a class" do
212
+ haml = %q{%p#id1.class1}
213
+ html = %q{<p class='class1' id='id1'></p>}
214
+ locals = {}
215
+ options = {}
216
+ assert_ugly(haml, locals, options)
217
+ end
218
+
219
+ specify "an implicit div with a CSS id" do
220
+ haml = %q{#id1}
221
+ html = %q{<div id='id1'></div>}
222
+ locals = {}
223
+ options = {}
224
+ assert_ugly(haml, locals, options)
225
+ end
226
+
227
+ specify "an implicit div with a CSS class" do
228
+ haml = %q{.class1}
229
+ html = %q{<div class='class1'></div>}
230
+ locals = {}
231
+ options = {}
232
+ assert_ugly(haml, locals, options)
233
+ end
234
+
235
+ specify "multiple simple Haml tags" do
236
+ haml = %q{%div
237
+ %div
238
+ %p}
239
+ html = %q{<div>
240
+ <div>
241
+ <p></p>
242
+ </div>
243
+ </div>}
244
+ locals = {}
245
+ options = {}
246
+ assert_ugly(haml, locals, options)
247
+ end
248
+ end
249
+
250
+ context "tags with unusual HTML characters" do
251
+ specify "a tag with colons" do
252
+ haml = %q{%ns:tag}
253
+ html = %q{<ns:tag></ns:tag>}
254
+ locals = {}
255
+ options = {}
256
+ assert_ugly(haml, locals, options)
257
+ end
258
+
259
+ specify "a tag with underscores" do
260
+ haml = %q{%snake_case}
261
+ html = %q{<snake_case></snake_case>}
262
+ locals = {}
263
+ options = {}
264
+ assert_ugly(haml, locals, options)
265
+ end
266
+
267
+ specify "a tag with dashes" do
268
+ haml = %q{%dashed-tag}
269
+ html = %q{<dashed-tag></dashed-tag>}
270
+ locals = {}
271
+ options = {}
272
+ assert_ugly(haml, locals, options)
273
+ end
274
+
275
+ specify "a tag with camelCase" do
276
+ haml = %q{%camelCase}
277
+ html = %q{<camelCase></camelCase>}
278
+ locals = {}
279
+ options = {}
280
+ assert_ugly(haml, locals, options)
281
+ end
282
+
283
+ specify "a tag with PascalCase" do
284
+ haml = %q{%PascalCase}
285
+ html = %q{<PascalCase></PascalCase>}
286
+ locals = {}
287
+ options = {}
288
+ assert_ugly(haml, locals, options)
289
+ end
290
+ end
291
+
292
+ context "tags with unusual CSS identifiers" do
293
+ specify "an all-numeric class" do
294
+ haml = %q{.123}
295
+ html = %q{<div class='123'></div>}
296
+ locals = {}
297
+ options = {}
298
+ assert_ugly(haml, locals, options)
299
+ end
300
+
301
+ specify "a class with underscores" do
302
+ haml = %q{.__}
303
+ html = %q{<div class='__'></div>}
304
+ locals = {}
305
+ options = {}
306
+ assert_ugly(haml, locals, options)
307
+ end
308
+
309
+ specify "a class with dashes" do
310
+ haml = %q{.--}
311
+ html = %q{<div class='--'></div>}
312
+ locals = {}
313
+ options = {}
314
+ assert_ugly(haml, locals, options)
315
+ end
316
+ end
317
+
318
+ context "tags with inline content" do
319
+ specify "Inline content simple tag" do
320
+ haml = %q{%p hello}
321
+ html = %q{<p>hello</p>}
322
+ locals = {}
323
+ options = {}
324
+ assert_ugly(haml, locals, options)
325
+ end
326
+
327
+ specify "Inline content tag with CSS" do
328
+ haml = %q{%p.class1 hello}
329
+ html = %q{<p class='class1'>hello</p>}
330
+ locals = {}
331
+ options = {}
332
+ assert_ugly(haml, locals, options)
333
+ end
334
+
335
+ specify "Inline content multiple simple tags" do
336
+ haml = %q{%div
337
+ %div
338
+ %p text}
339
+ html = %q{<div>
340
+ <div>
341
+ <p>text</p>
342
+ </div>
343
+ </div>}
344
+ locals = {}
345
+ options = {}
346
+ assert_ugly(haml, locals, options)
347
+ end
348
+ end
349
+
350
+ context "tags with nested content" do
351
+ specify "Nested content simple tag" do
352
+ haml = %q{%p
353
+ hello}
354
+ html = %q{<p>
355
+ hello
356
+ </p>}
357
+ locals = {}
358
+ options = {}
359
+ assert_ugly(haml, locals, options)
360
+ end
361
+
362
+ specify "Nested content tag with CSS" do
363
+ haml = %q{%p.class1
364
+ hello}
365
+ html = %q{<p class='class1'>
366
+ hello
367
+ </p>}
368
+ locals = {}
369
+ options = {}
370
+ assert_ugly(haml, locals, options)
371
+ end
372
+
373
+ specify "Nested content multiple simple tags" do
374
+ haml = %q{%div
375
+ %div
376
+ %p
377
+ text}
378
+ html = %q{<div>
379
+ <div>
380
+ <p>
381
+ text
382
+ </p>
383
+ </div>
384
+ </div>}
385
+ locals = {}
386
+ options = {}
387
+ assert_ugly(haml, locals, options)
388
+ end
389
+ end
390
+
391
+ context "tags with HTML-style attributes" do
392
+ specify "HTML-style one attribute" do
393
+ haml = %q{%p(a='b')}
394
+ html = %q{<p a='b'></p>}
395
+ locals = {}
396
+ options = {}
397
+ assert_ugly(haml, locals, options)
398
+ end
399
+
400
+ specify "HTML-style multiple attributes" do
401
+ haml = %q{%p(a='b' c='d')}
402
+ html = %q{<p a='b' c='d'></p>}
403
+ locals = {}
404
+ options = {}
405
+ assert_ugly(haml, locals, options)
406
+ end
407
+
408
+ specify "HTML-style attributes separated with newlines" do
409
+ haml = %q{%p(a='b'
410
+ c='d')}
411
+ html = %q{<p a='b' c='d'></p>}
412
+ locals = {}
413
+ options = {}
414
+ assert_ugly(haml, locals, options)
415
+ end
416
+
417
+ specify "HTML-style interpolated attribute" do
418
+ haml = %q{%p(a="#{var}")}
419
+ html = %q{<p a='value'></p>}
420
+ locals = {:var=>"value"}
421
+ options = {}
422
+ assert_ugly(haml, locals, options)
423
+ end
424
+
425
+ specify "HTML-style 'class' as an attribute" do
426
+ haml = %q{%p(class='class1')}
427
+ html = %q{<p class='class1'></p>}
428
+ locals = {}
429
+ options = {}
430
+ assert_ugly(haml, locals, options)
431
+ end
432
+
433
+ specify "HTML-style tag with a CSS class and 'class' as an attribute" do
434
+ haml = %q{%p.class2(class='class1')}
435
+ html = %q{<p class='class1 class2'></p>}
436
+ locals = {}
437
+ options = {}
438
+ assert_ugly(haml, locals, options)
439
+ end
440
+
441
+ specify "HTML-style tag with 'id' as an attribute" do
442
+ haml = %q{%p(id='1')}
443
+ html = %q{<p id='1'></p>}
444
+ locals = {}
445
+ options = {}
446
+ assert_ugly(haml, locals, options)
447
+ end
448
+
449
+ specify "HTML-style tag with a CSS id and 'id' as an attribute" do
450
+ haml = %q{%p#id(id='1')}
451
+ html = %q{<p id='id_1'></p>}
452
+ locals = {}
453
+ options = {}
454
+ assert_ugly(haml, locals, options)
455
+ end
456
+
457
+ specify "HTML-style tag with a variable attribute" do
458
+ haml = %q{%p(class=var)}
459
+ html = %q{<p class='hello'></p>}
460
+ locals = {:var=>"hello"}
461
+ options = {}
462
+ assert_ugly(haml, locals, options)
463
+ end
464
+
465
+ specify "HTML-style tag with a CSS class and 'class' as a variable attribute" do
466
+ haml = %q{.hello(class=var)}
467
+ html = %q{<div class='hello world'></div>}
468
+ locals = {:var=>"world"}
469
+ options = {}
470
+ assert_ugly(haml, locals, options)
471
+ end
472
+
473
+ specify "HTML-style tag multiple CSS classes (sorted correctly)" do
474
+ haml = %q{.z(class=var)}
475
+ html = %q{<div class='a z'></div>}
476
+ locals = {:var=>"a"}
477
+ options = {}
478
+ assert_ugly(haml, locals, options)
479
+ end
480
+
481
+ specify "HTML-style tag with an atomic attribute" do
482
+ haml = %q{%a(flag)}
483
+ html = %q{<a flag></a>}
484
+ locals = {}
485
+ options = {}
486
+ assert_ugly(haml, locals, options)
487
+ end
488
+ end
489
+
490
+ context "tags with Ruby-style attributes" do
491
+ specify "Ruby-style one attribute" do
492
+ haml = %q{%p{:a => 'b'}}
493
+ html = %q{<p a='b'></p>}
494
+ locals = {}
495
+ options = {}
496
+ assert_ugly(haml, locals, options)
497
+ end
498
+
499
+ specify "Ruby-style attributes hash with whitespace" do
500
+ haml = %q{%p{ :a => 'b' }}
501
+ html = %q{<p a='b'></p>}
502
+ locals = {}
503
+ options = {}
504
+ assert_ugly(haml, locals, options)
505
+ end
506
+
507
+ specify "Ruby-style interpolated attribute" do
508
+ haml = %q{%p{:a =>"#{var}"}}
509
+ html = %q{<p a='value'></p>}
510
+ locals = {:var=>"value"}
511
+ options = {}
512
+ assert_ugly(haml, locals, options)
513
+ end
514
+
515
+ specify "Ruby-style multiple attributes" do
516
+ haml = %q{%p{ :a => 'b', 'c' => 'd' }}
517
+ html = %q{<p a='b' c='d'></p>}
518
+ locals = {}
519
+ options = {}
520
+ assert_ugly(haml, locals, options)
521
+ end
522
+
523
+ specify "Ruby-style attributes separated with newlines" do
524
+ haml = %q{%p{ :a => 'b',
525
+ 'c' => 'd' }}
526
+ html = %q{<p a='b' c='d'></p>}
527
+ locals = {}
528
+ options = {}
529
+ assert_ugly(haml, locals, options)
530
+ end
531
+
532
+ specify "Ruby-style 'class' as an attribute" do
533
+ haml = %q{%p{:class => 'class1'}}
534
+ html = %q{<p class='class1'></p>}
535
+ locals = {}
536
+ options = {}
537
+ assert_ugly(haml, locals, options)
538
+ end
539
+
540
+ specify "Ruby-style tag with a CSS class and 'class' as an attribute" do
541
+ haml = %q{%p.class2{:class => 'class1'}}
542
+ html = %q{<p class='class1 class2'></p>}
543
+ locals = {}
544
+ options = {}
545
+ assert_ugly(haml, locals, options)
546
+ end
547
+
548
+ specify "Ruby-style tag with 'id' as an attribute" do
549
+ haml = %q{%p{:id => '1'}}
550
+ html = %q{<p id='1'></p>}
551
+ locals = {}
552
+ options = {}
553
+ assert_ugly(haml, locals, options)
554
+ end
555
+
556
+ specify "Ruby-style tag with a CSS id and 'id' as an attribute" do
557
+ haml = %q{%p#id{:id => '1'}}
558
+ html = %q{<p id='id_1'></p>}
559
+ locals = {}
560
+ options = {}
561
+ assert_ugly(haml, locals, options)
562
+ end
563
+
564
+ specify "Ruby-style tag with a CSS id and a numeric 'id' as an attribute" do
565
+ haml = %q{%p#id{:id => 1}}
566
+ html = %q{<p id='id_1'></p>}
567
+ locals = {}
568
+ options = {}
569
+ assert_ugly(haml, locals, options)
570
+ end
571
+
572
+ specify "Ruby-style tag with a variable attribute" do
573
+ haml = %q{%p{:class => var}}
574
+ html = %q{<p class='hello'></p>}
575
+ locals = {:var=>"hello"}
576
+ options = {}
577
+ assert_ugly(haml, locals, options)
578
+ end
579
+
580
+ specify "Ruby-style tag with a CSS class and 'class' as a variable attribute" do
581
+ haml = %q{.hello{:class => var}}
582
+ html = %q{<div class='hello world'></div>}
583
+ locals = {:var=>"world"}
584
+ options = {}
585
+ assert_ugly(haml, locals, options)
586
+ end
587
+
588
+ specify "Ruby-style tag multiple CSS classes (sorted correctly)" do
589
+ haml = %q{.z{:class => var}}
590
+ html = %q{<div class='a z'></div>}
591
+ locals = {:var=>"a"}
592
+ options = {}
593
+ assert_ugly(haml, locals, options)
594
+ end
595
+ end
596
+
597
+ context "silent comments" do
598
+ specify "an inline silent comment" do
599
+ haml = %q{-# hello}
600
+ html = %q{}
601
+ locals = {}
602
+ options = {}
603
+ assert_ugly(haml, locals, options)
604
+ end
605
+
606
+ specify "a nested silent comment" do
607
+ haml = %q{-#
608
+ hello}
609
+ html = %q{}
610
+ locals = {}
611
+ options = {}
612
+ assert_ugly(haml, locals, options)
613
+ end
614
+
615
+ specify "a multiply nested silent comment" do
616
+ haml = %q{-#
617
+ %div
618
+ foo}
619
+ html = %q{}
620
+ locals = {}
621
+ options = {}
622
+ assert_ugly(haml, locals, options)
623
+ end
624
+
625
+ specify "a multiply nested silent comment with inconsistent indents" do
626
+ haml = %q{-#
627
+ %div
628
+ foo}
629
+ html = %q{}
630
+ locals = {}
631
+ options = {}
632
+ assert_ugly(haml, locals, options)
633
+ end
634
+ end
635
+
636
+ context "markup comments" do
637
+ specify "an inline markup comment" do
638
+ haml = %q{/ comment}
639
+ html = %q{<!-- comment -->}
640
+ locals = {}
641
+ options = {}
642
+ assert_ugly(haml, locals, options)
643
+ end
644
+
645
+ specify "a nested markup comment" do
646
+ haml = %q{/
647
+ comment
648
+ comment2}
649
+ html = %q{<!--
650
+ comment
651
+ comment2
652
+ -->}
653
+ locals = {}
654
+ options = {}
655
+ assert_ugly(haml, locals, options)
656
+ end
657
+ end
658
+
659
+ context "conditional comments" do
660
+ specify "a conditional comment" do
661
+ haml = %q{/[if IE]
662
+ %p a}
663
+ html = %q{<!--[if IE]>
664
+ <p>a</p>
665
+ <![endif]-->}
666
+ locals = {}
667
+ options = {}
668
+ assert_ugly(haml, locals, options)
669
+ end
670
+ end
671
+
672
+ context "internal filters" do
673
+ specify "content in an 'escaped' filter" do
674
+ haml = %q{:escaped
675
+ <&">}
676
+ html = %q{&lt;&amp;&quot;&gt;}
677
+ locals = {}
678
+ options = {}
679
+ assert_ugly(haml, locals, options)
680
+ end
681
+
682
+ specify "content in a 'preserve' filter" do
683
+ haml = %q{:preserve
684
+ hello
685
+
686
+ %p}
687
+ html = %q{hello&#x000A;
688
+ <p></p>}
689
+ locals = {}
690
+ options = {}
691
+ assert_ugly(haml, locals, options)
692
+ end
693
+
694
+ specify "content in a 'plain' filter" do
695
+ haml = %q{:plain
696
+ hello
697
+
698
+ %p}
699
+ html = %q{hello
700
+ <p></p>}
701
+ locals = {}
702
+ options = {}
703
+ assert_ugly(haml, locals, options)
704
+ end
705
+
706
+ specify "content in a 'css' filter (XHTML)" do
707
+ haml = %q{:css
708
+ hello
709
+
710
+ %p}
711
+ html = %q{<style type='text/css'>
712
+ /*<![CDATA[*/
713
+ hello
714
+ /*]]>*/
715
+ </style>
716
+ <p></p>}
717
+ locals = {}
718
+ options = {:format=>:xhtml}
719
+ assert_ugly(haml, locals, options)
720
+ end
721
+
722
+ specify "content in a 'javascript' filter (XHTML)" do
723
+ haml = %q{:javascript
724
+ a();
725
+ %p}
726
+ html = %q{<script type='text/javascript'>
727
+ //<![CDATA[
728
+ a();
729
+ //]]>
730
+ </script>
731
+ <p></p>}
732
+ locals = {}
733
+ options = {:format=>:xhtml}
734
+ assert_ugly(haml, locals, options)
735
+ end
736
+
737
+ specify "content in a 'css' filter (HTML)" do
738
+ haml = %q{:css
739
+ hello
740
+
741
+ %p}
742
+ html = %q{<style>
743
+ hello
744
+ </style>
745
+ <p></p>}
746
+ locals = {}
747
+ options = {:format=>:html5}
748
+ assert_ugly(haml, locals, options)
749
+ end
750
+
751
+ specify "content in a 'javascript' filter (HTML)" do
752
+ haml = %q{:javascript
753
+ a();
754
+ %p}
755
+ html = %q{<script>
756
+ a();
757
+ </script>
758
+ <p></p>}
759
+ locals = {}
760
+ options = {:format=>:html5}
761
+ assert_ugly(haml, locals, options)
762
+ end
763
+ end
764
+
765
+ context "Ruby-style interpolation" do
766
+ specify "interpolation inside inline content" do
767
+ haml = %q{%p #{var}}
768
+ html = %q{<p>value</p>}
769
+ locals = {:var=>"value"}
770
+ options = {}
771
+ assert_ugly(haml, locals, options)
772
+ end
773
+
774
+ specify "no interpolation when escaped" do
775
+ haml = %q{%p \#{var}}
776
+ html = %q{<p>#{var}</p>}
777
+ locals = {:var=>"value"}
778
+ options = {}
779
+ assert_ugly(haml, locals, options)
780
+ end
781
+
782
+ specify "interpolation when the escape character is escaped" do
783
+ haml = %q{%p \\#{var}}
784
+ html = %q{<p>\value</p>}
785
+ locals = {:var=>"value"}
786
+ options = {}
787
+ assert_ugly(haml, locals, options)
788
+ end
789
+
790
+ specify "interpolation inside filtered content" do
791
+ haml = %q{:plain
792
+ #{var} interpolated: #{var}}
793
+ html = %q{value interpolated: value}
794
+ locals = {:var=>"value"}
795
+ options = {}
796
+ assert_ugly(haml, locals, options)
797
+ end
798
+ end
799
+
800
+ context "HTML escaping" do
801
+ specify "code following '&='" do
802
+ haml = %q{&= '<"&>'}
803
+ html = %q{&lt;&quot;&amp;&gt;}
804
+ locals = {}
805
+ options = {}
806
+ assert_ugly(haml, locals, options)
807
+ end
808
+
809
+ specify "code following '=' when escape_haml is set to true" do
810
+ haml = %q{= '<"&>'}
811
+ html = %q{&lt;&quot;&amp;&gt;}
812
+ locals = {}
813
+ options = {:escape_html=>"true"}
814
+ assert_ugly(haml, locals, options)
815
+ end
816
+
817
+ specify "code following '!=' when escape_haml is set to true" do
818
+ haml = %q{!= '<"&>'}
819
+ html = %q{<"&>}
820
+ locals = {}
821
+ options = {:escape_html=>"true"}
822
+ assert_ugly(haml, locals, options)
823
+ end
824
+ end
825
+
826
+ context "boolean attributes" do
827
+ specify "boolean attribute with XHTML" do
828
+ haml = %q{%input(checked=true)}
829
+ html = %q{<input checked='checked' />}
830
+ locals = {}
831
+ options = {:format=>:xhtml}
832
+ assert_ugly(haml, locals, options)
833
+ end
834
+
835
+ specify "boolean attribute with HTML" do
836
+ haml = %q{%input(checked=true)}
837
+ html = %q{<input checked>}
838
+ locals = {}
839
+ options = {:format=>:html5}
840
+ assert_ugly(haml, locals, options)
841
+ end
842
+ end
843
+
844
+ context "whitespace preservation" do
845
+ specify "following the '~' operator" do
846
+ haml = %q{~ "Foo\n<pre>Bar\nBaz</pre>"}
847
+ html = %q{Foo
848
+ <pre>Bar&#x000A;Baz</pre>}
849
+ locals = {}
850
+ options = {}
851
+ assert_ugly(haml, locals, options)
852
+ end
853
+
854
+ specify "inside a textarea tag" do
855
+ haml = %q{%textarea
856
+ hello
857
+ hello}
858
+ html = %q{<textarea>hello
859
+ hello</textarea>}
860
+ locals = {}
861
+ options = {}
862
+ assert_ugly(haml, locals, options)
863
+ end
864
+
865
+ specify "inside a pre tag" do
866
+ haml = %q{%pre
867
+ hello
868
+ hello}
869
+ html = %q{<pre>hello
870
+ hello</pre>}
871
+ locals = {}
872
+ options = {}
873
+ assert_ugly(haml, locals, options)
874
+ end
875
+ end
876
+
877
+ context "whitespace removal" do
878
+ specify "a tag with '>' appended and inline content" do
879
+ haml = %q{%li hello
880
+ %li> world
881
+ %li again}
882
+ html = %q{<li>hello</li><li>world</li><li>again</li>}
883
+ locals = {}
884
+ options = {}
885
+ assert_ugly(haml, locals, options)
886
+ end
887
+
888
+ specify "a tag with '>' appended and nested content" do
889
+ haml = %q{%li hello
890
+ %li>
891
+ world
892
+ %li again}
893
+ html = %q{<li>hello</li><li>
894
+ world
895
+ </li><li>again</li>}
896
+ locals = {}
897
+ options = {}
898
+ assert_ugly(haml, locals, options)
899
+ end
900
+
901
+ specify "a tag with '<' appended" do
902
+ haml = %q{%p<
903
+ hello
904
+ world}
905
+ html = %q{<p>hello
906
+ world</p>}
907
+ locals = {}
908
+ options = {}
909
+ assert_ugly(haml, locals, options)
910
+ end
911
+ end
912
+ end