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,29 @@
1
+ describe Hamlit::Parser do
2
+ describe 'comment' do
3
+ it 'renders html comment' do
4
+ assert_render(<<-HAML, <<-HTML)
5
+ / comments
6
+ HAML
7
+ <!-- comments -->
8
+ HTML
9
+ end
10
+
11
+ it 'strips html comment ignoring around spcaes' do
12
+ assert_render('/ comments ', <<-HTML)
13
+ <!-- comments -->
14
+ HTML
15
+ end
16
+
17
+ it 'ignores multiline comment' do
18
+ assert_render(<<-'HAML', <<-HTML)
19
+ -# if true
20
+ - raise 'ng'
21
+ = invalid script
22
+ too deep indent
23
+ ok
24
+ HAML
25
+ ok
26
+ HTML
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
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)
13
+ !!! XML
14
+ HAML
15
+ <?xml version='1.0' encoding='utf-8' ?>
16
+ HTML
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,47 @@
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
+ HAML
15
+ to raise_error(Hamlit::SyntaxError, 'inconsistent indentation: 2 spaces used for indentation, but the rest of the document was indented using 4 spaces')
16
+ end
17
+
18
+ it 'raises syntax error for illegal indentation' do
19
+ expect { render_string(<<-HAML.unindent) }.
20
+ %a
21
+ %b
22
+ HAML
23
+ to raise_error(Hamlit::SyntaxError, 'inconsistent indentation: 2 spaces used for indentation, but the rest of the document was indented using 1 spaces')
24
+ end
25
+
26
+ it 'raises syntax error which has correct line number in backtrace' do
27
+ begin
28
+ render_string(<<-HAML.unindent)
29
+ %1
30
+ %2
31
+ %3
32
+ %4
33
+ %5
34
+ %6
35
+ %7
36
+ %8 this is invalid indent
37
+ %9
38
+ HAML
39
+ rescue Hamlit::SyntaxError => e
40
+ if e.respond_to?(:backtrace_locations)
41
+ line_number = e.backtrace_locations.first.to_s.match(/:(\d+):/)[1]
42
+ expect(line_number).to eq('8')
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,44 @@
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
@@ -0,0 +1,19 @@
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
+ end
19
+ end
@@ -0,0 +1,85 @@
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 'renders attributes' do
44
+ assert_render(<<-'HAML', <<-HTML)
45
+ %span{ data: { disable: true } } bar
46
+ HAML
47
+ <span data-disable>bar</span>
48
+ HTML
49
+ end
50
+
51
+ it 'accepts even illegal input for haml' do
52
+ assert_render(<<-'HAML', <<-HTML)
53
+ %span{ class: '}}}', id: '{}}' } }{
54
+ HAML
55
+ <span class='}}}' id='{}}'>}{</span>
56
+ HTML
57
+ end
58
+
59
+ it 'accepts method call including comma' do
60
+ assert_render(<<-'HAML', <<-HTML)
61
+ %body{ class: "#{"ab".gsub(/a/, 'b')}", data: { confirm: 'really?', disable: true }, id: 'c'.gsub(/c/, 'a') }
62
+ HAML
63
+ <body class='bb' data-confirm='really?' data-disable id='a'></body>
64
+ HTML
65
+ end
66
+
67
+ it 'renders runtime hash attribute' do
68
+ assert_render(<<-'HAML', <<-HTML)
69
+ - hash = { foo: 'bar' }
70
+ %span{ hash }
71
+ HAML
72
+ <span foo='bar'></span>
73
+ HTML
74
+ end
75
+
76
+ it 'renders runtime hash attribute escaping only value' do
77
+ assert_render(<<-'HAML', <<-HTML)
78
+ - hash = { "'<foo>'" => '<bar>' }
79
+ %span{ hash }
80
+ HAML
81
+ <span '<foo>'='&lt;bar&gt;'></span>
82
+ HTML
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,11 @@
1
+ describe Hamlit::Parser do
2
+ describe 'preservation' do
3
+ it 'renders whitespace preservation operator' do
4
+ assert_render(<<-'HAML', <<-HTML)
5
+ ~ "<code>hello\nworld</code>"
6
+ HAML
7
+ <code>hello&#x000A;world</code>
8
+ HTML
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,87 @@
1
+ describe Hamlit::Engine do
2
+ describe 'script' do
3
+ it 'renders one-line script' do
4
+ assert_render(<<-HAML, <<-HTML)
5
+ = 1 + 2
6
+ %span= 3 * 4
7
+ HAML
8
+ 3
9
+ <span>12</span>
10
+ HTML
11
+ end
12
+
13
+ it 'renders multi-lines script' do
14
+ assert_render(<<-HAML, <<-HTML)
15
+ %span
16
+ = 1 + 2
17
+ 4 / 2
18
+ %a= 3 - 4
19
+ HAML
20
+ <span>
21
+ 3
22
+ 4 / 2
23
+ <a>-1</a>
24
+ </span>
25
+ HTML
26
+ end
27
+
28
+ it 'renders block script' do
29
+ assert_render(<<-HAML, <<-HTML)
30
+ = 3.times do |i|
31
+ = i
32
+ 4
33
+ HAML
34
+ 0
35
+ 1
36
+ 2
37
+ 3
38
+ 4
39
+ HTML
40
+ end
41
+
42
+ it 'renders tag internal block script' do
43
+ assert_render(<<-HAML, <<-HTML)
44
+ %span
45
+ = 1.times do |i|
46
+ = i
47
+ HAML
48
+ <span>
49
+ 0
50
+ 1
51
+ </span>
52
+ HTML
53
+ end
54
+
55
+ it 'accepts a continuing script' do
56
+ assert_render(<<-HAML, <<-HTML)
57
+ - def foo(a, b); a + b; end
58
+ = foo(1,
59
+ 2)
60
+ HAML
61
+ 3
62
+ HTML
63
+ end
64
+
65
+ it 'renders !=' do
66
+ assert_render(<<-HAML, <<-HTML, escape_html: true)
67
+ != '<"&>'
68
+ != '<"&>'.tap do |str|
69
+ -# no operation
70
+ HAML
71
+ <"&>
72
+ <"&>
73
+ HTML
74
+ end
75
+
76
+ it 'renders &=' do
77
+ assert_render(<<-HAML, <<-HTML, escape_html: false)
78
+ &= '<"&>'
79
+ &= '<"&>'.tap do |str|
80
+ -# no operation
81
+ HAML
82
+ &lt;&quot;&amp;&gt;
83
+ &lt;&quot;&amp;&gt;
84
+ HTML
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,135 @@
1
+ describe Hamlit::Engine do
2
+ describe 'silent script' do
3
+ it 'renders silent script' do
4
+ assert_render(<<-HAML, <<-HTML)
5
+ - foo = 3
6
+ - bar = 2
7
+ = foo + bar
8
+ HAML
9
+ 5
10
+ HTML
11
+ end
12
+
13
+ it 'renders nested block' do
14
+ assert_render(<<-HAML, <<-HTML)
15
+ - 2.times do |i|
16
+ = i
17
+ 2
18
+ - 3.upto(4).each do |i|
19
+ = i
20
+ HAML
21
+ 0
22
+ 1
23
+ 2
24
+ 3
25
+ 4
26
+ HTML
27
+ end
28
+
29
+ it 'renders if' do
30
+ assert_render(<<-HAML, <<-HTML)
31
+ - if true
32
+ ok
33
+ HAML
34
+ ok
35
+ HTML
36
+ end
37
+
38
+ it 'renders if-else' do
39
+ assert_render(<<-HAML, <<-HTML)
40
+ - if true
41
+ ok
42
+ - else
43
+ ng
44
+
45
+ - if false
46
+ ng
47
+
48
+ - else
49
+ ok
50
+ HAML
51
+ ok
52
+ ok
53
+ HTML
54
+ end
55
+
56
+ it 'renders nested if-else' do
57
+ assert_render(<<-'HAML', <<-HTML)
58
+ %span
59
+ - if false
60
+ ng
61
+ - else
62
+ ok
63
+ HAML
64
+ <span>
65
+ ok
66
+ </span>
67
+ HTML
68
+ end
69
+
70
+ it 'accept if inside if-else' do
71
+ assert_render(<<-'HAML', <<-HTML)
72
+ - if false
73
+ - if true
74
+ ng
75
+ - else
76
+ ok
77
+ HAML
78
+ ok
79
+ HTML
80
+ end
81
+
82
+ it 'renders if-elsif' do
83
+ assert_render(<<-HAML, <<-HTML)
84
+ - if false
85
+ - elsif true
86
+ ok
87
+
88
+ - if false
89
+ - elsif false
90
+ - else
91
+ ok
92
+ HAML
93
+ ok
94
+ ok
95
+ HTML
96
+ end
97
+
98
+ it 'renders case-when' do
99
+ assert_render(<<-'HAML', <<-HTML)
100
+ - case 'foo'
101
+ - when /\Ao/
102
+ ng
103
+ - when /\Af/
104
+ ok
105
+ - else
106
+ ng
107
+ HAML
108
+ ok
109
+ HTML
110
+ end
111
+
112
+ it 'joins a next line if a current line ends with ","' do
113
+ assert_render("- foo = [', \n ']\n= foo", <<-HTML)
114
+ [", "]
115
+ HTML
116
+ end
117
+
118
+ it 'accepts illegal indent in continuing code' do
119
+ assert_render(<<-HAML, <<-HTML)
120
+ %span
121
+ %div
122
+ - def foo(a, b); a + b; end
123
+ - num = foo(1,
124
+ 2)
125
+ = num
126
+ HAML
127
+ <span>
128
+ <div>
129
+ 3
130
+ </div>
131
+ </span>
132
+ HTML
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,210 @@
1
+ describe Hamlit::Engine do
2
+ describe 'tag' do
3
+ it 'renders one-line tag' do
4
+ assert_render(<<-HAML, <<-HTML)
5
+ %span hello
6
+ HAML
7
+ <span>hello</span>
8
+ HTML
9
+ end
10
+
11
+ it 'renders multi-line tag' do
12
+ assert_render(<<-HAML, <<-HTML)
13
+ %span
14
+ hello
15
+ HAML
16
+ <span>
17
+ hello
18
+ </span>
19
+ HTML
20
+ end
21
+
22
+ it 'renders a nested tag' do
23
+ assert_render(<<-HAML, <<-HTML)
24
+ %span
25
+ %b
26
+ hello
27
+ %i
28
+ %small world
29
+ HAML
30
+ <span>
31
+ <b>
32
+ hello
33
+ </b>
34
+ <i>
35
+ <small>world</small>
36
+ </i>
37
+ </span>
38
+ HTML
39
+ end
40
+
41
+ it 'renders multi-line texts' do
42
+ assert_render(<<-HAML, <<-HTML)
43
+ %span
44
+ %b
45
+ hello
46
+ world
47
+ HAML
48
+ <span>
49
+ <b>
50
+ hello
51
+ world
52
+ </b>
53
+ </span>
54
+ HTML
55
+ end
56
+
57
+ it 'skips empty lines' do
58
+ assert_render(<<-HAML, <<-HTML)
59
+ %span
60
+
61
+ %b
62
+
63
+ hello
64
+
65
+ HAML
66
+ <span>
67
+ <b>
68
+ hello
69
+ </b>
70
+ </span>
71
+ HTML
72
+ end
73
+
74
+ it 'renders classes' do
75
+ assert_render(<<-HAML, <<-HTML)
76
+ %span.foo-1.bar_A hello
77
+ HAML
78
+ <span class='foo-1 bar_A'>hello</span>
79
+ HTML
80
+ end
81
+
82
+ it 'renders ids only last one' do
83
+ assert_render(<<-HAML, <<-HTML)
84
+ %span#Bar_0#bar-
85
+ hello
86
+ HAML
87
+ <span id='bar-'>
88
+ hello
89
+ </span>
90
+ HTML
91
+ end
92
+
93
+ it 'renders ids and classes' do
94
+ assert_render(<<-HAML, <<-HTML)
95
+ %span#a.b#c.d hello
96
+ HAML
97
+ <span class='b d' id='c'>hello</span>
98
+ HTML
99
+ end
100
+
101
+ it 'renders implicit div tag starting with id' do
102
+ assert_render(<<-HAML, <<-HTML)
103
+ #hello.world
104
+ HAML
105
+ <div class='world' id='hello'></div>
106
+ HTML
107
+ end
108
+
109
+ it 'renders implicit div tag starting with class' do
110
+ assert_render(<<-HAML, <<-HTML)
111
+ .world#hello
112
+ foo
113
+ HAML
114
+ <div class='world' id='hello'>
115
+ foo
116
+ </div>
117
+ HTML
118
+ end
119
+
120
+ it 'renders large-case tag' do
121
+ assert_render(<<-HAML, <<-HTML)
122
+ %SPAN
123
+ foo
124
+ HAML
125
+ <SPAN>
126
+ foo
127
+ </SPAN>
128
+ HTML
129
+ end
130
+
131
+ it 'renders h1 tag' do
132
+ assert_render(<<-HAML, <<-HTML)
133
+ %h1 foo
134
+ HAML
135
+ <h1>foo</h1>
136
+ HTML
137
+ end
138
+
139
+ it 'renders tag including hyphen or underscore' do
140
+ assert_render(<<-HAML, <<-HTML)
141
+ %-_ foo
142
+ HAML
143
+ <-_>foo</-_>
144
+ HTML
145
+ end
146
+
147
+ it 'does not render silent script just after a tag' do
148
+ assert_render(<<-HAML, <<-HTML)
149
+ %span- raise 'a'
150
+ HAML
151
+ <span->raise 'a'</span->
152
+ HTML
153
+ end
154
+
155
+ it 'renders a text just after attributes' do
156
+ assert_render(<<-HAML, <<-HTML)
157
+ %span{a: 2}a
158
+ HAML
159
+ <span a='2'>a</span>
160
+ HTML
161
+ end
162
+
163
+ it 'strips a text' do
164
+ assert_render(<<-HAML, <<-HTML)
165
+ %span foo
166
+ HAML
167
+ <span>foo</span>
168
+ HTML
169
+ end
170
+
171
+ it 'ignores spaces after tag' do
172
+ assert_render("%span \n a", <<-HTML)
173
+ <span>
174
+ a
175
+ </span>
176
+ HTML
177
+ end
178
+
179
+ it 'parses self-closing tag' do
180
+ assert_render(<<-HAML, <<-HTML, format: :xhtml)
181
+ %div/
182
+ %div
183
+ HAML
184
+ <div />
185
+ <div></div>
186
+ HTML
187
+ end
188
+
189
+ it 'removes outer whitespace by >' do
190
+ assert_render(<<-HAML, <<-HTML)
191
+ %span> a
192
+ %span b
193
+ %span c
194
+ %span>
195
+ d
196
+ %span
197
+ e
198
+ %span f
199
+ HAML
200
+ <span>a</span><span>b</span>
201
+ <span>c</span><span>
202
+ d
203
+ </span><span>
204
+ e
205
+ </span>
206
+ <span>f</span>
207
+ HTML
208
+ end
209
+ end
210
+ end