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,239 +0,0 @@
|
|
1
|
-
describe Hamlit::Engine do
|
2
|
-
describe 'text' do
|
3
|
-
it 'renders string interpolation' do
|
4
|
-
assert_render(<<-'HAML', <<-HTML)
|
5
|
-
#{ "a#{3}a" }a" #{["1", 2]} b " !
|
6
|
-
a#{{ a: 3 }}
|
7
|
-
<ht#{2}ml>
|
8
|
-
HAML
|
9
|
-
a3aa" ["1", 2] b " !
|
10
|
-
a{:a=>3}
|
11
|
-
<ht2ml>
|
12
|
-
HTML
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'renders . or # which is not continued by tag name' do
|
16
|
-
assert_render(<<-HAML, <<-HTML, error_with: [:haml, :faml])
|
17
|
-
.
|
18
|
-
.*
|
19
|
-
..
|
20
|
-
#
|
21
|
-
#+
|
22
|
-
##
|
23
|
-
HAML
|
24
|
-
.
|
25
|
-
.*
|
26
|
-
..
|
27
|
-
#
|
28
|
-
#+
|
29
|
-
##
|
30
|
-
HTML
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'escapes all operators by backslash' do
|
34
|
-
assert_render(<<-'HAML', <<-HTML)
|
35
|
-
= 'a'
|
36
|
-
-
|
37
|
-
\= 'a'
|
38
|
-
\-
|
39
|
-
HAML
|
40
|
-
a
|
41
|
-
= 'a'
|
42
|
-
-
|
43
|
-
HTML
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'renders == operator' do
|
47
|
-
assert_render(<<-'HAML', <<-HTML)
|
48
|
-
===
|
49
|
-
== =
|
50
|
-
== <a>
|
51
|
-
== #{'<a>'}
|
52
|
-
HAML
|
53
|
-
=
|
54
|
-
=
|
55
|
-
<a>
|
56
|
-
<a>
|
57
|
-
HTML
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'renders !== operator' do
|
61
|
-
assert_render(<<-'HAML', <<-HTML)
|
62
|
-
== #{'<a>'}
|
63
|
-
!== #{'<a>'}
|
64
|
-
!===
|
65
|
-
!== =
|
66
|
-
HAML
|
67
|
-
<a>
|
68
|
-
<a>
|
69
|
-
=
|
70
|
-
=
|
71
|
-
HTML
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'leaves empty spaces after backslash' do
|
75
|
-
expect(render_string('\ a')).to eq(" a\n")
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'renders spaced - properly' do
|
79
|
-
assert_render(<<-HAML, <<-'HTML')
|
80
|
-
%div
|
81
|
-
foo
|
82
|
-
.test - bar
|
83
|
-
.test - baz
|
84
|
-
HAML
|
85
|
-
<div>
|
86
|
-
foo
|
87
|
-
<div class='test'>- bar</div>
|
88
|
-
<div class='test'>- baz</div>
|
89
|
-
</div>
|
90
|
-
HTML
|
91
|
-
end
|
92
|
-
|
93
|
-
describe 'inline operator' do
|
94
|
-
it 'renders ! operator' do
|
95
|
-
assert_render(<<-'HAML', <<-'HTML')
|
96
|
-
%span!#{'<nyaa>'}
|
97
|
-
%span! #{'<nyaa>'}
|
98
|
-
! #{'<nyaa>'}
|
99
|
-
HAML
|
100
|
-
<span><nyaa></span>
|
101
|
-
<span><nyaa></span>
|
102
|
-
<nyaa>
|
103
|
-
HTML
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'renders & operator' do
|
107
|
-
assert_render(<<-'HAML', <<-'HTML')
|
108
|
-
%span& #{'<nyaa>'}
|
109
|
-
%span&#{'<nyaa>'}
|
110
|
-
& #{'<nyaa>'}
|
111
|
-
HAML
|
112
|
-
<span><nyaa></span>
|
113
|
-
<span><nyaa></span>
|
114
|
-
<nyaa>
|
115
|
-
HTML
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'renders !, & operator right before a non-space character' do
|
119
|
-
assert_render(<<-'HAML', <<-'HTML', compatible_only: :haml)
|
120
|
-
|
121
|
-
\
|
122
|
-
!hello
|
123
|
-
\!hello
|
124
|
-
HAML
|
125
|
-
|
126
|
-
|
127
|
-
!hello
|
128
|
-
!hello
|
129
|
-
HTML
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'renders &, ! operator inside a tag' do
|
133
|
-
assert_render(<<-HAML, <<-HTML)
|
134
|
-
%span
|
135
|
-
%span
|
136
|
-
%span& nbsp;
|
137
|
-
%span !hello
|
138
|
-
%span!hello
|
139
|
-
%span! hello
|
140
|
-
HAML
|
141
|
-
<span> </span>
|
142
|
-
<span>nbsp;</span>
|
143
|
-
<span>nbsp;</span>
|
144
|
-
<span>!hello</span>
|
145
|
-
<span>hello</span>
|
146
|
-
<span>hello</span>
|
147
|
-
HTML
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'does not accept backslash operator' do
|
151
|
-
assert_render(<<-'HAML', <<-'HTML')
|
152
|
-
%span\ foo
|
153
|
-
HAML
|
154
|
-
<span>\ foo</span>
|
155
|
-
HTML
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'renders != operator' do
|
159
|
-
assert_render(<<-'HAML', <<-'HTML')
|
160
|
-
%span!= '<nyaa>'
|
161
|
-
HAML
|
162
|
-
<span><nyaa></span>
|
163
|
-
HTML
|
164
|
-
end
|
165
|
-
|
166
|
-
it 'renders !== operator' do
|
167
|
-
assert_render(<<-'HAML', <<-'HTML')
|
168
|
-
%span!==#{'<nyaa>'}
|
169
|
-
%span!== #{'<nyaa>'}
|
170
|
-
!==#{'<nyaa>'}
|
171
|
-
!== #{'<nyaa>'}
|
172
|
-
HAML
|
173
|
-
<span><nyaa></span>
|
174
|
-
<span><nyaa></span>
|
175
|
-
<nyaa>
|
176
|
-
<nyaa>
|
177
|
-
HTML
|
178
|
-
end
|
179
|
-
|
180
|
-
it 'renders &= operator' do
|
181
|
-
assert_render(<<-'HAML', <<-'HTML', escape_html: false)
|
182
|
-
%span&= '<nyaa>'
|
183
|
-
HAML
|
184
|
-
<span><nyaa></span>
|
185
|
-
HTML
|
186
|
-
end
|
187
|
-
|
188
|
-
it 'renders &== operator' do
|
189
|
-
assert_render(<<-'HAML', <<-'HTML')
|
190
|
-
&===
|
191
|
-
&== =
|
192
|
-
&== #{'<p>'}
|
193
|
-
HAML
|
194
|
-
=
|
195
|
-
=
|
196
|
-
<p>
|
197
|
-
HTML
|
198
|
-
end
|
199
|
-
|
200
|
-
it 'renders ~ operator' do
|
201
|
-
assert_render(<<-HAML, <<-HTML, escape_html: false)
|
202
|
-
%span~ 1
|
203
|
-
HAML
|
204
|
-
<span>1</span>
|
205
|
-
HTML
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
describe 'string interpolation' do
|
210
|
-
specify { assert_render('#{}', "\n") }
|
211
|
-
specify { assert_render('1#{}', "1\n") }
|
212
|
-
specify { assert_render('1#{2}', "12\n") }
|
213
|
-
specify { assert_render('}#{1}', "}1\n") }
|
214
|
-
specify { assert_render('#{1}2', "12\n") }
|
215
|
-
specify { assert_render('1#{ "2#{3}4" }5', "12345\n") }
|
216
|
-
specify { assert_render('#{1}2#{3}4#{5}6#{7}8#{9}', "123456789\n") }
|
217
|
-
specify { assert_render(%q{'"!@$%^&*|=#{1}1#{1}2}, %Q{'"!@$%^&*|=1112\n}) }
|
218
|
-
specify { assert_render('あ#{1}', "あ1\n") }
|
219
|
-
specify { assert_render('あ#{"い"}う', "あいう\n") }
|
220
|
-
specify { assert_render('a#{"<b>"}c', "a<b>c\n") }
|
221
|
-
end
|
222
|
-
|
223
|
-
describe 'illegal inputs' do
|
224
|
-
it 'rejects an invalid tag' do
|
225
|
-
expect { render_string(<<-HAML.unindent) }.
|
226
|
-
% a
|
227
|
-
HAML
|
228
|
-
to raise_error(Hamlit::SyntaxError, 'Invalid tag: "% a".')
|
229
|
-
end
|
230
|
-
|
231
|
-
it 'rejects an invalid tag' do
|
232
|
-
expect { render_string(<<-HAML.unindent) }.
|
233
|
-
%.foo
|
234
|
-
HAML
|
235
|
-
to raise_error(Hamlit::SyntaxError, 'Invalid tag: "%.foo".')
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
239
|
-
end
|
data/spec/hamlit/engine_spec.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
describe Hamlit::Engine do
|
2
|
-
describe '.new' do
|
3
|
-
subject { described_class.new(options) }
|
4
|
-
|
5
|
-
let(:buffer) { '_a' }
|
6
|
-
let(:options) do
|
7
|
-
{
|
8
|
-
buffer: buffer,
|
9
|
-
generator: Temple::Generators::ArrayBuffer,
|
10
|
-
}
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'accepts generator valid options' do
|
14
|
-
expect(subject.call('')).to eq(
|
15
|
-
"#{buffer} = []; ; #{buffer} = #{buffer}.join",
|
16
|
-
)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#call' do
|
21
|
-
let(:haml) do
|
22
|
-
<<-HAML.unindent
|
23
|
-
!!! html
|
24
|
-
|
25
|
-
%html
|
26
|
-
%head
|
27
|
-
%title Simple Haml
|
28
|
-
%body
|
29
|
-
%h1= 'header'
|
30
|
-
- unless false
|
31
|
-
%ul
|
32
|
-
- for i in [1, 2, 3]
|
33
|
-
- if i
|
34
|
-
%li
|
35
|
-
%strong= 'hello'
|
36
|
-
- else
|
37
|
-
%li
|
38
|
-
%a{:href => i}= i
|
39
|
-
- else
|
40
|
-
%p last line
|
41
|
-
HAML
|
42
|
-
end
|
43
|
-
let(:engine) { described_class.new }
|
44
|
-
|
45
|
-
it 'generates code with the same lineno as a template' do
|
46
|
-
lines = engine.call(haml).split("\n")
|
47
|
-
expect(lines[0]).to include('DOCTYPE')
|
48
|
-
expect(lines[6]).to include('header')
|
49
|
-
expect(lines[7]).to include('unless')
|
50
|
-
expect(lines[9]).to include('for i in')
|
51
|
-
expect(lines[10]).to include('if i')
|
52
|
-
expect(lines[12]).to include('hello')
|
53
|
-
expect(lines[13]).to include('else')
|
54
|
-
expect(lines[16]).to include('else')
|
55
|
-
expect(lines[17]).to include('last line')
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
describe Hamlit::Filters::Coffee do
|
2
|
-
describe '#compile' do
|
3
|
-
it 'renders coffee filter' do
|
4
|
-
assert_render(<<-HAML, <<-HTML)
|
5
|
-
:coffee
|
6
|
-
foo = ->
|
7
|
-
alert('hello')
|
8
|
-
HAML
|
9
|
-
<script>
|
10
|
-
(function() {
|
11
|
-
var foo;
|
12
|
-
|
13
|
-
foo = function() {
|
14
|
-
return alert('hello');
|
15
|
-
};
|
16
|
-
|
17
|
-
}).call(this);
|
18
|
-
</script>
|
19
|
-
HTML
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'renders coffeescript filter' do
|
23
|
-
assert_render(<<-HAML, <<-HTML)
|
24
|
-
:coffee
|
25
|
-
foo = ->
|
26
|
-
alert('hello')
|
27
|
-
HAML
|
28
|
-
<script>
|
29
|
-
(function() {
|
30
|
-
var foo;
|
31
|
-
|
32
|
-
foo = function() {
|
33
|
-
return alert('hello');
|
34
|
-
};
|
35
|
-
|
36
|
-
}).call(this);
|
37
|
-
</script>
|
38
|
-
HTML
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'renders coffeescript filter' do
|
42
|
-
assert_render(<<-'HAML', <<-HTML)
|
43
|
-
:coffee
|
44
|
-
foo = ->
|
45
|
-
alert("#{'<&>'}")
|
46
|
-
HAML
|
47
|
-
<script>
|
48
|
-
(function() {
|
49
|
-
var foo;
|
50
|
-
|
51
|
-
foo = function() {
|
52
|
-
return alert("<&>");
|
53
|
-
};
|
54
|
-
|
55
|
-
}).call(this);
|
56
|
-
</script>
|
57
|
-
HTML
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
describe Hamlit::Filters::Css do
|
2
|
-
describe '#compile' do
|
3
|
-
it 'renders css' do
|
4
|
-
assert_render(<<-HAML, <<-HTML)
|
5
|
-
:css
|
6
|
-
.foo {
|
7
|
-
width: 100px;
|
8
|
-
}
|
9
|
-
HAML
|
10
|
-
<style>
|
11
|
-
.foo {
|
12
|
-
width: 100px;
|
13
|
-
}
|
14
|
-
</style>
|
15
|
-
HTML
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'parses string interpolation' do
|
19
|
-
assert_render(<<-'HAML', <<-HTML)
|
20
|
-
:css
|
21
|
-
.foo {
|
22
|
-
content: "#{'<&>'}";
|
23
|
-
}
|
24
|
-
HAML
|
25
|
-
<style>
|
26
|
-
.foo {
|
27
|
-
content: "<&>";
|
28
|
-
}
|
29
|
-
</style>
|
30
|
-
HTML
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
describe Hamlit::Filters::Erb do
|
2
|
-
describe '#compile' do
|
3
|
-
it 'renders erb filter' do
|
4
|
-
assert_render(<<-HAML, <<-HTML, compatible_only: [], error_with: :faml)
|
5
|
-
:erb
|
6
|
-
<% if true %>
|
7
|
-
ok
|
8
|
-
<% else %>
|
9
|
-
ng
|
10
|
-
<% end %>
|
11
|
-
HAML
|
12
|
-
ok
|
13
|
-
HTML
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
describe Hamlit::Filters::Javascript do
|
2
|
-
describe '#compile' do
|
3
|
-
it 'just renders script tag for empty filter' do
|
4
|
-
assert_render(<<-HAML, <<-HTML, compatible_only: [])
|
5
|
-
before
|
6
|
-
:javascript
|
7
|
-
after
|
8
|
-
HAML
|
9
|
-
before
|
10
|
-
<script>
|
11
|
-
|
12
|
-
</script>
|
13
|
-
after
|
14
|
-
HTML
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'compiles javascript filter' do
|
18
|
-
assert_render(<<-HAML, <<-HTML)
|
19
|
-
before
|
20
|
-
:javascript
|
21
|
-
alert('hello');
|
22
|
-
after
|
23
|
-
HAML
|
24
|
-
before
|
25
|
-
<script>
|
26
|
-
alert('hello');
|
27
|
-
</script>
|
28
|
-
after
|
29
|
-
HTML
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'accepts illegal indentation' do
|
33
|
-
assert_render(<<-HAML, <<-HTML, compatible_only: :faml)
|
34
|
-
:javascript
|
35
|
-
if {
|
36
|
-
alert('hello');
|
37
|
-
}
|
38
|
-
:javascript
|
39
|
-
if {
|
40
|
-
alert('hello');
|
41
|
-
}
|
42
|
-
HAML
|
43
|
-
<script>
|
44
|
-
if {
|
45
|
-
alert('hello');
|
46
|
-
}
|
47
|
-
</script>
|
48
|
-
<script>
|
49
|
-
if {
|
50
|
-
alert('hello');
|
51
|
-
}
|
52
|
-
</script>
|
53
|
-
HTML
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'accepts illegal indentation' do
|
57
|
-
assert_render(<<-HAML, <<-HTML)
|
58
|
-
:javascript
|
59
|
-
if {
|
60
|
-
alert('a');
|
61
|
-
}
|
62
|
-
HAML
|
63
|
-
<script>
|
64
|
-
if {
|
65
|
-
alert('a');
|
66
|
-
}
|
67
|
-
</script>
|
68
|
-
HTML
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'parses string interpolation' do
|
72
|
-
assert_render(<<-'HAML', <<-HTML)
|
73
|
-
:javascript
|
74
|
-
var a = "#{'<&>'}";
|
75
|
-
HAML
|
76
|
-
<script>
|
77
|
-
var a = "<&>";
|
78
|
-
</script>
|
79
|
-
HTML
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|