faml 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.gitmodules +3 -0
- data/.rspec +2 -0
- data/.travis.yml +27 -0
- data/Appraisals +26 -0
- data/CHANGELOG.md +47 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +115 -0
- data/Rakefile +28 -0
- data/benchmark/attribute_builder.haml +5 -0
- data/benchmark/rendering.rb +35 -0
- data/bin/faml +4 -0
- data/ext/attribute_builder/attribute_builder.c +261 -0
- data/ext/attribute_builder/extconf.rb +3 -0
- data/faml.gemspec +38 -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/faml.rb +10 -0
- data/lib/faml/ast.rb +112 -0
- data/lib/faml/cli.rb +38 -0
- data/lib/faml/compiler.rb +374 -0
- data/lib/faml/element_parser.rb +235 -0
- data/lib/faml/engine.rb +34 -0
- data/lib/faml/filter_compilers.rb +41 -0
- data/lib/faml/filter_compilers/base.rb +43 -0
- data/lib/faml/filter_compilers/cdata.rb +15 -0
- data/lib/faml/filter_compilers/coffee.rb +16 -0
- data/lib/faml/filter_compilers/css.rb +16 -0
- data/lib/faml/filter_compilers/escaped.rb +23 -0
- data/lib/faml/filter_compilers/javascript.rb +16 -0
- data/lib/faml/filter_compilers/markdown.rb +18 -0
- data/lib/faml/filter_compilers/plain.rb +15 -0
- data/lib/faml/filter_compilers/preserve.rb +26 -0
- data/lib/faml/filter_compilers/ruby.rb +17 -0
- data/lib/faml/filter_compilers/sass.rb +15 -0
- data/lib/faml/filter_compilers/scss.rb +16 -0
- data/lib/faml/filter_compilers/tilt_base.rb +34 -0
- data/lib/faml/filter_parser.rb +54 -0
- data/lib/faml/html.rb +58 -0
- data/lib/faml/indent_tracker.rb +84 -0
- data/lib/faml/line_parser.rb +66 -0
- data/lib/faml/newline.rb +30 -0
- data/lib/faml/parser.rb +211 -0
- data/lib/faml/parser_utils.rb +17 -0
- data/lib/faml/rails_handler.rb +10 -0
- data/lib/faml/railtie.rb +9 -0
- data/lib/faml/ruby_multiline.rb +23 -0
- data/lib/faml/script_parser.rb +84 -0
- data/lib/faml/static_hash_parser.rb +113 -0
- data/lib/faml/syntax_error.rb +10 -0
- data/lib/faml/text_compiler.rb +69 -0
- data/lib/faml/tilt.rb +17 -0
- data/lib/faml/version.rb +3 -0
- data/spec/compiler_newline_spec.rb +162 -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.ru +4 -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/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/faml_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 +241 -0
- data/spec/render/comment_spec.rb +61 -0
- data/spec/render/doctype_spec.rb +57 -0
- data/spec/render/element_spec.rb +136 -0
- data/spec/render/filters/cdata_spec.rb +12 -0
- data/spec/render/filters/coffee_spec.rb +25 -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/markdown_spec.rb +19 -0
- data/spec/render/filters/plain_spec.rb +24 -0
- data/spec/render/filters/preserve_spec.rb +24 -0
- data/spec/render/filters/ruby_spec.rb +13 -0
- data/spec/render/filters/sass_spec.rb +28 -0
- data/spec/render/filters/scss_spec.rb +32 -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/newline_spec.rb +83 -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 +81 -0
- data/spec/render/silent_script_spec.rb +97 -0
- data/spec/render/unescape_spec.rb +45 -0
- data/spec/spec_helper.rb +47 -0
- data/spec/tilt_spec.rb +33 -0
- metadata +489 -0
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'Element rendering', type: :render do
|
4
|
+
it 'parses one-line element' do
|
5
|
+
expect(render_string('%span hello')).to eq("<span>hello</span>\n")
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'parses multi-line element' do
|
9
|
+
expect(render_string(<<HAML)).to eq("<span>\nhello\n</span>\n")
|
10
|
+
%span
|
11
|
+
hello
|
12
|
+
HAML
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'parses nested elements' do
|
16
|
+
expect(render_string(<<HAML)).to eq("<span>\n<b>\nhello\n</b>\n<i>\n<small>world</small>\n</i>\n</span>\n")
|
17
|
+
%span
|
18
|
+
%b
|
19
|
+
hello
|
20
|
+
%i
|
21
|
+
%small world
|
22
|
+
HAML
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'parses multi-line texts' do
|
26
|
+
expect(render_string(<<HAML)).to eq("<span>\n<b>\nhello\nworld\n</b>\n</span>\n")
|
27
|
+
%span
|
28
|
+
%b
|
29
|
+
hello
|
30
|
+
world
|
31
|
+
HAML
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'skips empty lines' do
|
35
|
+
expect(render_string(<<HAML)).to eq("<span>\n<b>\nhello\n</b>\n</span>\n")
|
36
|
+
%span
|
37
|
+
|
38
|
+
%b
|
39
|
+
|
40
|
+
hello
|
41
|
+
|
42
|
+
HAML
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'raises error if indent is wrong' do
|
46
|
+
expect { render_string(<<HAML) }.to raise_error(Faml::IndentTracker::IndentMismatch)
|
47
|
+
%div
|
48
|
+
%div
|
49
|
+
%div
|
50
|
+
%div
|
51
|
+
HAML
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'parses classes' do
|
55
|
+
expect(render_string('%span.foo.bar hello')).to eq(%Q{<span class='foo bar'>hello</span>\n})
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'parses id' do
|
59
|
+
expect(render_string('%span#foo-bar hello')).to eq(%Q{<span id='foo-bar'>hello</span>\n})
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'parses classes and id' do
|
63
|
+
expect(render_string('%span.foo#foo-bar.bar hello')).to eq(%Q{<span class='foo bar' id='foo-bar'>hello</span>\n})
|
64
|
+
end
|
65
|
+
|
66
|
+
it "doesn't skip spaces before attribute list" do
|
67
|
+
expect(render_string('%span {hello}')).to eq("<span>{hello}</span>\n")
|
68
|
+
expect(render_string('%span (hello)')).to eq("<span>(hello)</span>\n")
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'with invalid tag name' do
|
72
|
+
it 'raises error' do
|
73
|
+
expect { render_string('%.foo') }.to raise_error(Faml::SyntaxError)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'parses #' do
|
78
|
+
expect(render_string('#main')).to eq(%Q{<div id='main'></div>\n})
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'parses .' do
|
82
|
+
expect(render_string('.wrapper.main')).to eq(%Q{<div class='wrapper main'></div>\n})
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'parses Ruby multiline' do
|
86
|
+
expect(render_string(<<HAML)).to eq("<div>\n<span>2+3i</span>\n</div>\n")
|
87
|
+
%div
|
88
|
+
%span= Complex(2,
|
89
|
+
3)
|
90
|
+
HAML
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'parses string interpolation' do
|
94
|
+
expect(render_string(%q|%span hello <span> #{'</span>'} </span>|)).to eq("<span>hello <span> </span> </span></span>\n")
|
95
|
+
expect(render_string(<<'HAML')).to eq("<span>\nhello <span> </span> </span>\n</span>\n")
|
96
|
+
%span
|
97
|
+
hello <span> #{{text: '</span>'}[:text]} </span>
|
98
|
+
HAML
|
99
|
+
expect(render_string(<<'HAML')).to eq("<span>\nhello <span> </span> </span>\n</span>\n")
|
100
|
+
- @var = '</span>'
|
101
|
+
%span
|
102
|
+
hello <span> #@var </span>
|
103
|
+
HAML
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'parses string interpolation with multibyte characters' do
|
107
|
+
expect(render_string(%q|#{'日本語'} にほんご|)).to eq("日本語 にほんご\n")
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'recognized escaped string interpolation' do
|
111
|
+
expect(render_string(%q|%p hello \#{1 + 2}|)).to eq("<p>hello \#{1 + 2}</p>\n")
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'parses self-closing tag' do
|
115
|
+
expect(render_string('%p/')).to eq("<p>\n")
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'renders some attributes as self-closing by default' do
|
119
|
+
expect(render_string('%meta{"http-equiv" => "Content-Type", :content => "text/html"}')).to eq("<meta content='text/html' http-equiv='Content-Type'>\n")
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'parses == syntax' do
|
123
|
+
expect(render_string('%p== =#{1+2}hello')).to eq("<p>=3hello</p>\n")
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'raises error if self-closing tag have text' do
|
127
|
+
expect { render_string('%p/ hello') }.to raise_error(Faml::SyntaxError)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'raises error if self-closing tag have children' do
|
131
|
+
expect { render_string(<<HAML) }.to raise_error(Faml::SyntaxError)
|
132
|
+
%p/
|
133
|
+
hello
|
134
|
+
HAML
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'CDATA filter rendering', type: :render do
|
4
|
+
it 'renders CDATA filter' do
|
5
|
+
expect(render_string(<<'HAML')).to eq("<![CDATA[\n hello\n world\n <span>hello</span>\n]]>\n")
|
6
|
+
:cdata
|
7
|
+
hello
|
8
|
+
#{'world'}
|
9
|
+
<span>hello</span>
|
10
|
+
HAML
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'CoffeeScript filter rendering', type: :render do
|
4
|
+
it 'renders CoffeeScript filter' do
|
5
|
+
html = render_string(<<HAML)
|
6
|
+
:coffee
|
7
|
+
square = (x) -> x * x
|
8
|
+
square(3)
|
9
|
+
HAML
|
10
|
+
expect(html).to include('<script>')
|
11
|
+
expect(html).to include('square = function(x)')
|
12
|
+
expect(html).to include('square(3)')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'parses string interpolation' do
|
16
|
+
html = render_string(<<'HAML')
|
17
|
+
:coffee
|
18
|
+
square = (x) -> x * x
|
19
|
+
square(#{1 + 2})
|
20
|
+
HAML
|
21
|
+
expect(html).to include('<script>')
|
22
|
+
expect(html).to include('square = function(x)')
|
23
|
+
expect(html).to include('square(3)')
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'CSS filter rendering', type: :render do
|
4
|
+
it 'renders css filter' do
|
5
|
+
expect(render_string(<<HAML)).to eq("<div>\n<style>\n html { font-size: 12px; }\n</style>\n<span>hello</span>\n</div>\n")
|
6
|
+
%div
|
7
|
+
:css
|
8
|
+
html { font-size: 12px; }
|
9
|
+
%span hello
|
10
|
+
HAML
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'keeps indent' do
|
14
|
+
expect(render_string(<<HAML)).to eq("<div>\n<style>\n html {\n font-size: 12px;\n }\n</style>\n<span>hello</span>\n</div>\n")
|
15
|
+
%div
|
16
|
+
:css
|
17
|
+
html {
|
18
|
+
font-size: 12px;
|
19
|
+
}
|
20
|
+
%span hello
|
21
|
+
HAML
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'ignores empty filter' do
|
25
|
+
expect(render_string(<<HAML)).to eq("<div>\n<span>hello</span>\n</div>\n")
|
26
|
+
%div
|
27
|
+
:css
|
28
|
+
%span hello
|
29
|
+
HAML
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'parses string interpolation' do
|
33
|
+
expect(render_string(<<'HAML')).to eq("<style>\n html { font-size: 12px; }\n</style>\n")
|
34
|
+
:css
|
35
|
+
html { font-size: #{10 + 2}px; }
|
36
|
+
HAML
|
37
|
+
end
|
38
|
+
|
39
|
+
it "doesn't escape in string interpolation" do
|
40
|
+
expect(render_string(<<'HAML')).to eq("<style>\n <span/>\n</style>\n")
|
41
|
+
:css
|
42
|
+
#{'<span/>'}
|
43
|
+
HAML
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'Escaped filter rendering', type: :render do
|
4
|
+
it' renders escaped filter' do
|
5
|
+
expect(render_string(<<'HAML')).to eq("<span>start</span>\nhello\n <p>world</p>\n<span>hello</span>\n\n<span>end</span>\n")
|
6
|
+
%span start
|
7
|
+
:escaped
|
8
|
+
hello
|
9
|
+
#{'<p>world</p>'}
|
10
|
+
<span>hello</span>
|
11
|
+
%span end
|
12
|
+
HAML
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'JavaScript filter rendering', type: :render do
|
4
|
+
it 'renders javascript filter' do
|
5
|
+
expect(render_string(<<HAML)).to eq("<div>\n<script>\n alert('hello');\n</script>\n<span>world</span>\n</div>\n")
|
6
|
+
%div
|
7
|
+
:javascript
|
8
|
+
alert('hello');
|
9
|
+
%span world
|
10
|
+
HAML
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'keeps indent' do
|
14
|
+
expect(render_string(<<HAML)).to eq("<div>\n<script>\n alert('hello');\n \n alert('world');\n</script>\n</div>\n")
|
15
|
+
%div
|
16
|
+
:javascript
|
17
|
+
alert('hello');
|
18
|
+
|
19
|
+
alert('world');
|
20
|
+
HAML
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'ignores empty filter' do
|
24
|
+
expect(render_string(<<HAML)).to eq("<div>\n<span>world</span>\n</div>\n")
|
25
|
+
%div
|
26
|
+
:javascript
|
27
|
+
%span world
|
28
|
+
HAML
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'parses string interpolation' do
|
32
|
+
expect(render_string(<<'HAML')).to eq("<script>\n var x = 3;\n</script>\n")
|
33
|
+
:javascript
|
34
|
+
var x = #{1 + 2};
|
35
|
+
HAML
|
36
|
+
end
|
37
|
+
|
38
|
+
it "doesn't escape in string interpolation" do
|
39
|
+
expect(render_string(<<'HAML')).to eq("<script>\n <span/>\n</script>\n")
|
40
|
+
:javascript
|
41
|
+
#{'<span/>'}
|
42
|
+
HAML
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'Markdown filter rendering', type: :render do
|
4
|
+
it 'renders Markdown filter' do
|
5
|
+
expect(render_string(<<HAML)).to eq("<h1>hello</h1>\nworld\n")
|
6
|
+
:markdown
|
7
|
+
# hello
|
8
|
+
world
|
9
|
+
HAML
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'parses string interpolation' do
|
13
|
+
expect(render_string(<<'HAML')).to eq("<h1>hello</h1>\nworld\n")
|
14
|
+
:markdown
|
15
|
+
# #{'hello'}
|
16
|
+
world
|
17
|
+
HAML
|
18
|
+
end
|
19
|
+
end
|
@@ -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,24 @@
|
|
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
|
+
%span start
|
7
|
+
:preserve
|
8
|
+
hello
|
9
|
+
#{"<p>wor\nld</p>"}
|
10
|
+
<span>hello</span>
|
11
|
+
%span end
|
12
|
+
HAML
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'preserves last empty lines' do
|
16
|
+
expect(render_string(<<HAML)).to eq("hello

\n<p></p>\n")
|
17
|
+
:preserve
|
18
|
+
hello
|
19
|
+
|
20
|
+
|
21
|
+
%p
|
22
|
+
HAML
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'SASS filter rendering', type: :render do
|
4
|
+
it 'renders SASS filter' do
|
5
|
+
html = render_string(<<'HAML')
|
6
|
+
:sass
|
7
|
+
nav
|
8
|
+
ul
|
9
|
+
margin: 0
|
10
|
+
content: "hello"
|
11
|
+
HAML
|
12
|
+
expect(html).to include('<style>')
|
13
|
+
expect(html).to include('nav ul {')
|
14
|
+
expect(html).to include('content: "hello"')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'parses string interpolation' do
|
18
|
+
html = render_string(<<'HAML')
|
19
|
+
:sass
|
20
|
+
nav
|
21
|
+
ul
|
22
|
+
margin: #{0 + 5}px
|
23
|
+
HAML
|
24
|
+
expect(html).to include('<style>')
|
25
|
+
expect(html).to include('nav ul {')
|
26
|
+
expect(html).to include('margin: 5px')
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'SCSS filter rendering', type: :render do
|
4
|
+
it 'renders SCSS filter' do
|
5
|
+
html = render_string(<<'HAML')
|
6
|
+
:scss
|
7
|
+
nav {
|
8
|
+
ul {
|
9
|
+
margin: 0;
|
10
|
+
content: "hello";
|
11
|
+
}
|
12
|
+
}
|
13
|
+
HAML
|
14
|
+
expect(html).to include('<style>')
|
15
|
+
expect(html).to include('nav ul {')
|
16
|
+
expect(html).to include('content: "hello"')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'parses string interpolation' do
|
20
|
+
html = render_string(<<'HAML')
|
21
|
+
:scss
|
22
|
+
nav {
|
23
|
+
ul {
|
24
|
+
margin: #{0 + 5}px;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
HAML
|
28
|
+
expect(html).to include('<style>')
|
29
|
+
expect(html).to include('nav ul {')
|
30
|
+
expect(html).to include('margin: 5px')
|
31
|
+
end
|
32
|
+
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(Faml::SyntaxError)
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'raises error if unregistered filter name is given' do
|
9
|
+
expect { render_string(':eagletmt') }.to raise_error(Faml::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
|