fast_haml 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.gitmodules +3 -0
- data/.rspec +2 -0
- data/.travis.yml +25 -0
- data/Appraisals +26 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +96 -0
- data/Rakefile +11 -0
- data/benchmark/rendering.rb +29 -0
- data/bin/fast_haml +4 -0
- data/ext/attribute_builder/attribute_builder.c +259 -0
- data/ext/attribute_builder/extconf.rb +3 -0
- data/fast_haml.gemspec +35 -0
- data/gemfiles/rails_4.0.gemfile +9 -0
- data/gemfiles/rails_4.1.gemfile +9 -0
- data/gemfiles/rails_4.2.gemfile +9 -0
- data/gemfiles/rails_edge.gemfile +10 -0
- data/haml_spec_test.rb +22 -0
- data/lib/fast_haml/ast.rb +112 -0
- data/lib/fast_haml/cli.rb +38 -0
- data/lib/fast_haml/compiler.rb +325 -0
- data/lib/fast_haml/element_parser.rb +288 -0
- data/lib/fast_haml/engine.rb +32 -0
- data/lib/fast_haml/filter_compilers/base.rb +29 -0
- data/lib/fast_haml/filter_compilers/cdata.rb +15 -0
- data/lib/fast_haml/filter_compilers/css.rb +15 -0
- data/lib/fast_haml/filter_compilers/escaped.rb +22 -0
- data/lib/fast_haml/filter_compilers/javascript.rb +15 -0
- data/lib/fast_haml/filter_compilers/plain.rb +17 -0
- data/lib/fast_haml/filter_compilers/preserve.rb +30 -0
- data/lib/fast_haml/filter_compilers/ruby.rb +13 -0
- data/lib/fast_haml/filter_compilers.rb +37 -0
- data/lib/fast_haml/filter_parser.rb +54 -0
- data/lib/fast_haml/html.rb +44 -0
- data/lib/fast_haml/indent_tracker.rb +84 -0
- data/lib/fast_haml/line_parser.rb +66 -0
- data/lib/fast_haml/parser.rb +251 -0
- data/lib/fast_haml/parser_utils.rb +17 -0
- data/lib/fast_haml/rails_handler.rb +10 -0
- data/lib/fast_haml/railtie.rb +8 -0
- data/lib/fast_haml/ruby_multiline.rb +23 -0
- data/lib/fast_haml/static_hash_parser.rb +113 -0
- data/lib/fast_haml/syntax_error.rb +10 -0
- data/lib/fast_haml/text_compiler.rb +69 -0
- data/lib/fast_haml/tilt.rb +16 -0
- data/lib/fast_haml/version.rb +3 -0
- data/lib/fast_haml.rb +10 -0
- data/spec/rails/Rakefile +6 -0
- data/spec/rails/app/assets/images/.keep +0 -0
- data/spec/rails/app/assets/javascripts/application.js +13 -0
- data/spec/rails/app/assets/stylesheets/application.css +15 -0
- data/spec/rails/app/controllers/application_controller.rb +5 -0
- data/spec/rails/app/controllers/books_controller.rb +8 -0
- data/spec/rails/app/controllers/concerns/.keep +0 -0
- data/spec/rails/app/helpers/application_helper.rb +2 -0
- data/spec/rails/app/mailers/.keep +0 -0
- data/spec/rails/app/models/.keep +0 -0
- data/spec/rails/app/models/book.rb +9 -0
- data/spec/rails/app/models/concerns/.keep +0 -0
- data/spec/rails/app/views/books/hello.html.haml +2 -0
- data/spec/rails/app/views/books/with_capture.html.haml +4 -0
- data/spec/rails/app/views/books/with_variables.html.haml +4 -0
- data/spec/rails/app/views/layouts/application.html.haml +9 -0
- data/spec/rails/bin/bundle +3 -0
- data/spec/rails/bin/rails +4 -0
- data/spec/rails/bin/rake +4 -0
- data/spec/rails/bin/setup +29 -0
- data/spec/rails/config/application.rb +12 -0
- data/spec/rails/config/boot.rb +3 -0
- data/spec/rails/config/database.yml +25 -0
- data/spec/rails/config/environment.rb +5 -0
- data/spec/rails/config/environments/development.rb +41 -0
- data/spec/rails/config/environments/production.rb +79 -0
- data/spec/rails/config/environments/test.rb +42 -0
- data/spec/rails/config/initializers/assets.rb +11 -0
- data/spec/rails/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails/config/initializers/cookies_serializer.rb +3 -0
- data/spec/rails/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/rails/config/initializers/inflections.rb +16 -0
- data/spec/rails/config/initializers/mime_types.rb +4 -0
- data/spec/rails/config/initializers/secret_key_base.rb +6 -0
- data/spec/rails/config/initializers/session_store.rb +3 -0
- data/spec/rails/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails/config/locales/en.yml +23 -0
- data/spec/rails/config/routes.rb +7 -0
- data/spec/rails/config/secrets.yml +22 -0
- data/spec/rails/config.ru +4 -0
- data/spec/rails/db/seeds.rb +7 -0
- 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 +67 -0
- data/spec/rails/public/422.html +67 -0
- data/spec/rails/public/500.html +66 -0
- data/spec/rails/public/favicon.ico +0 -0
- data/spec/rails/public/robots.txt +5 -0
- data/spec/rails/spec/requests/fast_haml_spec.rb +41 -0
- data/spec/rails/vendor/assets/javascripts/.keep +0 -0
- data/spec/rails/vendor/assets/stylesheets/.keep +0 -0
- data/spec/rails_helper.rb +4 -0
- data/spec/render/attribute_spec.rb +209 -0
- data/spec/render/comment_spec.rb +61 -0
- data/spec/render/doctype_spec.rb +62 -0
- data/spec/render/element_spec.rb +165 -0
- data/spec/render/filters/cdata_spec.rb +12 -0
- data/spec/render/filters/css_spec.rb +45 -0
- data/spec/render/filters/escaped_spec.rb +14 -0
- data/spec/render/filters/javascript_spec.rb +44 -0
- data/spec/render/filters/plain_spec.rb +24 -0
- data/spec/render/filters/preserve_spec.rb +25 -0
- data/spec/render/filters/ruby_spec.rb +13 -0
- data/spec/render/filters_spec.rb +11 -0
- data/spec/render/haml_comment_spec.rb +24 -0
- data/spec/render/multiline_spec.rb +39 -0
- data/spec/render/plain_spec.rb +20 -0
- data/spec/render/preserve_spec.rb +8 -0
- data/spec/render/sanitize_spec.rb +36 -0
- data/spec/render/script_spec.rb +74 -0
- data/spec/render/silent_script_spec.rb +97 -0
- data/spec/render/unescape_spec.rb +40 -0
- data/spec/spec_helper.rb +49 -0
- data/spec/tilt_spec.rb +33 -0
- metadata +427 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe 'Plain filter rendering', type: :render do
|
|
4
|
+
it 'renders plain filter' do
|
|
5
|
+
expect(render_string(<<HAML)).to eq("<span>\nhello\n<span>world</span>\n</span>\n")
|
|
6
|
+
%span
|
|
7
|
+
:plain
|
|
8
|
+
he#{'llo'}
|
|
9
|
+
%span world
|
|
10
|
+
HAML
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'strips last empty lines' do
|
|
14
|
+
expect(render_string(<<HAML)).to eq("<span>\nhello\n\nabc\n<span>world</span>\n</span>\n")
|
|
15
|
+
%span
|
|
16
|
+
:plain
|
|
17
|
+
he#{'llo'}
|
|
18
|
+
|
|
19
|
+
abc
|
|
20
|
+
|
|
21
|
+
%span world
|
|
22
|
+
HAML
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe 'Preserve filter rendering', type: :render do
|
|
4
|
+
it 'renders preserve filter' do
|
|
5
|
+
expect(render_string(<<'HAML')).to eq("<span>start</span>\nhello
 <p>wor
ld</p>
<span>hello</span>\n<span>end</span>\n")
|
|
6
|
+
|
|
7
|
+
%span start
|
|
8
|
+
:preserve
|
|
9
|
+
hello
|
|
10
|
+
#{"<p>wor\nld</p>"}
|
|
11
|
+
<span>hello</span>
|
|
12
|
+
%span end
|
|
13
|
+
HAML
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'preserves last empty lines' do
|
|
17
|
+
expect(render_string(<<HAML)).to eq("hello

\n<p></p>\n")
|
|
18
|
+
:preserve
|
|
19
|
+
hello
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
%p
|
|
23
|
+
HAML
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe 'filter rendering', type: :render do
|
|
4
|
+
it 'raises error if invalid filter name is given' do
|
|
5
|
+
expect { render_string(':filter with spaces') }.to raise_error(FastHaml::SyntaxError)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it 'raises error if unregistered filter name is given' do
|
|
9
|
+
expect { render_string(':eagletmt') }.to raise_error(FastHaml::FilterCompilers::NotFound)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe 'Haml comment rendering', type: :render do
|
|
4
|
+
it 'renders nothing' do
|
|
5
|
+
expect(render_string(<<HAML)).to eq("<div>\n<p>hello</p>\n<p>world</p>\n</div>\n")
|
|
6
|
+
%div
|
|
7
|
+
%p hello
|
|
8
|
+
-# this
|
|
9
|
+
should
|
|
10
|
+
not
|
|
11
|
+
be rendered
|
|
12
|
+
%p world
|
|
13
|
+
HAML
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'parses empty comment' do
|
|
17
|
+
expect(render_string(<<HAML)).to eq("<div>\n<p>hello</p>\n<p>world</p>\n</div>\n")
|
|
18
|
+
%div
|
|
19
|
+
%p hello
|
|
20
|
+
-#
|
|
21
|
+
%p world
|
|
22
|
+
HAML
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe 'Multiline rendering', type: :render do
|
|
4
|
+
it 'handles multiline syntax' do
|
|
5
|
+
expect(render_string(<<HAML)).to eq("<p>\nfoo bar baz\nquux\n</p>\n")
|
|
6
|
+
%p
|
|
7
|
+
= "foo " + |
|
|
8
|
+
"bar " + |
|
|
9
|
+
"baz" |
|
|
10
|
+
= "quux"
|
|
11
|
+
HAML
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'handles multiline with non-script line' do
|
|
15
|
+
expect(render_string(<<HAML)).to eq("<p>\nfoo \nbar\n</p>\n")
|
|
16
|
+
%p
|
|
17
|
+
foo |
|
|
18
|
+
bar
|
|
19
|
+
HAML
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'handles multiline at the end of template' do
|
|
23
|
+
expect(render_string(<<HAML)).to eq("<p>\nfoo bar baz \n</p>\n")
|
|
24
|
+
%p
|
|
25
|
+
foo |
|
|
26
|
+
bar |
|
|
27
|
+
baz |
|
|
28
|
+
HAML
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'is not multiline' do
|
|
32
|
+
expect(render_string(<<HAML)).to eq("<div>\nhello\n|\nworld\n</div>\n")
|
|
33
|
+
%div
|
|
34
|
+
hello
|
|
35
|
+
|
|
|
36
|
+
world
|
|
37
|
+
HAML
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe 'Plain rendering', type: :render do
|
|
4
|
+
it 'outputs literally when prefixed with "\\"' do
|
|
5
|
+
expect(render_string('\= @title')).to eq("= @title\n")
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it 'correctly escapes interpolation' do
|
|
9
|
+
expect(render_string(<<'HAML')).to eq("<span>foo\\3bar</span>\n")
|
|
10
|
+
%span foo\\#{1 + 2}bar
|
|
11
|
+
HAML
|
|
12
|
+
expect(render_string(<<'HAML')).to eq("<span>foo\\\#{1 + 2}bar</span>\n")
|
|
13
|
+
%span foo\\\#{1 + 2}bar
|
|
14
|
+
HAML
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'raises error when interpolation is unterminated' do
|
|
18
|
+
expect { render_string('%span foo#{1 + 2') }.to raise_error(FastHaml::TextCompiler::InvalidInterpolation)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe 'Preserve rendering', type: :render do
|
|
4
|
+
it 'parses preserved script' do
|
|
5
|
+
expect(render_string('~ "<p>hello\nworld</p>"')).to eq("<p>hello\nworld</p>\n")
|
|
6
|
+
expect(render_string('%span~ "<p>hello\nworld</p>"')).to eq("<span><p>hello\nworld</p></span>\n")
|
|
7
|
+
end
|
|
8
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe 'Sanitize rendering', type: :render do
|
|
4
|
+
it 'parses sanitized script' do
|
|
5
|
+
# Default in fast_haml
|
|
6
|
+
expect(render_string('&= "hello<p>unescape</p>world"')).to eq("hello<p>unescape</p>world\n")
|
|
7
|
+
expect(render_string(<<HAML)).to eq("<span>\nhello<p>unescape</p>world\n</span>\n")
|
|
8
|
+
%span
|
|
9
|
+
&= "hello<p>unescape</p>world"
|
|
10
|
+
HAML
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'ignores single sanitize mark' do
|
|
14
|
+
expect(render_string('& <p>hello</p>')).to eq("<p>hello</p>\n")
|
|
15
|
+
expect(render_string('%span& <p>hello</p>')).to eq("<span><p>hello</p></span>\n")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'parses == syntax' do
|
|
19
|
+
expect(render_string('&== =<p>hello</p>')).to eq("=<p>hello</p>\n")
|
|
20
|
+
expect(render_string('%span&== =<p>hello</p>')).to eq("<span>=<p>hello</p></span>\n")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context 'with preserve' do
|
|
24
|
+
it 'ignores preserve mark' do
|
|
25
|
+
expect(render_string('&~ "<p>hello</p>"')).to eq("<p>hello</p>\n")
|
|
26
|
+
expect(render_string('%span&~ "<p>hello</p>"')).to eq("<span><p>hello</p></span>\n")
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context 'without Ruby code' do
|
|
31
|
+
it 'raises error' do
|
|
32
|
+
expect { render_string('%span&=') }.to raise_error(FastHaml::SyntaxError)
|
|
33
|
+
expect { render_string('&=') }.to raise_error(FastHaml::SyntaxError)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe 'Script rendering', type: :render do
|
|
4
|
+
it 'parses script' do
|
|
5
|
+
expect(render_string('%span= 1 + 2')).to eq("<span>3</span>\n")
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it 'parses multi-line script' do
|
|
9
|
+
expect(render_string(<<HAML)).to eq("<span>\n3\n</span>\n")
|
|
10
|
+
%span
|
|
11
|
+
= 1 + 2
|
|
12
|
+
HAML
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'parses script and text' do
|
|
16
|
+
expect(render_string(<<HAML)).to eq("<span>\n3\n3\n9\n</span>\n")
|
|
17
|
+
%span
|
|
18
|
+
= 1 + 2
|
|
19
|
+
3
|
|
20
|
+
= 4 + 5
|
|
21
|
+
HAML
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'can contain Ruby comment' do
|
|
25
|
+
expect(render_string('%span= 1 + 2 # comments')).to eq("<span>3</span>\n")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'can contain Ruby comment in multi-line' do
|
|
29
|
+
expect(render_string(<<HAML)).to eq("<span>\n3\n3\n9\n</span>\n")
|
|
30
|
+
%span
|
|
31
|
+
= 1 + 2 # comment
|
|
32
|
+
3
|
|
33
|
+
= 4 + 5 # comment
|
|
34
|
+
HAML
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'can have children' do
|
|
38
|
+
expect(render_string(<<HAML)).to eq("<span>0</span>\n1<span>end</span>\n")
|
|
39
|
+
= 1.times do |i|
|
|
40
|
+
%span= i
|
|
41
|
+
%span end
|
|
42
|
+
HAML
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'escapes unsafe string' do
|
|
46
|
+
expect(render_string(<<HAML)).to eq("<p><script>alert(1)</script></p>\n")
|
|
47
|
+
- title = '<script>alert(1)</script>'
|
|
48
|
+
%p= title
|
|
49
|
+
HAML
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'parses Ruby multiline' do
|
|
53
|
+
expect(render_string(<<HAML)).to eq("<div>\n<span>\n2+3i\n</span>\n</div>\n")
|
|
54
|
+
%div
|
|
55
|
+
%span
|
|
56
|
+
= Complex(2,
|
|
57
|
+
3)
|
|
58
|
+
HAML
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'parses == syntax' do
|
|
62
|
+
expect(render_string('== =#{1+2}hello')).to eq("=3hello\n")
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context 'without Ruby code' do
|
|
66
|
+
it 'raises error' do
|
|
67
|
+
expect { render_string('%span=') }.to raise_error(FastHaml::SyntaxError)
|
|
68
|
+
expect { render_string(<<HAML) }.to raise_error(FastHaml::SyntaxError)
|
|
69
|
+
%span
|
|
70
|
+
=
|
|
71
|
+
HAML
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe 'SilentScript rendering', type: :render do
|
|
4
|
+
it 'parses silent script' do
|
|
5
|
+
expect(render_string(<<HAML)).to eq("<span>0</span>\n<span>1</span>\n")
|
|
6
|
+
- 2.times do |i|
|
|
7
|
+
%span= i
|
|
8
|
+
HAML
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'parses if' do
|
|
12
|
+
expect(render_string(<<HAML)).to eq("<div>\neven\n</div>\n")
|
|
13
|
+
%div
|
|
14
|
+
- if 2.even?
|
|
15
|
+
even
|
|
16
|
+
HAML
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'parses if and text' do
|
|
20
|
+
expect(render_string(<<HAML)).to eq("<div>\neven\nok\n</div>\n")
|
|
21
|
+
%div
|
|
22
|
+
- if 2.even?
|
|
23
|
+
even
|
|
24
|
+
ok
|
|
25
|
+
HAML
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'parses if and else' do
|
|
29
|
+
expect(render_string(<<HAML)).to eq("<div>\nodd\n</div>\n")
|
|
30
|
+
%div
|
|
31
|
+
- if 1.even?
|
|
32
|
+
even
|
|
33
|
+
- else
|
|
34
|
+
odd
|
|
35
|
+
HAML
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'parses if and elsif' do
|
|
39
|
+
expect(render_string(<<HAML)).to eq("<div>\n2\neven\n</div>\n")
|
|
40
|
+
%div
|
|
41
|
+
- if 1.even?
|
|
42
|
+
even
|
|
43
|
+
- elsif 2.even?
|
|
44
|
+
2
|
|
45
|
+
even
|
|
46
|
+
- else
|
|
47
|
+
odd
|
|
48
|
+
HAML
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'parses case-when' do
|
|
52
|
+
expect(render_string(<<HAML)).to eq("<div>\n2\neven\n</div>\n")
|
|
53
|
+
%div
|
|
54
|
+
- case
|
|
55
|
+
- when 1.even?
|
|
56
|
+
even
|
|
57
|
+
- when 2.even?
|
|
58
|
+
2
|
|
59
|
+
even
|
|
60
|
+
- else
|
|
61
|
+
else
|
|
62
|
+
HAML
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'parses Ruby comment' do
|
|
66
|
+
expect(render_string(<<HAML)).to eq("<span>Print me</span>\n")
|
|
67
|
+
- # Ruby comment here
|
|
68
|
+
%span Print me
|
|
69
|
+
HAML
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'parses Ruby multiline' do
|
|
73
|
+
expect(render_string(<<HAML)).to eq("<div>\n<span>ne</span>\n</div>\n")
|
|
74
|
+
%div
|
|
75
|
+
- if 1 == Complex(2,
|
|
76
|
+
3)
|
|
77
|
+
%span eq
|
|
78
|
+
- else
|
|
79
|
+
%span ne
|
|
80
|
+
HAML
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'raises error if no Ruby code is given' do
|
|
84
|
+
expect { render_string('-') }.to raise_error(FastHaml::SyntaxError)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'checks indent levels' do
|
|
88
|
+
expect(render_string(<<HAML)).to eq("<span>hello</span>\n")
|
|
89
|
+
- if true
|
|
90
|
+
%span hello
|
|
91
|
+
- if false
|
|
92
|
+
%span world
|
|
93
|
+
- else
|
|
94
|
+
%span !!!
|
|
95
|
+
HAML
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe 'Unescape rendering', type: :render do
|
|
4
|
+
it 'parses unescape script' do
|
|
5
|
+
expect(render_string('%span!= "hello<p>unescape</p>world"')).to eq("<span>hello<p>unescape</p>world</span>\n")
|
|
6
|
+
expect(render_string(<<HAML)).to eq("<span>\nhello<p>unescape</p>world\n</span>\n")
|
|
7
|
+
%span
|
|
8
|
+
!= "hello<p>unescape</p>world"
|
|
9
|
+
HAML
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'ignores single unescape mark' do
|
|
13
|
+
expect(render_string('! <p>hello</p>')).to eq("<p>hello</p>\n")
|
|
14
|
+
expect(render_string('%span! <p>hello</p>')).to eq("<span><p>hello</p></span>\n")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'has effect on string interpolation in plain' do
|
|
18
|
+
expect(render_string('! <p>#{"<strong>hello</strong>"}</p>')).to eq("<p><strong>hello</strong></p>\n")
|
|
19
|
+
expect(render_string('%span! <p>#{"<strong>hello</strong>"}</p>')).to eq("<span><p><strong>hello</strong></p></span>\n")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'parses == syntax' do
|
|
23
|
+
expect(render_string('!== =#{"<br>"}hello')).to eq("=<br>hello\n")
|
|
24
|
+
expect(render_string('%p!== =#{"<br>"}hello')).to eq("<p>=<br>hello</p>\n")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context 'with preserve' do
|
|
28
|
+
it 'keeps newlines within preserve tags' do
|
|
29
|
+
expect(render_string('!~ "<p>hello\n<pre>pre\nworld</pre></p>"')).to eq("<p>hello\n<pre>pre
world</pre></p>\n")
|
|
30
|
+
expect(render_string('%span!~ "<p>hello\n<pre>pre\nworld</pre></p>"')).to eq("<span><p>hello\n<pre>pre
world</pre></p></span>\n")
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context 'without Ruby code' do
|
|
35
|
+
it 'raises error' do
|
|
36
|
+
expect { render_string('%span!=') }.to raise_error(FastHaml::SyntaxError)
|
|
37
|
+
expect { render_string('!=') }.to raise_error(FastHaml::SyntaxError)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'simplecov'
|
|
2
|
+
require 'coveralls'
|
|
3
|
+
|
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
|
5
|
+
SimpleCov::Formatter::HTMLFormatter,
|
|
6
|
+
Coveralls::SimpleCov::Formatter,
|
|
7
|
+
]
|
|
8
|
+
SimpleCov.start do
|
|
9
|
+
add_filter File.dirname(__FILE__)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
require 'fast_haml'
|
|
13
|
+
|
|
14
|
+
module RenderSpecHelper
|
|
15
|
+
def render_string(str, options = {})
|
|
16
|
+
eval(FastHaml::Engine.new(options).call(str))
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
RSpec.configure do |config|
|
|
21
|
+
config.expect_with :rspec do |expectations|
|
|
22
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
config.mock_with :rspec do |mocks|
|
|
26
|
+
mocks.verify_partial_doubles = true
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
config.filter_run :focus
|
|
30
|
+
config.run_all_when_everything_filtered = true
|
|
31
|
+
|
|
32
|
+
config.disable_monkey_patching!
|
|
33
|
+
|
|
34
|
+
config.warnings = true
|
|
35
|
+
|
|
36
|
+
if config.files_to_run.one?
|
|
37
|
+
config.default_formatter = 'doc'
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
if ENV['TRAVIS']
|
|
41
|
+
config.profile_examples = 10
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
config.order = :random
|
|
45
|
+
|
|
46
|
+
Kernel.srand config.seed
|
|
47
|
+
|
|
48
|
+
config.include(RenderSpecHelper, type: :render)
|
|
49
|
+
end
|
data/spec/tilt_spec.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe 'Tilt integration' do
|
|
4
|
+
def tilt(str)
|
|
5
|
+
Tilt.new('spec.haml') { str }
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it 'renders with fast_haml' do
|
|
9
|
+
expect(Tilt['spec.haml']).to equal(FastHaml::Tilt)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'renders' do
|
|
13
|
+
expect(tilt('%span= 1+2').render).to eq("<span>3</span>\n")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'renders scope' do
|
|
17
|
+
scope = Class.new do
|
|
18
|
+
def hello
|
|
19
|
+
'world'
|
|
20
|
+
end
|
|
21
|
+
end.new
|
|
22
|
+
|
|
23
|
+
expect(tilt('%span= hello').render(scope)).to eq("<span>world</span>\n")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'renders locals' do
|
|
27
|
+
expect(tilt('%span= hello').render(Object.new, hello: 'world')).to eq("<span>world</span>\n")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'renders yield block' do
|
|
31
|
+
expect(tilt('%span= yield').render { 'world' }).to eq("<span>world</span>\n")
|
|
32
|
+
end
|
|
33
|
+
end
|