hamlit 1.7.2 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -3
- data/.gitmodules +3 -0
- data/.travis.yml +25 -37
- data/CHANGELOG.md +18 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +23 -2
- data/README.md +106 -48
- data/REFERENCE.md +222 -0
- data/Rakefile +77 -19
- data/benchmark/boolean_attribute.haml +6 -0
- data/benchmark/class_attribute.haml +5 -0
- data/benchmark/common_attribute.haml +3 -0
- data/benchmark/data_attribute.haml +4 -0
- data/benchmark/dynamic_attributes/boolean_attribute.haml +4 -0
- data/benchmark/dynamic_attributes/class_attribute.haml +4 -0
- data/benchmark/dynamic_attributes/common_attribute.haml +2 -0
- data/benchmark/dynamic_attributes/data_attribute.haml +2 -0
- data/benchmark/dynamic_attributes/id_attribute.haml +2 -0
- data/benchmark/etc/attribute_builder.haml +5 -0
- data/benchmark/etc/real_sample.haml +888 -0
- data/benchmark/etc/real_sample.rb +11 -0
- data/benchmark/etc/static_analyzer.haml +1 -0
- data/benchmark/etc/tags.haml +3 -0
- data/benchmark/ext/build_data.rb +15 -0
- data/benchmark/ext/build_id.rb +13 -0
- data/benchmark/id_attribute.haml +3 -0
- data/benchmark/plain.haml +4 -0
- data/benchmark/script.haml +4 -0
- data/benchmark/slim/LICENSE +21 -0
- data/{benchmarks → benchmark/slim}/context.rb +2 -4
- data/benchmark/slim/run-benchmarks.rb +94 -0
- data/{benchmarks → benchmark/slim}/view.erb +3 -3
- data/{benchmarks → benchmark/slim}/view.haml +0 -0
- data/{benchmarks/view.escaped.slim → benchmark/slim/view.slim} +1 -1
- data/benchmark/string_interpolation.haml +2 -0
- data/benchmark/utils/benchmark_ips_extension.rb +43 -0
- data/bin/bench +85 -0
- data/bin/clone +14 -0
- data/bin/console +11 -0
- data/bin/lineprof +48 -0
- data/bin/ruby +3 -0
- data/bin/setup +7 -0
- data/bin/stackprof +27 -0
- data/{test → bin/test} +6 -10
- data/{bin → exe}/hamlit +0 -0
- data/ext/hamlit/extconf.rb +14 -0
- data/ext/hamlit/hamlit.c +512 -0
- data/ext/hamlit/houdini/.gitignore +3 -0
- data/ext/hamlit/houdini/COPYING +7 -0
- data/ext/hamlit/houdini/Makefile +79 -0
- data/ext/hamlit/houdini/README.md +59 -0
- data/ext/hamlit/houdini/buffer.c +249 -0
- data/ext/hamlit/houdini/buffer.h +113 -0
- data/ext/hamlit/houdini/houdini.h +46 -0
- data/ext/hamlit/houdini/houdini_href_e.c +115 -0
- data/ext/hamlit/houdini/houdini_html_e.c +90 -0
- data/ext/hamlit/houdini/houdini_html_u.c +122 -0
- data/ext/hamlit/houdini/houdini_js_e.c +90 -0
- data/ext/hamlit/houdini/houdini_js_u.c +60 -0
- data/ext/hamlit/houdini/houdini_uri_e.c +107 -0
- data/ext/hamlit/houdini/houdini_uri_u.c +68 -0
- data/ext/hamlit/houdini/houdini_xml_e.c +136 -0
- data/ext/hamlit/houdini/html_unescape.gperf +258 -0
- data/ext/hamlit/houdini/html_unescape.h +754 -0
- data/ext/hamlit/houdini/tools/build_table.py +13 -0
- data/ext/hamlit/houdini/tools/build_tables.c +51 -0
- data/ext/hamlit/houdini/tools/wikipedia_table.txt +2025 -0
- data/hamlit.gemspec +30 -31
- data/lib/hamlit.rb +3 -1
- data/lib/hamlit/attribute_builder.rb +12 -0
- data/lib/hamlit/cli.rb +44 -43
- data/lib/hamlit/compiler.rb +92 -16
- data/lib/hamlit/compiler/attribute_compiler.rb +148 -0
- data/lib/hamlit/compiler/children_compiler.rb +111 -0
- data/lib/hamlit/compiler/comment_compiler.rb +36 -0
- data/lib/hamlit/compiler/doctype_compiler.rb +45 -0
- data/lib/hamlit/compiler/script_compiler.rb +97 -0
- data/lib/hamlit/compiler/silent_script_compiler.rb +24 -0
- data/lib/hamlit/compiler/tag_compiler.rb +69 -0
- data/lib/hamlit/engine.rb +12 -7
- data/lib/hamlit/error.rb +14 -0
- data/lib/hamlit/escapable.rb +12 -0
- data/lib/hamlit/filters.rb +65 -0
- data/lib/hamlit/filters/base.rb +4 -62
- data/lib/hamlit/filters/coffee.rb +9 -7
- data/lib/hamlit/filters/css.rb +25 -8
- data/lib/hamlit/filters/erb.rb +4 -6
- data/lib/hamlit/filters/escaped.rb +11 -9
- data/lib/hamlit/filters/javascript.rb +25 -8
- data/lib/hamlit/filters/less.rb +9 -7
- data/lib/hamlit/filters/markdown.rb +5 -6
- data/lib/hamlit/filters/plain.rb +11 -15
- data/lib/hamlit/filters/preserve.rb +15 -5
- data/lib/hamlit/filters/ruby.rb +3 -5
- data/lib/hamlit/filters/sass.rb +9 -7
- data/lib/hamlit/filters/scss.rb +9 -7
- data/lib/hamlit/filters/text_base.rb +24 -0
- data/lib/hamlit/filters/tilt_base.rb +47 -0
- data/lib/hamlit/hash_parser.rb +107 -0
- data/lib/hamlit/html.rb +9 -6
- data/lib/hamlit/identity.rb +12 -0
- data/lib/hamlit/object_ref.rb +29 -0
- data/lib/hamlit/parser.rb +25 -142
- data/lib/hamlit/parser/MIT-LICENSE +20 -0
- data/lib/hamlit/parser/README.md +28 -0
- data/lib/hamlit/parser/haml_buffer.rb +348 -0
- data/lib/hamlit/parser/haml_compiler.rb +553 -0
- data/lib/hamlit/parser/haml_error.rb +61 -0
- data/lib/hamlit/parser/haml_helpers.rb +727 -0
- data/lib/hamlit/parser/haml_options.rb +286 -0
- data/lib/hamlit/parser/haml_parser.rb +801 -0
- data/lib/hamlit/parser/haml_util.rb +283 -0
- data/lib/hamlit/parser/haml_xss_mods.rb +109 -0
- data/lib/hamlit/{helpers.rb → rails_helpers.rb} +2 -7
- data/lib/hamlit/rails_template.rb +30 -0
- data/lib/hamlit/railtie.rb +1 -12
- data/lib/hamlit/ruby_expression.rb +31 -0
- data/lib/hamlit/static_analyzer.rb +49 -0
- data/lib/hamlit/string_interpolation.rb +69 -0
- data/lib/hamlit/template.rb +8 -0
- data/lib/hamlit/utils.rb +9 -0
- data/lib/hamlit/version.rb +1 -1
- metadata +116 -324
- data/.rspec +0 -2
- data/benchmarks/benchmark.rb +0 -110
- data/benchmarks/view.slim +0 -17
- data/doc/README.md +0 -19
- data/doc/engine/indent.md +0 -48
- data/doc/engine/new_attribute.md +0 -77
- data/doc/engine/old_attributes.md +0 -198
- data/doc/engine/silent_script.md +0 -97
- data/doc/engine/tag.md +0 -48
- data/doc/engine/text.md +0 -64
- data/doc/faml/README.md +0 -16
- data/doc/faml/engine/indent.md +0 -48
- data/doc/faml/engine/old_attributes.md +0 -111
- data/doc/faml/engine/silent_script.md +0 -97
- data/doc/faml/engine/text.md +0 -59
- data/doc/faml/filters/erb.md +0 -24
- data/doc/faml/filters/javascript.md +0 -27
- data/doc/faml/filters/less.md +0 -57
- data/doc/faml/filters/plain.md +0 -25
- data/doc/filters/erb.md +0 -31
- data/doc/filters/javascript.md +0 -83
- data/doc/filters/less.md +0 -57
- data/doc/filters/markdown.md +0 -31
- data/doc/filters/plain.md +0 -25
- data/doc/haml/README.md +0 -15
- data/doc/haml/engine/new_attribute.md +0 -77
- data/doc/haml/engine/old_attributes.md +0 -142
- data/doc/haml/engine/tag.md +0 -48
- data/doc/haml/engine/text.md +0 -29
- data/doc/haml/filters/erb.md +0 -26
- data/doc/haml/filters/javascript.md +0 -76
- data/doc/haml/filters/markdown.md +0 -31
- data/lib/hamlit/attribute.rb +0 -78
- data/lib/hamlit/compilers/attributes.rb +0 -108
- data/lib/hamlit/compilers/comment.rb +0 -13
- data/lib/hamlit/compilers/doctype.rb +0 -39
- data/lib/hamlit/compilers/filter.rb +0 -53
- data/lib/hamlit/compilers/new_attribute.rb +0 -115
- data/lib/hamlit/compilers/old_attribute.rb +0 -241
- data/lib/hamlit/compilers/runtime_attribute.rb +0 -58
- data/lib/hamlit/compilers/script.rb +0 -31
- data/lib/hamlit/compilers/strip.rb +0 -19
- data/lib/hamlit/compilers/text.rb +0 -111
- data/lib/hamlit/concerns/attribute_builder.rb +0 -22
- data/lib/hamlit/concerns/balanceable.rb +0 -68
- data/lib/hamlit/concerns/deprecation.rb +0 -20
- data/lib/hamlit/concerns/error.rb +0 -31
- data/lib/hamlit/concerns/escapable.rb +0 -17
- data/lib/hamlit/concerns/included.rb +0 -28
- data/lib/hamlit/concerns/indentable.rb +0 -117
- data/lib/hamlit/concerns/lexable.rb +0 -32
- data/lib/hamlit/concerns/line_reader.rb +0 -62
- data/lib/hamlit/concerns/registerable.rb +0 -24
- data/lib/hamlit/concerns/string_interpolation.rb +0 -48
- data/lib/hamlit/concerns/whitespace.rb +0 -91
- data/lib/hamlit/filters/tilt.rb +0 -41
- data/lib/hamlit/parsers/attribute.rb +0 -71
- data/lib/hamlit/parsers/comment.rb +0 -30
- data/lib/hamlit/parsers/doctype.rb +0 -18
- data/lib/hamlit/parsers/filter.rb +0 -18
- data/lib/hamlit/parsers/multiline.rb +0 -58
- data/lib/hamlit/parsers/script.rb +0 -126
- data/lib/hamlit/parsers/tag.rb +0 -83
- data/lib/hamlit/parsers/text.rb +0 -28
- data/lib/hamlit/temple.rb +0 -9
- data/release +0 -6
- data/spec/Rakefile +0 -72
- data/spec/hamlit/engine/comment_spec.rb +0 -56
- data/spec/hamlit/engine/doctype_spec.rb +0 -19
- data/spec/hamlit/engine/error_spec.rb +0 -135
- data/spec/hamlit/engine/indent_spec.rb +0 -42
- data/spec/hamlit/engine/multiline_spec.rb +0 -44
- data/spec/hamlit/engine/new_attribute_spec.rb +0 -110
- data/spec/hamlit/engine/old_attributes_spec.rb +0 -404
- data/spec/hamlit/engine/script_spec.rb +0 -116
- data/spec/hamlit/engine/silent_script_spec.rb +0 -213
- data/spec/hamlit/engine/tag_spec.rb +0 -295
- data/spec/hamlit/engine/text_spec.rb +0 -239
- data/spec/hamlit/engine_spec.rb +0 -58
- data/spec/hamlit/filters/coffee_spec.rb +0 -60
- data/spec/hamlit/filters/css_spec.rb +0 -33
- data/spec/hamlit/filters/erb_spec.rb +0 -16
- data/spec/hamlit/filters/javascript_spec.rb +0 -82
- data/spec/hamlit/filters/less_spec.rb +0 -37
- data/spec/hamlit/filters/markdown_spec.rb +0 -30
- data/spec/hamlit/filters/plain_spec.rb +0 -15
- data/spec/hamlit/filters/ruby_spec.rb +0 -24
- data/spec/hamlit/filters/sass_spec.rb +0 -33
- data/spec/hamlit/filters/scss_spec.rb +0 -37
- data/spec/hamlit/haml_spec.rb +0 -910
- data/spec/rails/.gitignore +0 -18
- data/spec/rails/.rspec +0 -2
- data/spec/rails/Gemfile +0 -19
- data/spec/rails/README.rdoc +0 -28
- data/spec/rails/Rakefile +0 -6
- data/spec/rails/app/assets/images/.keep +0 -0
- data/spec/rails/app/assets/javascripts/application.js +0 -15
- data/spec/rails/app/assets/stylesheets/application.css +0 -15
- data/spec/rails/app/controllers/application_controller.rb +0 -8
- data/spec/rails/app/controllers/concerns/.keep +0 -0
- data/spec/rails/app/controllers/users_controller.rb +0 -23
- data/spec/rails/app/helpers/application_helper.rb +0 -2
- data/spec/rails/app/mailers/.keep +0 -0
- data/spec/rails/app/models/.keep +0 -0
- data/spec/rails/app/models/concerns/.keep +0 -0
- data/spec/rails/app/views/application/index.html.haml +0 -18
- data/spec/rails/app/views/layouts/application.html.haml +0 -12
- data/spec/rails/app/views/users/capture.html.haml +0 -5
- data/spec/rails/app/views/users/capture_haml.html.haml +0 -5
- data/spec/rails/app/views/users/form.html.haml +0 -2
- data/spec/rails/app/views/users/helpers.html.haml +0 -10
- data/spec/rails/app/views/users/index.html.haml +0 -9
- data/spec/rails/app/views/users/inline.html.haml +0 -6
- data/spec/rails/app/views/users/old_attributes.html.haml +0 -5
- data/spec/rails/app/views/users/safe_buffer.html.haml +0 -4
- data/spec/rails/app/views/users/whitespace.html.haml +0 -4
- data/spec/rails/bin/bundle +0 -3
- data/spec/rails/bin/rails +0 -8
- data/spec/rails/bin/rake +0 -8
- data/spec/rails/bin/setup +0 -29
- data/spec/rails/bin/spring +0 -15
- data/spec/rails/config.ru +0 -4
- data/spec/rails/config/application.rb +0 -34
- data/spec/rails/config/boot.rb +0 -3
- data/spec/rails/config/database.yml +0 -25
- data/spec/rails/config/environment.rb +0 -5
- data/spec/rails/config/environments/development.rb +0 -41
- data/spec/rails/config/environments/production.rb +0 -79
- data/spec/rails/config/environments/test.rb +0 -42
- data/spec/rails/config/initializers/assets.rb +0 -11
- data/spec/rails/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails/config/initializers/cookies_serializer.rb +0 -3
- data/spec/rails/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/rails/config/initializers/inflections.rb +0 -16
- data/spec/rails/config/initializers/mime_types.rb +0 -4
- data/spec/rails/config/initializers/session_store.rb +0 -3
- data/spec/rails/config/initializers/wrap_parameters.rb +0 -14
- data/spec/rails/config/locales/en.yml +0 -24
- data/spec/rails/config/routes.rb +0 -16
- data/spec/rails/config/secrets.yml +0 -22
- data/spec/rails/db/schema.rb +0 -16
- data/spec/rails/db/seeds.rb +0 -7
- data/spec/rails/lib/assets/.keep +0 -0
- data/spec/rails/lib/tasks/.keep +0 -0
- data/spec/rails/log/.keep +0 -0
- data/spec/rails/public/404.html +0 -67
- data/spec/rails/public/422.html +0 -67
- data/spec/rails/public/500.html +0 -66
- data/spec/rails/public/favicon.ico +0 -0
- data/spec/rails/public/robots.txt +0 -5
- data/spec/rails/spec/hamlit_spec.rb +0 -123
- data/spec/rails/spec/rails_helper.rb +0 -56
- data/spec/rails/spec/spec_helper.rb +0 -91
- data/spec/rails/vendor/assets/javascripts/.keep +0 -0
- data/spec/rails/vendor/assets/stylesheets/.keep +0 -0
- data/spec/spec_helper.rb +0 -36
- data/spec/spec_helper/document_generator.rb +0 -93
- data/spec/spec_helper/render_helper.rb +0 -120
- data/spec/spec_helper/test_case.rb +0 -55
@@ -1,116 +0,0 @@
|
|
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 one-line script with comment' do
|
14
|
-
assert_render(<<-HAML, <<-HTML)
|
15
|
-
= # comment_only
|
16
|
-
= '#' + "#" # = 3 #
|
17
|
-
= ['#',
|
18
|
-
"#"] # comment
|
19
|
-
HAML
|
20
|
-
|
21
|
-
##
|
22
|
-
["#", "#"]
|
23
|
-
HTML
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'renders multi-lines script' do
|
27
|
-
assert_render(<<-HAML, <<-HTML)
|
28
|
-
%span
|
29
|
-
= 1 + 2
|
30
|
-
4 / 2
|
31
|
-
%a= 3 - 4
|
32
|
-
HAML
|
33
|
-
<span>
|
34
|
-
3
|
35
|
-
4 / 2
|
36
|
-
<a>-1</a>
|
37
|
-
</span>
|
38
|
-
HTML
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'renders block script' do
|
42
|
-
assert_render(<<-HAML, <<-HTML)
|
43
|
-
= 3.times do |i|
|
44
|
-
= i
|
45
|
-
4
|
46
|
-
HAML
|
47
|
-
0
|
48
|
-
1
|
49
|
-
2
|
50
|
-
34
|
51
|
-
HTML
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'renders tag internal block script' do
|
55
|
-
assert_render(<<-HAML, <<-HTML)
|
56
|
-
%span
|
57
|
-
= 1.times do |i|
|
58
|
-
= i
|
59
|
-
HAML
|
60
|
-
<span>
|
61
|
-
0
|
62
|
-
1</span>
|
63
|
-
HTML
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'renders block and a variable with spaces' do
|
67
|
-
assert_render(<<-HAML, <<-HTML)
|
68
|
-
- 1.times do | i |
|
69
|
-
= i
|
70
|
-
HAML
|
71
|
-
0
|
72
|
-
HTML
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'accepts a continuing script' do
|
76
|
-
assert_render(<<-HAML, <<-HTML)
|
77
|
-
- def foo(a, b); a + b; end
|
78
|
-
= foo(1,
|
79
|
-
2)
|
80
|
-
HAML
|
81
|
-
3
|
82
|
-
HTML
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'renders !=' do
|
86
|
-
assert_render(<<-HAML, <<-HTML.rstrip, escape_html: true)
|
87
|
-
!= '<"&>'
|
88
|
-
!= '<"&>'.tap do |str|
|
89
|
-
-# no operation
|
90
|
-
HAML
|
91
|
-
<"&>
|
92
|
-
<"&>
|
93
|
-
HTML
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'renders &=' do
|
97
|
-
assert_render(<<-HAML, <<-HTML.rstrip, escape_html: false)
|
98
|
-
&= '<"&>'
|
99
|
-
&= '<"&>'.tap do |str|
|
100
|
-
-# no operation
|
101
|
-
HAML
|
102
|
-
<"&>
|
103
|
-
<"&>
|
104
|
-
HTML
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'regards ~ operator as =' do
|
108
|
-
assert_render(<<-'HAML', <<-HTML)
|
109
|
-
~ "<code>hello\nworld</code>"
|
110
|
-
HAML
|
111
|
-
<code>hello
|
112
|
-
world</code>
|
113
|
-
HTML
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
@@ -1,213 +0,0 @@
|
|
1
|
-
describe Hamlit::Engine do
|
2
|
-
describe 'silent script' do
|
3
|
-
it 'renders nothing' do
|
4
|
-
assert_render(<<-HAML, <<-HTML)
|
5
|
-
- nil
|
6
|
-
- 3
|
7
|
-
- 'foo'
|
8
|
-
HAML
|
9
|
-
HTML
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'renders silent script' do
|
13
|
-
assert_render(<<-HAML, <<-HTML)
|
14
|
-
- foo = 3
|
15
|
-
- bar = 2
|
16
|
-
= foo + bar
|
17
|
-
HAML
|
18
|
-
5
|
19
|
-
HTML
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'renders nested block' do
|
23
|
-
assert_render(<<-HAML, <<-HTML)
|
24
|
-
- 2.times do |i|
|
25
|
-
= i
|
26
|
-
2
|
27
|
-
- 3.upto(4).each do |i|
|
28
|
-
= i
|
29
|
-
HAML
|
30
|
-
0
|
31
|
-
1
|
32
|
-
2
|
33
|
-
3
|
34
|
-
4
|
35
|
-
HTML
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'renders if' do
|
39
|
-
assert_render(<<-HAML, <<-HTML)
|
40
|
-
- if true
|
41
|
-
ok
|
42
|
-
HAML
|
43
|
-
ok
|
44
|
-
HTML
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'renders if-else' do
|
48
|
-
assert_render(<<-HAML, <<-HTML)
|
49
|
-
- if true
|
50
|
-
ok
|
51
|
-
- else
|
52
|
-
ng
|
53
|
-
|
54
|
-
- if false
|
55
|
-
ng
|
56
|
-
|
57
|
-
- else
|
58
|
-
ok
|
59
|
-
HAML
|
60
|
-
ok
|
61
|
-
ok
|
62
|
-
HTML
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'renders nested if-else' do
|
66
|
-
assert_render(<<-'HAML', <<-HTML)
|
67
|
-
%span
|
68
|
-
- if false
|
69
|
-
ng
|
70
|
-
- else
|
71
|
-
ok
|
72
|
-
HAML
|
73
|
-
<span>
|
74
|
-
ok
|
75
|
-
</span>
|
76
|
-
HTML
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'renders empty elsif statement' do
|
80
|
-
assert_render(<<-'HAML', <<-HTML, compatible_only: :haml, error_with: :faml)
|
81
|
-
%span
|
82
|
-
- if false
|
83
|
-
- elsif false
|
84
|
-
HAML
|
85
|
-
<span>
|
86
|
-
</span>
|
87
|
-
HTML
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'renders empty else statement' do
|
91
|
-
assert_render(<<-'HAML', <<-HTML, compatible_only: :haml, error_with: :faml)
|
92
|
-
%span
|
93
|
-
- if false
|
94
|
-
ng
|
95
|
-
- else
|
96
|
-
HAML
|
97
|
-
<span>
|
98
|
-
</span>
|
99
|
-
HTML
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'renders empty when statement' do
|
103
|
-
assert_render(<<-'HAML', <<-HTML, compatible_only: :haml, error_with: :faml)
|
104
|
-
%span
|
105
|
-
- case
|
106
|
-
- when false
|
107
|
-
HAML
|
108
|
-
<span>
|
109
|
-
</span>
|
110
|
-
HTML
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'accept if inside if-else' do
|
114
|
-
assert_render(<<-'HAML', <<-HTML)
|
115
|
-
- if false
|
116
|
-
- if true
|
117
|
-
ng
|
118
|
-
- else
|
119
|
-
ok
|
120
|
-
HAML
|
121
|
-
ok
|
122
|
-
HTML
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'renders if-elsif' do
|
126
|
-
assert_render(<<-HAML, <<-HTML)
|
127
|
-
- if false
|
128
|
-
- elsif true
|
129
|
-
ok
|
130
|
-
|
131
|
-
- if false
|
132
|
-
- elsif false
|
133
|
-
- else
|
134
|
-
ok
|
135
|
-
HAML
|
136
|
-
ok
|
137
|
-
ok
|
138
|
-
HTML
|
139
|
-
end
|
140
|
-
|
141
|
-
it 'renders case-when' do
|
142
|
-
assert_render(<<-'HAML', <<-HTML)
|
143
|
-
- case 'foo'
|
144
|
-
- when /\Ao/
|
145
|
-
ng
|
146
|
-
- when /\Af/
|
147
|
-
ok
|
148
|
-
- else
|
149
|
-
ng
|
150
|
-
HAML
|
151
|
-
ok
|
152
|
-
HTML
|
153
|
-
end
|
154
|
-
|
155
|
-
it 'renders case-when with multiple candidates' do
|
156
|
-
assert_render(<<-'HAML', <<-HTML)
|
157
|
-
- case 'a'
|
158
|
-
- when 'a', 'b'
|
159
|
-
ok
|
160
|
-
HAML
|
161
|
-
ok
|
162
|
-
HTML
|
163
|
-
end
|
164
|
-
|
165
|
-
it 'renders begin-rescue' do
|
166
|
-
assert_render(<<-'HAML', <<-HTML)
|
167
|
-
- begin
|
168
|
-
- raise 'error'
|
169
|
-
- rescue
|
170
|
-
hello
|
171
|
-
- ensure
|
172
|
-
world
|
173
|
-
HAML
|
174
|
-
hello
|
175
|
-
world
|
176
|
-
HTML
|
177
|
-
end
|
178
|
-
|
179
|
-
it 'renders rescue with error' do
|
180
|
-
assert_render(<<-'HAML', <<-HTML)
|
181
|
-
- begin
|
182
|
-
- raise 'error'
|
183
|
-
- rescue RuntimeError => e
|
184
|
-
hello
|
185
|
-
HAML
|
186
|
-
hello
|
187
|
-
HTML
|
188
|
-
end
|
189
|
-
|
190
|
-
it 'joins a next line if a current line ends with ","' do
|
191
|
-
assert_render("- foo = [', \n ']\n= foo", <<-HTML, compatible_only: :haml)
|
192
|
-
[", "]
|
193
|
-
HTML
|
194
|
-
end
|
195
|
-
|
196
|
-
it 'accepts illegal indent in continuing code' do
|
197
|
-
assert_render(<<-HAML, <<-HTML)
|
198
|
-
%span
|
199
|
-
%div
|
200
|
-
- def foo(a, b); a + b; end
|
201
|
-
- num = foo(1,
|
202
|
-
2)
|
203
|
-
= num
|
204
|
-
HAML
|
205
|
-
<span>
|
206
|
-
<div>
|
207
|
-
3
|
208
|
-
</div>
|
209
|
-
</span>
|
210
|
-
HTML
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
@@ -1,295 +0,0 @@
|
|
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 'accepts multi-line =' do
|
12
|
-
assert_render(<<-HAML, <<-HTML)
|
13
|
-
%span= 'hello'.gsub('hell',
|
14
|
-
'')
|
15
|
-
HAML
|
16
|
-
<span>o</span>
|
17
|
-
HTML
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'renders multi-line tag' do
|
21
|
-
assert_render(<<-HAML, <<-HTML)
|
22
|
-
%span
|
23
|
-
hello
|
24
|
-
HAML
|
25
|
-
<span>
|
26
|
-
hello
|
27
|
-
</span>
|
28
|
-
HTML
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'renders a nested tag' do
|
32
|
-
assert_render(<<-HAML, <<-HTML)
|
33
|
-
%span
|
34
|
-
%b
|
35
|
-
hello
|
36
|
-
%i
|
37
|
-
%small world
|
38
|
-
HAML
|
39
|
-
<span>
|
40
|
-
<b>
|
41
|
-
hello
|
42
|
-
</b>
|
43
|
-
<i>
|
44
|
-
<small>world</small>
|
45
|
-
</i>
|
46
|
-
</span>
|
47
|
-
HTML
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'renders multi-line texts' do
|
51
|
-
assert_render(<<-HAML, <<-HTML)
|
52
|
-
%span
|
53
|
-
%b
|
54
|
-
hello
|
55
|
-
world
|
56
|
-
HAML
|
57
|
-
<span>
|
58
|
-
<b>
|
59
|
-
hello
|
60
|
-
world
|
61
|
-
</b>
|
62
|
-
</span>
|
63
|
-
HTML
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'skips empty lines' do
|
67
|
-
assert_render(<<-HAML, <<-HTML)
|
68
|
-
%span
|
69
|
-
|
70
|
-
%b
|
71
|
-
|
72
|
-
hello
|
73
|
-
|
74
|
-
HAML
|
75
|
-
<span>
|
76
|
-
<b>
|
77
|
-
hello
|
78
|
-
</b>
|
79
|
-
</span>
|
80
|
-
HTML
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'renders classes' do
|
84
|
-
assert_render(<<-HAML, <<-HTML)
|
85
|
-
%span.foo-1.bar_A hello
|
86
|
-
HAML
|
87
|
-
<span class='foo-1 bar_A'>hello</span>
|
88
|
-
HTML
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'renders ids only last one' do
|
92
|
-
assert_render(<<-HAML, <<-HTML)
|
93
|
-
%span#Bar_0#bar-
|
94
|
-
hello
|
95
|
-
HAML
|
96
|
-
<span id='bar-'>
|
97
|
-
hello
|
98
|
-
</span>
|
99
|
-
HTML
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'renders ids and classes' do
|
103
|
-
assert_render(<<-HAML, <<-HTML)
|
104
|
-
%span#a.b#c.d hello
|
105
|
-
HAML
|
106
|
-
<span class='b d' id='c'>hello</span>
|
107
|
-
HTML
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'renders implicit div tag starting with id' do
|
111
|
-
assert_render(<<-HAML, <<-HTML)
|
112
|
-
#hello.world
|
113
|
-
HAML
|
114
|
-
<div class='world' id='hello'></div>
|
115
|
-
HTML
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'renders implicit div tag starting with class' do
|
119
|
-
assert_render(<<-HAML, <<-HTML)
|
120
|
-
.world#hello
|
121
|
-
foo
|
122
|
-
HAML
|
123
|
-
<div class='world' id='hello'>
|
124
|
-
foo
|
125
|
-
</div>
|
126
|
-
HTML
|
127
|
-
end
|
128
|
-
|
129
|
-
it 'renders large-case tag' do
|
130
|
-
assert_render(<<-HAML, <<-HTML)
|
131
|
-
%SPAN
|
132
|
-
foo
|
133
|
-
HAML
|
134
|
-
<SPAN>
|
135
|
-
foo
|
136
|
-
</SPAN>
|
137
|
-
HTML
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'renders h1 tag' do
|
141
|
-
assert_render(<<-HAML, <<-HTML)
|
142
|
-
%h1 foo
|
143
|
-
HAML
|
144
|
-
<h1>foo</h1>
|
145
|
-
HTML
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'renders tag including hyphen or underscore' do
|
149
|
-
assert_render(<<-HAML, <<-HTML)
|
150
|
-
%-_ foo
|
151
|
-
HAML
|
152
|
-
<-_>foo</-_>
|
153
|
-
HTML
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'does not render silent script just after a tag' do
|
157
|
-
assert_render(<<-HAML, <<-HTML)
|
158
|
-
%span- raise 'a'
|
159
|
-
HAML
|
160
|
-
<span->raise 'a'</span->
|
161
|
-
HTML
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'renders a text just after attributes' do
|
165
|
-
assert_render(<<-HAML, <<-HTML)
|
166
|
-
%span{a: 2}a
|
167
|
-
HAML
|
168
|
-
<span a='2'>a</span>
|
169
|
-
HTML
|
170
|
-
end
|
171
|
-
|
172
|
-
it 'strips a text' do
|
173
|
-
assert_render(<<-HAML, <<-HTML)
|
174
|
-
%span foo
|
175
|
-
HAML
|
176
|
-
<span>foo</span>
|
177
|
-
HTML
|
178
|
-
end
|
179
|
-
|
180
|
-
it 'ignores spaces after tag' do
|
181
|
-
assert_render("%span \n a", <<-HTML)
|
182
|
-
<span>
|
183
|
-
a
|
184
|
-
</span>
|
185
|
-
HTML
|
186
|
-
end
|
187
|
-
|
188
|
-
it 'parses self-closing tag' do
|
189
|
-
assert_render(<<-HAML, <<-HTML, format: :xhtml)
|
190
|
-
%div/
|
191
|
-
%div
|
192
|
-
HAML
|
193
|
-
<div />
|
194
|
-
<div></div>
|
195
|
-
HTML
|
196
|
-
end
|
197
|
-
|
198
|
-
describe 'whitespace removal' do
|
199
|
-
it 'removes outer whitespace by >' do
|
200
|
-
assert_render(<<-HAML, <<-HTML)
|
201
|
-
%span> a
|
202
|
-
%span b
|
203
|
-
%span c
|
204
|
-
%span>
|
205
|
-
d
|
206
|
-
%span
|
207
|
-
e
|
208
|
-
%span f
|
209
|
-
HAML
|
210
|
-
<span>a</span><span>b</span>
|
211
|
-
<span>c</span><span>
|
212
|
-
d
|
213
|
-
</span><span>
|
214
|
-
e
|
215
|
-
</span>
|
216
|
-
<span>f</span>
|
217
|
-
HTML
|
218
|
-
end
|
219
|
-
|
220
|
-
it 'removes outer whitespace by > from inside of block' do
|
221
|
-
assert_render(<<-HAML, <<-HTML)
|
222
|
-
%span a
|
223
|
-
- if true
|
224
|
-
%span>
|
225
|
-
b
|
226
|
-
%span
|
227
|
-
c
|
228
|
-
HAML
|
229
|
-
<span>a</span><span>
|
230
|
-
b
|
231
|
-
</span><span>
|
232
|
-
c
|
233
|
-
</span>
|
234
|
-
HTML
|
235
|
-
end
|
236
|
-
|
237
|
-
it 'removes whitespaces inside block script' do
|
238
|
-
assert_render(<<-HAML, <<-HTML)
|
239
|
-
%span<
|
240
|
-
= 2.times do
|
241
|
-
= 'foo'
|
242
|
-
%span> bar
|
243
|
-
HAML
|
244
|
-
<span>foofoo2<span>bar</span></span>
|
245
|
-
HTML
|
246
|
-
end
|
247
|
-
|
248
|
-
it 'removes whitespace inside script inside silent script' do
|
249
|
-
assert_render(<<-HAML, <<-HTML)
|
250
|
-
.bar<
|
251
|
-
- 3.times do
|
252
|
-
= 'foo'
|
253
|
-
HAML
|
254
|
-
<div class='bar'>foofoofoo</div>
|
255
|
-
HTML
|
256
|
-
end
|
257
|
-
|
258
|
-
it 'removes whitespace inside script recursively' do
|
259
|
-
assert_render(<<-HAML, <<-HTML)
|
260
|
-
.foo<
|
261
|
-
- 1.times do
|
262
|
-
= 2.times do
|
263
|
-
- 2.times do
|
264
|
-
= 1.times do
|
265
|
-
= 'bar'
|
266
|
-
HAML
|
267
|
-
<div class='foo'>bar1bar1bar1bar12</div>
|
268
|
-
HTML
|
269
|
-
end
|
270
|
-
|
271
|
-
it 'does not remove whitespace after string interpolation' do
|
272
|
-
assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
|
273
|
-
%div<
|
274
|
-
#{'hello'}
|
275
|
-
world
|
276
|
-
HAML
|
277
|
-
<div>hello
|
278
|
-
world</div>
|
279
|
-
HTML
|
280
|
-
end
|
281
|
-
|
282
|
-
it 'removes whitespace inside script inside silent script' do
|
283
|
-
assert_render(<<-HAML, <<-HTML, compatible_only: :faml)
|
284
|
-
.bar<
|
285
|
-
- 1.times do
|
286
|
-
= '1'
|
287
|
-
= '2'
|
288
|
-
HAML
|
289
|
-
<div class='bar'>1
|
290
|
-
2</div>
|
291
|
-
HTML
|
292
|
-
end
|
293
|
-
end
|
294
|
-
end
|
295
|
-
end
|