hamlit 1.7.2 → 2.0.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.
Files changed (283) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -3
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +25 -37
  5. data/CHANGELOG.md +18 -0
  6. data/Gemfile +16 -0
  7. data/LICENSE.txt +23 -2
  8. data/README.md +106 -48
  9. data/REFERENCE.md +222 -0
  10. data/Rakefile +77 -19
  11. data/benchmark/boolean_attribute.haml +6 -0
  12. data/benchmark/class_attribute.haml +5 -0
  13. data/benchmark/common_attribute.haml +3 -0
  14. data/benchmark/data_attribute.haml +4 -0
  15. data/benchmark/dynamic_attributes/boolean_attribute.haml +4 -0
  16. data/benchmark/dynamic_attributes/class_attribute.haml +4 -0
  17. data/benchmark/dynamic_attributes/common_attribute.haml +2 -0
  18. data/benchmark/dynamic_attributes/data_attribute.haml +2 -0
  19. data/benchmark/dynamic_attributes/id_attribute.haml +2 -0
  20. data/benchmark/etc/attribute_builder.haml +5 -0
  21. data/benchmark/etc/real_sample.haml +888 -0
  22. data/benchmark/etc/real_sample.rb +11 -0
  23. data/benchmark/etc/static_analyzer.haml +1 -0
  24. data/benchmark/etc/tags.haml +3 -0
  25. data/benchmark/ext/build_data.rb +15 -0
  26. data/benchmark/ext/build_id.rb +13 -0
  27. data/benchmark/id_attribute.haml +3 -0
  28. data/benchmark/plain.haml +4 -0
  29. data/benchmark/script.haml +4 -0
  30. data/benchmark/slim/LICENSE +21 -0
  31. data/{benchmarks → benchmark/slim}/context.rb +2 -4
  32. data/benchmark/slim/run-benchmarks.rb +94 -0
  33. data/{benchmarks → benchmark/slim}/view.erb +3 -3
  34. data/{benchmarks → benchmark/slim}/view.haml +0 -0
  35. data/{benchmarks/view.escaped.slim → benchmark/slim/view.slim} +1 -1
  36. data/benchmark/string_interpolation.haml +2 -0
  37. data/benchmark/utils/benchmark_ips_extension.rb +43 -0
  38. data/bin/bench +85 -0
  39. data/bin/clone +14 -0
  40. data/bin/console +11 -0
  41. data/bin/lineprof +48 -0
  42. data/bin/ruby +3 -0
  43. data/bin/setup +7 -0
  44. data/bin/stackprof +27 -0
  45. data/{test → bin/test} +6 -10
  46. data/{bin → exe}/hamlit +0 -0
  47. data/ext/hamlit/extconf.rb +14 -0
  48. data/ext/hamlit/hamlit.c +512 -0
  49. data/ext/hamlit/houdini/.gitignore +3 -0
  50. data/ext/hamlit/houdini/COPYING +7 -0
  51. data/ext/hamlit/houdini/Makefile +79 -0
  52. data/ext/hamlit/houdini/README.md +59 -0
  53. data/ext/hamlit/houdini/buffer.c +249 -0
  54. data/ext/hamlit/houdini/buffer.h +113 -0
  55. data/ext/hamlit/houdini/houdini.h +46 -0
  56. data/ext/hamlit/houdini/houdini_href_e.c +115 -0
  57. data/ext/hamlit/houdini/houdini_html_e.c +90 -0
  58. data/ext/hamlit/houdini/houdini_html_u.c +122 -0
  59. data/ext/hamlit/houdini/houdini_js_e.c +90 -0
  60. data/ext/hamlit/houdini/houdini_js_u.c +60 -0
  61. data/ext/hamlit/houdini/houdini_uri_e.c +107 -0
  62. data/ext/hamlit/houdini/houdini_uri_u.c +68 -0
  63. data/ext/hamlit/houdini/houdini_xml_e.c +136 -0
  64. data/ext/hamlit/houdini/html_unescape.gperf +258 -0
  65. data/ext/hamlit/houdini/html_unescape.h +754 -0
  66. data/ext/hamlit/houdini/tools/build_table.py +13 -0
  67. data/ext/hamlit/houdini/tools/build_tables.c +51 -0
  68. data/ext/hamlit/houdini/tools/wikipedia_table.txt +2025 -0
  69. data/hamlit.gemspec +30 -31
  70. data/lib/hamlit.rb +3 -1
  71. data/lib/hamlit/attribute_builder.rb +12 -0
  72. data/lib/hamlit/cli.rb +44 -43
  73. data/lib/hamlit/compiler.rb +92 -16
  74. data/lib/hamlit/compiler/attribute_compiler.rb +148 -0
  75. data/lib/hamlit/compiler/children_compiler.rb +111 -0
  76. data/lib/hamlit/compiler/comment_compiler.rb +36 -0
  77. data/lib/hamlit/compiler/doctype_compiler.rb +45 -0
  78. data/lib/hamlit/compiler/script_compiler.rb +97 -0
  79. data/lib/hamlit/compiler/silent_script_compiler.rb +24 -0
  80. data/lib/hamlit/compiler/tag_compiler.rb +69 -0
  81. data/lib/hamlit/engine.rb +12 -7
  82. data/lib/hamlit/error.rb +14 -0
  83. data/lib/hamlit/escapable.rb +12 -0
  84. data/lib/hamlit/filters.rb +65 -0
  85. data/lib/hamlit/filters/base.rb +4 -62
  86. data/lib/hamlit/filters/coffee.rb +9 -7
  87. data/lib/hamlit/filters/css.rb +25 -8
  88. data/lib/hamlit/filters/erb.rb +4 -6
  89. data/lib/hamlit/filters/escaped.rb +11 -9
  90. data/lib/hamlit/filters/javascript.rb +25 -8
  91. data/lib/hamlit/filters/less.rb +9 -7
  92. data/lib/hamlit/filters/markdown.rb +5 -6
  93. data/lib/hamlit/filters/plain.rb +11 -15
  94. data/lib/hamlit/filters/preserve.rb +15 -5
  95. data/lib/hamlit/filters/ruby.rb +3 -5
  96. data/lib/hamlit/filters/sass.rb +9 -7
  97. data/lib/hamlit/filters/scss.rb +9 -7
  98. data/lib/hamlit/filters/text_base.rb +24 -0
  99. data/lib/hamlit/filters/tilt_base.rb +47 -0
  100. data/lib/hamlit/hash_parser.rb +107 -0
  101. data/lib/hamlit/html.rb +9 -6
  102. data/lib/hamlit/identity.rb +12 -0
  103. data/lib/hamlit/object_ref.rb +29 -0
  104. data/lib/hamlit/parser.rb +25 -142
  105. data/lib/hamlit/parser/MIT-LICENSE +20 -0
  106. data/lib/hamlit/parser/README.md +28 -0
  107. data/lib/hamlit/parser/haml_buffer.rb +348 -0
  108. data/lib/hamlit/parser/haml_compiler.rb +553 -0
  109. data/lib/hamlit/parser/haml_error.rb +61 -0
  110. data/lib/hamlit/parser/haml_helpers.rb +727 -0
  111. data/lib/hamlit/parser/haml_options.rb +286 -0
  112. data/lib/hamlit/parser/haml_parser.rb +801 -0
  113. data/lib/hamlit/parser/haml_util.rb +283 -0
  114. data/lib/hamlit/parser/haml_xss_mods.rb +109 -0
  115. data/lib/hamlit/{helpers.rb → rails_helpers.rb} +2 -7
  116. data/lib/hamlit/rails_template.rb +30 -0
  117. data/lib/hamlit/railtie.rb +1 -12
  118. data/lib/hamlit/ruby_expression.rb +31 -0
  119. data/lib/hamlit/static_analyzer.rb +49 -0
  120. data/lib/hamlit/string_interpolation.rb +69 -0
  121. data/lib/hamlit/template.rb +8 -0
  122. data/lib/hamlit/utils.rb +9 -0
  123. data/lib/hamlit/version.rb +1 -1
  124. metadata +116 -324
  125. data/.rspec +0 -2
  126. data/benchmarks/benchmark.rb +0 -110
  127. data/benchmarks/view.slim +0 -17
  128. data/doc/README.md +0 -19
  129. data/doc/engine/indent.md +0 -48
  130. data/doc/engine/new_attribute.md +0 -77
  131. data/doc/engine/old_attributes.md +0 -198
  132. data/doc/engine/silent_script.md +0 -97
  133. data/doc/engine/tag.md +0 -48
  134. data/doc/engine/text.md +0 -64
  135. data/doc/faml/README.md +0 -16
  136. data/doc/faml/engine/indent.md +0 -48
  137. data/doc/faml/engine/old_attributes.md +0 -111
  138. data/doc/faml/engine/silent_script.md +0 -97
  139. data/doc/faml/engine/text.md +0 -59
  140. data/doc/faml/filters/erb.md +0 -24
  141. data/doc/faml/filters/javascript.md +0 -27
  142. data/doc/faml/filters/less.md +0 -57
  143. data/doc/faml/filters/plain.md +0 -25
  144. data/doc/filters/erb.md +0 -31
  145. data/doc/filters/javascript.md +0 -83
  146. data/doc/filters/less.md +0 -57
  147. data/doc/filters/markdown.md +0 -31
  148. data/doc/filters/plain.md +0 -25
  149. data/doc/haml/README.md +0 -15
  150. data/doc/haml/engine/new_attribute.md +0 -77
  151. data/doc/haml/engine/old_attributes.md +0 -142
  152. data/doc/haml/engine/tag.md +0 -48
  153. data/doc/haml/engine/text.md +0 -29
  154. data/doc/haml/filters/erb.md +0 -26
  155. data/doc/haml/filters/javascript.md +0 -76
  156. data/doc/haml/filters/markdown.md +0 -31
  157. data/lib/hamlit/attribute.rb +0 -78
  158. data/lib/hamlit/compilers/attributes.rb +0 -108
  159. data/lib/hamlit/compilers/comment.rb +0 -13
  160. data/lib/hamlit/compilers/doctype.rb +0 -39
  161. data/lib/hamlit/compilers/filter.rb +0 -53
  162. data/lib/hamlit/compilers/new_attribute.rb +0 -115
  163. data/lib/hamlit/compilers/old_attribute.rb +0 -241
  164. data/lib/hamlit/compilers/runtime_attribute.rb +0 -58
  165. data/lib/hamlit/compilers/script.rb +0 -31
  166. data/lib/hamlit/compilers/strip.rb +0 -19
  167. data/lib/hamlit/compilers/text.rb +0 -111
  168. data/lib/hamlit/concerns/attribute_builder.rb +0 -22
  169. data/lib/hamlit/concerns/balanceable.rb +0 -68
  170. data/lib/hamlit/concerns/deprecation.rb +0 -20
  171. data/lib/hamlit/concerns/error.rb +0 -31
  172. data/lib/hamlit/concerns/escapable.rb +0 -17
  173. data/lib/hamlit/concerns/included.rb +0 -28
  174. data/lib/hamlit/concerns/indentable.rb +0 -117
  175. data/lib/hamlit/concerns/lexable.rb +0 -32
  176. data/lib/hamlit/concerns/line_reader.rb +0 -62
  177. data/lib/hamlit/concerns/registerable.rb +0 -24
  178. data/lib/hamlit/concerns/string_interpolation.rb +0 -48
  179. data/lib/hamlit/concerns/whitespace.rb +0 -91
  180. data/lib/hamlit/filters/tilt.rb +0 -41
  181. data/lib/hamlit/parsers/attribute.rb +0 -71
  182. data/lib/hamlit/parsers/comment.rb +0 -30
  183. data/lib/hamlit/parsers/doctype.rb +0 -18
  184. data/lib/hamlit/parsers/filter.rb +0 -18
  185. data/lib/hamlit/parsers/multiline.rb +0 -58
  186. data/lib/hamlit/parsers/script.rb +0 -126
  187. data/lib/hamlit/parsers/tag.rb +0 -83
  188. data/lib/hamlit/parsers/text.rb +0 -28
  189. data/lib/hamlit/temple.rb +0 -9
  190. data/release +0 -6
  191. data/spec/Rakefile +0 -72
  192. data/spec/hamlit/engine/comment_spec.rb +0 -56
  193. data/spec/hamlit/engine/doctype_spec.rb +0 -19
  194. data/spec/hamlit/engine/error_spec.rb +0 -135
  195. data/spec/hamlit/engine/indent_spec.rb +0 -42
  196. data/spec/hamlit/engine/multiline_spec.rb +0 -44
  197. data/spec/hamlit/engine/new_attribute_spec.rb +0 -110
  198. data/spec/hamlit/engine/old_attributes_spec.rb +0 -404
  199. data/spec/hamlit/engine/script_spec.rb +0 -116
  200. data/spec/hamlit/engine/silent_script_spec.rb +0 -213
  201. data/spec/hamlit/engine/tag_spec.rb +0 -295
  202. data/spec/hamlit/engine/text_spec.rb +0 -239
  203. data/spec/hamlit/engine_spec.rb +0 -58
  204. data/spec/hamlit/filters/coffee_spec.rb +0 -60
  205. data/spec/hamlit/filters/css_spec.rb +0 -33
  206. data/spec/hamlit/filters/erb_spec.rb +0 -16
  207. data/spec/hamlit/filters/javascript_spec.rb +0 -82
  208. data/spec/hamlit/filters/less_spec.rb +0 -37
  209. data/spec/hamlit/filters/markdown_spec.rb +0 -30
  210. data/spec/hamlit/filters/plain_spec.rb +0 -15
  211. data/spec/hamlit/filters/ruby_spec.rb +0 -24
  212. data/spec/hamlit/filters/sass_spec.rb +0 -33
  213. data/spec/hamlit/filters/scss_spec.rb +0 -37
  214. data/spec/hamlit/haml_spec.rb +0 -910
  215. data/spec/rails/.gitignore +0 -18
  216. data/spec/rails/.rspec +0 -2
  217. data/spec/rails/Gemfile +0 -19
  218. data/spec/rails/README.rdoc +0 -28
  219. data/spec/rails/Rakefile +0 -6
  220. data/spec/rails/app/assets/images/.keep +0 -0
  221. data/spec/rails/app/assets/javascripts/application.js +0 -15
  222. data/spec/rails/app/assets/stylesheets/application.css +0 -15
  223. data/spec/rails/app/controllers/application_controller.rb +0 -8
  224. data/spec/rails/app/controllers/concerns/.keep +0 -0
  225. data/spec/rails/app/controllers/users_controller.rb +0 -23
  226. data/spec/rails/app/helpers/application_helper.rb +0 -2
  227. data/spec/rails/app/mailers/.keep +0 -0
  228. data/spec/rails/app/models/.keep +0 -0
  229. data/spec/rails/app/models/concerns/.keep +0 -0
  230. data/spec/rails/app/views/application/index.html.haml +0 -18
  231. data/spec/rails/app/views/layouts/application.html.haml +0 -12
  232. data/spec/rails/app/views/users/capture.html.haml +0 -5
  233. data/spec/rails/app/views/users/capture_haml.html.haml +0 -5
  234. data/spec/rails/app/views/users/form.html.haml +0 -2
  235. data/spec/rails/app/views/users/helpers.html.haml +0 -10
  236. data/spec/rails/app/views/users/index.html.haml +0 -9
  237. data/spec/rails/app/views/users/inline.html.haml +0 -6
  238. data/spec/rails/app/views/users/old_attributes.html.haml +0 -5
  239. data/spec/rails/app/views/users/safe_buffer.html.haml +0 -4
  240. data/spec/rails/app/views/users/whitespace.html.haml +0 -4
  241. data/spec/rails/bin/bundle +0 -3
  242. data/spec/rails/bin/rails +0 -8
  243. data/spec/rails/bin/rake +0 -8
  244. data/spec/rails/bin/setup +0 -29
  245. data/spec/rails/bin/spring +0 -15
  246. data/spec/rails/config.ru +0 -4
  247. data/spec/rails/config/application.rb +0 -34
  248. data/spec/rails/config/boot.rb +0 -3
  249. data/spec/rails/config/database.yml +0 -25
  250. data/spec/rails/config/environment.rb +0 -5
  251. data/spec/rails/config/environments/development.rb +0 -41
  252. data/spec/rails/config/environments/production.rb +0 -79
  253. data/spec/rails/config/environments/test.rb +0 -42
  254. data/spec/rails/config/initializers/assets.rb +0 -11
  255. data/spec/rails/config/initializers/backtrace_silencers.rb +0 -7
  256. data/spec/rails/config/initializers/cookies_serializer.rb +0 -3
  257. data/spec/rails/config/initializers/filter_parameter_logging.rb +0 -4
  258. data/spec/rails/config/initializers/inflections.rb +0 -16
  259. data/spec/rails/config/initializers/mime_types.rb +0 -4
  260. data/spec/rails/config/initializers/session_store.rb +0 -3
  261. data/spec/rails/config/initializers/wrap_parameters.rb +0 -14
  262. data/spec/rails/config/locales/en.yml +0 -24
  263. data/spec/rails/config/routes.rb +0 -16
  264. data/spec/rails/config/secrets.yml +0 -22
  265. data/spec/rails/db/schema.rb +0 -16
  266. data/spec/rails/db/seeds.rb +0 -7
  267. data/spec/rails/lib/assets/.keep +0 -0
  268. data/spec/rails/lib/tasks/.keep +0 -0
  269. data/spec/rails/log/.keep +0 -0
  270. data/spec/rails/public/404.html +0 -67
  271. data/spec/rails/public/422.html +0 -67
  272. data/spec/rails/public/500.html +0 -66
  273. data/spec/rails/public/favicon.ico +0 -0
  274. data/spec/rails/public/robots.txt +0 -5
  275. data/spec/rails/spec/hamlit_spec.rb +0 -123
  276. data/spec/rails/spec/rails_helper.rb +0 -56
  277. data/spec/rails/spec/spec_helper.rb +0 -91
  278. data/spec/rails/vendor/assets/javascripts/.keep +0 -0
  279. data/spec/rails/vendor/assets/stylesheets/.keep +0 -0
  280. data/spec/spec_helper.rb +0 -36
  281. data/spec/spec_helper/document_generator.rb +0 -93
  282. data/spec/spec_helper/render_helper.rb +0 -120
  283. data/spec/spec_helper/test_case.rb +0 -55
@@ -1,19 +0,0 @@
1
- describe Hamlit::Engine do
2
- describe 'doctype' do
3
- it 'renders html5 doctype' do
4
- assert_render(<<-HAML, <<-HTML)
5
- !!!
6
- HAML
7
- <!DOCTYPE html>
8
- HTML
9
- end
10
-
11
- it 'renders xml doctype' do
12
- assert_render(<<-HAML, <<-HTML, format: :xhtml)
13
- !!! XML
14
- HAML
15
- <?xml version='1.0' encoding='utf-8' ?>
16
- HTML
17
- end
18
- end
19
- end
@@ -1,135 +0,0 @@
1
- describe Hamlit::Engine do
2
- describe 'syntax error' do
3
- it 'raises syntax error for empty =' do
4
- expect { render_string('= ') }.to raise_error(
5
- Hamlit::SyntaxError,
6
- "There's no Ruby code for = to evaluate.",
7
- )
8
- end
9
-
10
- it 'raises syntax error for illegal indentation' do
11
- expect { render_string(<<-HAML.unindent) }.
12
- %a
13
- %b
14
- %a
15
- HAML
16
- to raise_error(Hamlit::SyntaxError, 'Inconsistent indentation: 1 space used for indentation, but the rest of the document was indented using 4 spaces.')
17
- end
18
-
19
- it 'raises syntax error for illegal indentation' do
20
- expect { render_string(<<-HAML.unindent) }.
21
- %a
22
- \t\t%a
23
- \t%a
24
- HAML
25
- to raise_error(Hamlit::SyntaxError, 'Inconsistent indentation: 1 tab used for indentation, but the rest of the document was indented using 2 tabs.')
26
- end
27
-
28
- it 'raises syntax error which has correct line number in backtrace' do
29
- begin
30
- render_string(<<-HAML.unindent)
31
- %1
32
- %2
33
- %3
34
- %4
35
- %5
36
- %6
37
- %7
38
- %8 this is invalid indent
39
- %9
40
- HAML
41
- rescue Hamlit::SyntaxError => e
42
- if e.respond_to?(:backtrace_locations)
43
- line_number = e.backtrace_locations.first.to_s.match(/:(\d+):/)[1]
44
- expect(line_number).to eq('8')
45
- end
46
- end
47
- end
48
-
49
- it 'raises syntax error for an inconsistent indentation' do
50
- expect { render_string(<<-HAML.unindent) }.
51
- %a
52
- %b
53
- \t\t%b
54
- HAML
55
- to raise_error(Hamlit::SyntaxError, 'Inconsistent indentation: 2 tabs used for indentation, but the rest of the document was indented using 2 spaces.')
56
- end
57
-
58
- it 'raises syntax error for an inconsistent indentation' do
59
- expect { render_string(<<-'HAML'.unindent) }.
60
- 1#{2
61
- HAML
62
- to raise_error(Hamlit::SyntaxError, 'Unbalanced brackets.')
63
- end
64
-
65
- it 'raises syntax error for an inconsistent indentation' do
66
- expect { render_string(<<-HAML.unindent) }.
67
- %p
68
- \t %span
69
- HAML
70
- to raise_error(Hamlit::SyntaxError, "Indentation can't use both tabs and spaces.")
71
- end
72
-
73
- it 'raises syntax error for an inconsistent indentation' do
74
- expect { render_string(<<-HAML.unindent) }.
75
- %div/ foo
76
- HAML
77
- to raise_error(Hamlit::SyntaxError, "Self-closing tags can't have content.")
78
- end
79
-
80
- it 'raises syntax error for an inconsistent indentation' do
81
- expect { render_string(<<-HAML.unindent) }.
82
- %div/
83
- foo
84
- HAML
85
- to raise_error(Hamlit::SyntaxError, "Illegal nesting: nesting within a self-closing tag is illegal.")
86
- end
87
-
88
- it 'rejects illegal indentation' do
89
- expect { render_string(<<-HAML.unindent) }.
90
- hello
91
- world
92
- HAML
93
- to raise_error(Hamlit::SyntaxError, 'Illegal nesting: nesting within plain text is illegal.')
94
- end
95
-
96
- it 'rejects illegal indentation' do
97
- expect { render_string(<<-HAML.unindent) }.
98
- %span hello
99
- world
100
- HAML
101
- to raise_error(Hamlit::SyntaxError, "Illegal nesting: content can't be both given on the same line as %span and nested within it.")
102
- end
103
-
104
- it 'rejects illegal indentation' do
105
- expect { render_string(<<-HAML.unindent) }.
106
- / hello
107
- world
108
- HAML
109
- to raise_error(Hamlit::SyntaxError, 'Illegal nesting: nesting within a tag that already has content is illegal.')
110
- end
111
-
112
- it 'rejects illegal indentation' do
113
- expect { render_string(<<-HAML.unindent) }.
114
- %span
115
- %span
116
- %span
117
- HAML
118
- to raise_error(Hamlit::SyntaxError, 'The line was indented 2 levels deeper than the previous line.')
119
- end
120
-
121
- it 'rejects illegal indentation' do
122
- expect { render_string(<<-HAML.unindent) }.
123
- %span
124
- %span
125
- %span
126
- HAML
127
- to raise_error(Hamlit::SyntaxError, "Inconsistent indentation: 6 spaces used for indentation, but the rest of the document was indented using 4 spaces.")
128
- end
129
-
130
- it 'rejects illegal indentation' do
131
- expect { render_string(' hello') }.
132
- to raise_error(Hamlit::SyntaxError, 'Indenting at the beginning of the document is illegal.')
133
- end
134
- end
135
- end
@@ -1,42 +0,0 @@
1
- describe Hamlit::Engine do
2
- describe 'tab indent' do
3
- it 'accepts tab indentation' do
4
- assert_render(<<-HAML, <<-HTML, compatible_only: :haml, error_with: :faml)
5
- %p
6
- \t%a
7
- HAML
8
- <p>
9
- <a></a>
10
- </p>
11
- HTML
12
- end
13
-
14
- it 'accepts N-space indentation' do
15
- assert_render(<<-HAML, <<-HTML)
16
- %p
17
- %span
18
- foo
19
- HAML
20
- <p>
21
- <span>
22
- foo
23
- </span>
24
- </p>
25
- HTML
26
- end
27
-
28
- it 'accepts N-tab indentation' do
29
- assert_render(<<-HAML, <<-HTML, compatible_only: :haml, error_with: :faml)
30
- %p
31
- \t%span
32
- \t\tfoo
33
- HAML
34
- <p>
35
- <span>
36
- foo
37
- </span>
38
- </p>
39
- HTML
40
- end
41
- end
42
- end
@@ -1,44 +0,0 @@
1
- describe Hamlit::Engine do
2
- describe 'multiline' do
3
- it 'joins multi-lines ending with pipe' do
4
- assert_render(<<-HAML, <<-HTML)
5
- a |
6
- b |
7
- HAML
8
- a b
9
- HTML
10
- end
11
-
12
- it 'renders multi lines' do
13
- assert_render(<<-HAML, <<-HTML)
14
- = 'a' + |
15
- 'b' + |
16
- 'c' |
17
- 'd'
18
- HAML
19
- abc
20
- 'd'
21
- HTML
22
- end
23
-
24
- it 'accepts invalid indent' do
25
- assert_render(<<-HAML, <<-HTML)
26
- %span
27
- %div
28
- = '1' + |
29
- '2' |
30
- %div
31
- 3
32
- HAML
33
- <span>
34
- <div>
35
- 12
36
- </div>
37
- <div>
38
- 3
39
- </div>
40
- </span>
41
- HTML
42
- end
43
- end
44
- end
@@ -1,110 +0,0 @@
1
- describe Hamlit::Engine do
2
- describe 'new attributes' do
3
- it 'renders attributes' do
4
- assert_render(<<-HAML, <<-HTML)
5
- %p(class='foo') bar
6
- HAML
7
- <p class='foo'>bar</p>
8
- HTML
9
- end
10
-
11
- it 'renders multiple attributes' do
12
- assert_render(<<-HAML, <<-HTML)
13
- %p(a=1 b=2) bar
14
- HAML
15
- <p a='1' b='2'>bar</p>
16
- HTML
17
- end
18
-
19
- it 'renders multi-line attributes properly' do
20
- assert_render(<<-HAML, <<-HTML, compatible_only: :faml)
21
- %span(a=__LINE__
22
- b=__LINE__)
23
- = __LINE__
24
- HAML
25
- <span a='1' b='2'></span>
26
- 3
27
- HTML
28
- end
29
-
30
- it 'renders hyphenated attributes properly' do
31
- assert_render(<<-HAML, <<-HTML)
32
- %p(data-foo='bar') bar
33
- HAML
34
- <p data-foo='bar'>bar</p>
35
- HTML
36
- end
37
-
38
- it 'renders multiply hyphenated attributes properly' do
39
- assert_render(<<-HAML, <<-HTML)
40
- %p(data-x-foo='bar') bar
41
- HAML
42
- <p data-x-foo='bar'>bar</p>
43
- HTML
44
- end
45
-
46
- describe 'html escape' do
47
- it 'escapes attribute values on static attributes' do
48
- assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
49
- %a(title="'")
50
- %a(title = "'\"")
51
- %a(href='/search?foo=bar&hoge=<fuga>')
52
- HAML
53
- <a title='&#39;'></a>
54
- <a title='&#39;&quot;'></a>
55
- <a href='/search?foo=bar&amp;hoge=&lt;fuga&gt;'></a>
56
- HTML
57
- end
58
-
59
- it 'escapes attribute values on dynamic attributes' do
60
- assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
61
- - title = "'\""
62
- - href = '/search?foo=bar&hoge=<fuga>'
63
- %a(title=title)
64
- %a(href=href)
65
- HAML
66
- <a title='&#39;&quot;'></a>
67
- <a href='/search?foo=bar&amp;hoge=&lt;fuga&gt;'></a>
68
- HTML
69
- end
70
- end
71
-
72
- describe 'element class with attribute class' do
73
- it 'does not generate double classes' do
74
- assert_render(<<-HAML, <<-HTML)
75
- .item(class='first')
76
- HAML
77
- <div class='first item'></div>
78
- HTML
79
- end
80
-
81
- it 'does not generate double classes for a variable' do
82
- assert_render(<<-HAML, <<-HTML)
83
- - val = 'val'
84
- .element(class=val)
85
- HAML
86
- <div class='element val'></div>
87
- HTML
88
- end
89
- end
90
-
91
- describe 'element id with attribute id' do
92
- it 'concatenates ids with underscore' do
93
- assert_render(<<-HAML, <<-HTML)
94
- #item(id='first')
95
- HAML
96
- <div id='item_first'></div>
97
- HTML
98
- end
99
-
100
- it 'concatenates ids with underscore for a variable' do
101
- assert_render(<<-HAML, <<-HTML)
102
- - val = 'first'
103
- #item(id=val)
104
- HAML
105
- <div id='item_first'></div>
106
- HTML
107
- end
108
- end
109
- end
110
- end
@@ -1,404 +0,0 @@
1
- describe Hamlit::Engine do
2
- describe 'old attributes' do
3
- it 'renders attributes' do
4
- assert_render(<<-HAML, <<-HTML)
5
- %span{class: 'foo'} bar
6
- HAML
7
- <span class='foo'>bar</span>
8
- HTML
9
- end
10
-
11
- it 'renders attributes' do
12
- assert_render(<<-HAML, <<-HTML)
13
- %span{ data: 2 } bar
14
- HAML
15
- <span data='2'>bar</span>
16
- HTML
17
- end
18
-
19
- it 'renders attributes' do
20
- assert_render(<<-'HAML', <<-HTML)
21
- %span{ :class => 'foo' } bar
22
- HAML
23
- <span class='foo'>bar</span>
24
- HTML
25
- end
26
-
27
- it 'renders attributes' do
28
- assert_render(<<-'HAML', <<-HTML)
29
- %span{ :class => 'foo', id: 'bar' } bar
30
- HAML
31
- <span class='foo' id='bar'>bar</span>
32
- HTML
33
- end
34
-
35
- it 'renders attributes' do
36
- assert_render(<<-'HAML', <<-HTML)
37
- %span{ :'data-disable' => true } bar
38
- HAML
39
- <span data-disable>bar</span>
40
- HTML
41
- end
42
-
43
- it 'accepts even illegal input for haml' do
44
- assert_render(<<-'HAML', <<-HTML, error_with: [:haml, :faml])
45
- %span{ class: '}}}', id: '{}}' } }{
46
- HAML
47
- <span class='}}}' id='{}}'>}{</span>
48
- HTML
49
- end
50
-
51
- it 'accepts method call including comma' do
52
- assert_render(<<-'HAML', <<-HTML)
53
- %body{ class: "#{"ab".gsub(/a/, 'b')}", data: { confirm: 'really?', disable: true }, id: 'c'.gsub(/c/, 'a') }
54
- HAML
55
- <body class='bb' data-confirm='really?' data-disable id='a'></body>
56
- HTML
57
- end
58
-
59
- it 'accepts tag content' do
60
- assert_render(<<-'HAML', <<-HTML)
61
- %span{ class: 'foo' } <b>bar</b>
62
- HAML
63
- <span class='foo'><b>bar</b></span>
64
- HTML
65
- end
66
-
67
- it 'renders multi-byte chars as static attribute value' do
68
- assert_render(<<-'HAML', <<-HTML)
69
- %img{ alt: 'こんにちは' }
70
- HAML
71
- <img alt='こんにちは'>
72
- HTML
73
- end
74
-
75
- it 'sorts static attributes by name' do
76
- assert_render(<<-HAML, <<-HTML)
77
- %span{ :foo => "bar", :hoge => "piyo"}
78
- %span{ :hoge => "piyo", :foo => "bar"}
79
- HAML
80
- <span foo='bar' hoge='piyo'></span>
81
- <span foo='bar' hoge='piyo'></span>
82
- HTML
83
- end
84
-
85
- describe 'runtime attributes' do
86
- it 'renders runtime hash attribute' do
87
- assert_render(<<-'HAML', <<-HTML)
88
- - hash = { foo: 'bar' }
89
- %span{ hash }
90
- HAML
91
- <span foo='bar'></span>
92
- HTML
93
- end
94
-
95
- it 'renders multiples hashes' do
96
- assert_render(<<-'HAML', <<-HTML)
97
- - h1 = { a: 'b' }
98
- - h2 = { c: 'd' }
99
- - h3 = { e: 'f' }
100
- %span{ h1, h2, h3 }
101
- HAML
102
- <span a='b' c='d' e='f'></span>
103
- HTML
104
- end
105
-
106
- it 'renders multiples hashes and literal hash' do
107
- assert_render(<<-'HAML', <<-HTML)
108
- - h1 = { a: 'b' }
109
- - h2 = { c: 'd' }
110
- - h3 = { e: 'f' }
111
- %span{ h1, h2, h3, g: 'h', i: 'j' }
112
- HAML
113
- <span a='b' c='d' e='f' g='h' i='j'></span>
114
- HTML
115
- end
116
- end
117
-
118
- describe 'joinable attributes' do
119
- it 'joins class with a space' do
120
- assert_render(<<-'HAML', <<-HTML)
121
- - val = ['a', 'b', 'c']
122
- %p{ class: val }
123
- %p{ class: %w[a b c] }
124
- %p{ class: ['a', 'b', 'c'] }
125
- HAML
126
- <p class='a b c'></p>
127
- <p class='a b c'></p>
128
- <p class='a b c'></p>
129
- HTML
130
- end
131
-
132
- it 'joins attribute class and element class' do
133
- assert_render(<<-HAML, <<-HTML, compatible_only: :haml)
134
- .foo{ class: ['bar'] }
135
- .foo{ class: ['bar', 'foo'] }
136
- .foo{ class: ['bar', nil] }
137
- .foo{ class: ['bar', 'baz'] }
138
- HAML
139
- <div class='bar foo'></div>
140
- <div class='bar foo'></div>
141
- <div class='bar foo'></div>
142
- <div class='bar baz foo'></div>
143
- HTML
144
- end
145
-
146
- it 'joins id with an underscore' do
147
- assert_render(<<-'HAML', <<-HTML)
148
- - val = ['a', 'b', 'c']
149
- %p{ id: val }
150
- %p{ id: %w[a b c] }
151
- %p{ id: ['a', 'b', 'c'] }
152
- HAML
153
- <p id='a_b_c'></p>
154
- <p id='a_b_c'></p>
155
- <p id='a_b_c'></p>
156
- HTML
157
- end
158
-
159
- it 'does not join others' do
160
- assert_render(<<-'HAML', <<-HTML)
161
- %a{ data: { value: [count: 1] } }
162
- HAML
163
- <a data-value='[{:count=&gt;1}]'></a>
164
- HTML
165
- end
166
- end
167
-
168
- describe 'deletable attributes' do
169
- it 'deletes attributes whose value is nil or false' do
170
- assert_render(<<-'HAML', <<-HTML)
171
- - hash = { checked: false }
172
- %input{ hash }
173
- %input{ checked: false }
174
- %input{ checked: nil }
175
- - checked = nil
176
- %input{ checked: checked }
177
- - checked = false
178
- %input{ checked: checked }
179
- HAML
180
- <input>
181
- <input>
182
- <input>
183
- <input>
184
- <input>
185
- HTML
186
- end
187
-
188
- it 'deletes some limited attributes with dynamic value' do
189
- assert_render(<<-'HAML', <<-HTML)
190
- - val = false
191
- #foo.bar{ autofocus: val }
192
- #foo.bar{ checked: val }
193
- #foo.bar{ data: { disabled: val } }
194
- #foo.bar{ disabled: val }
195
- #foo.bar{ formnovalidate: val }
196
- #foo.bar{ multiple: val }
197
- #foo.bar{ readonly: val }
198
- #foo.bar{ required: val }
199
- HAML
200
- <div class='bar' id='foo'></div>
201
- <div class='bar' id='foo'></div>
202
- <div class='bar' id='foo'></div>
203
- <div class='bar' id='foo'></div>
204
- <div class='bar' id='foo'></div>
205
- <div class='bar' id='foo'></div>
206
- <div class='bar' id='foo'></div>
207
- <div class='bar' id='foo'></div>
208
- HTML
209
- end
210
-
211
- it 'does not delete non-boolean attributes, for optimization' do
212
- assert_render(<<-'HAML', <<-HTML, compatible_only: [])
213
- / wontfix: Non-boolean attributes are not escaped for optimization.
214
- - val = false
215
- %a{ href: val }
216
- - val = nil
217
- %a{ href: val }
218
-
219
- / Boolean attributes are escaped correctly.
220
- - val = false
221
- %a{ disabled: val }
222
- - val = nil
223
- %a{ disabled: val }
224
- HAML
225
- <!-- wontfix: Non-boolean attributes are not escaped for optimization. -->
226
- <a href='false'></a>
227
- <a href=''></a>
228
- <!-- Boolean attributes are escaped correctly. -->
229
- <a></a>
230
- <a></a>
231
- HTML
232
- end
233
- end
234
-
235
- describe 'html escape' do
236
- it 'escapes attribute values on static attributes' do
237
- assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
238
- %a{title: "'"}
239
- %a{title: "'\""}
240
- %a{href: '/search?foo=bar&hoge=<fuga>'}
241
- HAML
242
- <a title='&#39;'></a>
243
- <a title='&#39;&quot;'></a>
244
- <a href='/search?foo=bar&amp;hoge=&lt;fuga&gt;'></a>
245
- HTML
246
- end
247
-
248
- it 'escapes attribute values on dynamic attributes' do
249
- assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
250
- - title = "'\""
251
- - href = '/search?foo=bar&hoge=<fuga>'
252
- %a{title: title}
253
- %a{href: href}
254
- HAML
255
- <a title='&#39;&quot;'></a>
256
- <a href='/search?foo=bar&amp;hoge=&lt;fuga&gt;'></a>
257
- HTML
258
- end
259
-
260
- it 'escapes attribute values on hash attributes' do
261
- assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
262
- - title = { title: "'\"" }
263
- - href = { href: '/search?foo=bar&hoge=<fuga>' }
264
- %a{ title }
265
- %a{ href }
266
- HAML
267
- <a title='&#39;&quot;'></a>
268
- <a href='/search?foo=bar&amp;hoge=&lt;fuga&gt;'></a>
269
- HTML
270
- end
271
- end
272
-
273
- describe 'nested attributes' do
274
- it 'renders data attribute by hash' do
275
- assert_render(<<-'HAML', <<-HTML)
276
- - hash = { bar: 'baz' }
277
- %span.foo{ data: hash }
278
- HAML
279
- <span class='foo' data-bar='baz'></span>
280
- HTML
281
- end
282
-
283
- it 'renders true attributes' do
284
- assert_render(<<-'HAML', <<-HTML, compatible_only: :haml)
285
- %span{ data: { disable: true } } bar
286
- HAML
287
- <span data-disable>bar</span>
288
- HTML
289
- end
290
-
291
- it 'renders nested hash whose value is variable' do
292
- assert_render(<<-'HAML', <<-HTML)
293
- - hash = { disable: true }
294
- %span{ data: hash } bar
295
- HAML
296
- <span data-disable>bar</span>
297
- HTML
298
- end
299
-
300
- it 'changes an underscore in a nested key to a hyphen' do
301
- assert_render(<<-'HAML', <<-HTML)
302
- %div{ data: { raw_src: 'foo' } }
303
- HAML
304
- <div data-raw-src='foo'></div>
305
- HTML
306
- end
307
-
308
- it 'changes an underscore in a nested dynamic attribute' do
309
- assert_render(<<-'HAML', <<-HTML)
310
- - hash = { raw_src: 'foo' }
311
- %div{ data: hash }
312
- HAML
313
- <div data-raw-src='foo'></div>
314
- HTML
315
- end
316
- end
317
-
318
- describe 'element class with attribute class' do
319
- it 'does not generate double classes' do
320
- assert_render(<<-HAML, <<-HTML)
321
- .item{ class: 'first' }
322
- HAML
323
- <div class='first item'></div>
324
- HTML
325
- end
326
-
327
- it 'does not generate double classes for a variable' do
328
- assert_render(<<-HAML, <<-HTML)
329
- - val = 'val'
330
- .element{ class: val }
331
- HAML
332
- <div class='element val'></div>
333
- HTML
334
- end
335
-
336
- it 'does not generate double classes for hash attributes' do
337
- assert_render(<<-HAML, <<-HTML)
338
- - hash = { class: 'val' }
339
- .element{ hash }
340
- HAML
341
- <div class='element val'></div>
342
- HTML
343
- end
344
- end
345
-
346
- describe 'element id with attribute id' do
347
- it 'does not generate double ids' do
348
- assert_render(<<-HAML, <<-HTML)
349
- #item{ id: 'first' }
350
- HAML
351
- <div id='item_first'></div>
352
- HTML
353
- end
354
-
355
- it 'does not generate double ids for a variable' do
356
- assert_render(<<-HAML, <<-HTML)
357
- - val = 'first'
358
- #item{ id: val }
359
- HAML
360
- <div id='item_first'></div>
361
- HTML
362
- end
363
-
364
- it 'does not generate double ids for hash attributes' do
365
- assert_render(<<-HAML, <<-HTML)
366
- - hash = { id: 'first' }
367
- #item{ hash }
368
- HAML
369
- <div id='item_first'></div>
370
- HTML
371
- end
372
-
373
- it 'does not generate double ids and classes for hash attributes' do
374
- assert_render(<<-HAML, <<-HTML)
375
- - hash = { id: 'first', class: 'foo' }
376
- #item.bar{ hash }
377
- HAML
378
- <div class='bar foo' id='item_first'></div>
379
- HTML
380
- end
381
- end
382
-
383
- if RUBY_VERSION >= "2.2.0"
384
- describe 'Ruby 2.2 syntax' do
385
- it 'renders static attributes' do
386
- assert_render(<<-HAML, <<-HTML)
387
- %meta{ content: 'IE=edge', 'http-equiv': 'X-UA-Compatible' }
388
- HAML
389
- <meta content='IE=edge' http-equiv='X-UA-Compatible'>
390
- HTML
391
- end
392
-
393
- it 'renders dynamic attributes' do
394
- assert_render(<<-HAML, <<-HTML)
395
- - hash = { content: 'IE=edge' }
396
- %meta{ hash, 'http-equiv': 'X-UA-Compatible' }
397
- HAML
398
- <meta content='IE=edge' http-equiv='X-UA-Compatible'>
399
- HTML
400
- end
401
- end
402
- end
403
- end
404
- end