slim 1.3.6 → 1.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +17 -5
- data/CHANGES +32 -0
- data/Gemfile +9 -1
- data/README.md +51 -32
- data/lib/slim.rb +2 -2
- data/lib/slim/code_attributes.rb +3 -3
- data/lib/slim/command.rb +4 -7
- data/lib/slim/{control_structures.rb → controls.rb} +1 -1
- data/lib/slim/{embedded_engine.rb → embedded.rb} +23 -4
- data/lib/slim/end_inserter.rb +1 -1
- data/lib/slim/engine.rb +28 -13
- data/lib/slim/filter.rb +1 -1
- data/lib/slim/logic_less/filter.rb +1 -1
- data/lib/slim/parser.rb +49 -22
- data/lib/slim/splat_attributes.rb +7 -7
- data/lib/slim/template.rb +2 -2
- data/lib/slim/translator.rb +3 -3
- data/lib/slim/version.rb +1 -1
- data/slim.gemspec +1 -8
- data/test/core/helper.rb +21 -13
- data/test/core/test_code_escaping.rb +62 -4
- data/test/core/test_code_structure.rb +42 -0
- data/test/core/test_embedded_engines.rb +79 -0
- data/test/core/test_html_attributes.rb +23 -1
- data/test/core/test_parser_errors.rb +8 -0
- data/test/core/test_pretty.rb +37 -8
- data/test/core/test_ruby_errors.rb +6 -2
- data/test/core/test_tabs.rb +169 -0
- data/test/literate/TESTS.md +26 -6
- data/test/rails/app/controllers/parents_controller.rb +1 -0
- data/test/rails/app/controllers/slim_controller.rb +1 -1
- data/test/rails/config/environments/test.rb +2 -0
- data/test/rails/config/initializers/secret_token.rb +1 -1
- data/test/rails/test/test_slim.rb +6 -2
- metadata +12 -115
- data/test/rails/config/environments/development.rb +0 -23
- data/test/rails/config/environments/production.rb +0 -49
@@ -104,4 +104,46 @@ div
|
|
104
104
|
'This is the menu'
|
105
105
|
end
|
106
106
|
end
|
107
|
+
|
108
|
+
def test_render_with_begin_rescue
|
109
|
+
source = %q{
|
110
|
+
- begin
|
111
|
+
p Begin
|
112
|
+
- rescue
|
113
|
+
p Rescue
|
114
|
+
p After
|
115
|
+
}
|
116
|
+
|
117
|
+
assert_html '<p>Begin</p><p>After</p>', source
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_render_with_begin_rescue_exception
|
121
|
+
source = %q{
|
122
|
+
- begin
|
123
|
+
p Begin
|
124
|
+
- raise 'Boom'
|
125
|
+
p After Boom
|
126
|
+
- rescue => ex
|
127
|
+
p = ex.message
|
128
|
+
p After
|
129
|
+
}
|
130
|
+
|
131
|
+
assert_html '<p>Begin</p><p>Boom</p><p>After</p>', source
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_render_with_begin_rescue_ensure
|
135
|
+
source = %q{
|
136
|
+
- begin
|
137
|
+
p Begin
|
138
|
+
- raise 'Boom'
|
139
|
+
p After Boom
|
140
|
+
- rescue => ex
|
141
|
+
p = ex.message
|
142
|
+
- ensure
|
143
|
+
p Ensure
|
144
|
+
p After
|
145
|
+
}
|
146
|
+
|
147
|
+
assert_html '<p>Begin</p><p>Boom</p><p>Ensure</p><p>After</p>', source
|
148
|
+
end
|
107
149
|
end
|
@@ -14,6 +14,57 @@ p
|
|
14
14
|
assert_html "<p><b>Hello from BEFORE ERB BLOCK!</b>\nSecond Line!\ntrue</p>", source
|
15
15
|
end
|
16
16
|
|
17
|
+
def test_wip_render_with_asciidoc
|
18
|
+
source = %q{
|
19
|
+
asciidoc:
|
20
|
+
== Header
|
21
|
+
Hello from #{"AsciiDoc!"}
|
22
|
+
|
23
|
+
#{1+2}
|
24
|
+
|
25
|
+
* one
|
26
|
+
* two
|
27
|
+
}
|
28
|
+
|
29
|
+
expected = <<-EOS
|
30
|
+
<div class="sect1">
|
31
|
+
<h2 id="_header">Header</h2>
|
32
|
+
<div class="sectionbody">
|
33
|
+
<div class="paragraph">
|
34
|
+
<p>Hello from AsciiDoc!</p>
|
35
|
+
</div>
|
36
|
+
<div class="paragraph">
|
37
|
+
<p>3</p>
|
38
|
+
</div>
|
39
|
+
<div class="ulist">
|
40
|
+
<ul>
|
41
|
+
<li>
|
42
|
+
<p>one</p>
|
43
|
+
</li>
|
44
|
+
<li>
|
45
|
+
<p>two</p>
|
46
|
+
</li>
|
47
|
+
</ul>
|
48
|
+
</div>
|
49
|
+
</div>
|
50
|
+
</div>
|
51
|
+
EOS
|
52
|
+
# render, then remove blank lines and unindent the remaining lines
|
53
|
+
output = render(source).gsub(/^ *(\n|(?=[^ ]))/, '')
|
54
|
+
|
55
|
+
assert_equal expected, output
|
56
|
+
|
57
|
+
Slim::Embedded.with_options(:asciidoc => {:compact => true, :attributes => {'sectids!' => ''}}) do
|
58
|
+
# render, then unindent lines
|
59
|
+
output = render(source).gsub(/^ *(?=[^ ])/, '')
|
60
|
+
assert_equal expected.gsub('<h2 id="_header">', '<h2>'), output
|
61
|
+
end
|
62
|
+
|
63
|
+
# render again, then remove blank lines and unindent the remaining lines
|
64
|
+
output = render(source).gsub(/^ *(\n|(?=[^ ]))/, '')
|
65
|
+
assert_equal expected, output
|
66
|
+
end
|
67
|
+
|
17
68
|
def test_render_with_markdown
|
18
69
|
source = %q{
|
19
70
|
markdown:
|
@@ -90,6 +141,34 @@ javascript:
|
|
90
141
|
assert_html %q|<script type="text/javascript">$(function() { alert('hello'); });</script>|, source
|
91
142
|
end
|
92
143
|
|
144
|
+
def test_render_with_javascript_with_explicit_html_comment
|
145
|
+
Slim::Engine.with_options(:js_wrapper => :comment) do
|
146
|
+
source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi"
|
147
|
+
assert_html "<script type=\"text/javascript\"><!--\n$(function() {});\nalert('hello')\n//--></script><p>Hi</p>", source
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_render_with_javascript_with_explicit_cdata_comment
|
152
|
+
Slim::Engine.with_options(:js_wrapper => :cdata) do
|
153
|
+
source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi"
|
154
|
+
assert_html "<script type=\"text/javascript\">\n//<![CDATA[\n$(function() {});\nalert('hello')\n//]]>\n</script><p>Hi</p>", source
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_render_with_javascript_with_format_xhtml_comment
|
159
|
+
Slim::Engine.with_options(:js_wrapper => :guess, :format => :xhtml) do
|
160
|
+
source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi"
|
161
|
+
assert_html "<script type=\"text/javascript\">\n//<![CDATA[\n$(function() {});\nalert('hello')\n//]]>\n</script><p>Hi</p>", source
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_render_with_javascript_with_format_html_comment
|
166
|
+
Slim::Engine.with_options(:js_wrapper => :guess, :format => :html) do
|
167
|
+
source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi"
|
168
|
+
assert_html "<script type=\"text/javascript\"><!--\n$(function() {});\nalert('hello')\n//--></script><p>Hi</p>", source
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
93
172
|
def test_render_with_ruby
|
94
173
|
source = %q{
|
95
174
|
ruby:
|
@@ -52,6 +52,20 @@ p id=(false ? 'notshown' : 'shown') = output_number
|
|
52
52
|
assert_html '<div id="alpha-beta">Test it</div>', source, :attr_delimiter => {'class' => ' ', 'id' => '-' }
|
53
53
|
end
|
54
54
|
|
55
|
+
def test_id_attribute_merging3
|
56
|
+
source = %{
|
57
|
+
#alpha id="beta" Test it
|
58
|
+
}
|
59
|
+
assert_html '<div id="alpha_beta">Test it</div>', source, :merge_attrs => {'class' => ' ', 'id' => '_' }
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_id_attribute_merging4
|
63
|
+
source = %{
|
64
|
+
#alpha id="beta" Test it
|
65
|
+
}
|
66
|
+
assert_html '<div id="alpha-beta">Test it</div>', source, :merge_attrs => {'class' => ' ', 'id' => '-' }
|
67
|
+
end
|
68
|
+
|
55
69
|
def test_boolean_attribute_false
|
56
70
|
source = %{
|
57
71
|
- cond=false
|
@@ -143,7 +157,7 @@ h1 *hash This is my title
|
|
143
157
|
|
144
158
|
def test_closed_splat_tag
|
145
159
|
source = %q{
|
146
|
-
*hash /
|
160
|
+
*hash /
|
147
161
|
}
|
148
162
|
|
149
163
|
assert_html '<div a="The letter a" b="The letter b"/>', source
|
@@ -231,4 +245,12 @@ p(id="marvin" class=nil nonempty=("".to_s) data-info="Illudium Q-36")= output_nu
|
|
231
245
|
|
232
246
|
assert_html '<p data-info="Illudium Q-36" id="marvin" nonempty="">1337</p>', source
|
233
247
|
end
|
248
|
+
|
249
|
+
def test_double_escape_warning
|
250
|
+
source = %q{
|
251
|
+
a href='http://slim-lang.com?a=1&b=2'
|
252
|
+
}
|
253
|
+
|
254
|
+
assert_html '<a href="http://slim-lang.com?a=1&b=2"></a>', source
|
255
|
+
end
|
234
256
|
end
|
@@ -149,4 +149,12 @@ html: body:/comment
|
|
149
149
|
}
|
150
150
|
assert_syntax_error "Expected tag\n (__TEMPLATE__), Line 2, Column 11\n html: body:/comment\n ^\n", source
|
151
151
|
end
|
152
|
+
|
153
|
+
def test_unexpected_text_after_closed
|
154
|
+
source = %{
|
155
|
+
img / text
|
156
|
+
}
|
157
|
+
|
158
|
+
assert_syntax_error "Unexpected text after closed tag\n (__TEMPLATE__), Line 2, Column 6\n img / text\n ^\n", source
|
159
|
+
end
|
152
160
|
end
|
data/test/core/test_pretty.rb
CHANGED
@@ -41,7 +41,9 @@ html
|
|
41
41
|
result = %q{<!DOCTYPE html>
|
42
42
|
<html>
|
43
43
|
<head>
|
44
|
-
<title>
|
44
|
+
<title>
|
45
|
+
Hello World!
|
46
|
+
</title>
|
45
47
|
<!--Meta tags
|
46
48
|
with long explanatory
|
47
49
|
multiline comment-->
|
@@ -52,24 +54,51 @@ html
|
|
52
54
|
<!--Javascripts-->
|
53
55
|
<script src="jquery.js"></script>
|
54
56
|
<script src="jquery.ui.js"></script>
|
55
|
-
<!--[if lt IE 9]
|
56
|
-
<script src="old-
|
57
|
+
<!--[if lt IE 9]>
|
58
|
+
<script src="old-ie1.js"></script>
|
59
|
+
<script src="old-ie2.js"></script>
|
60
|
+
<![endif]-->
|
57
61
|
<style type="text/css">
|
58
62
|
body {
|
59
63
|
background-color: red;
|
60
64
|
}
|
61
|
-
|
65
|
+
</style>
|
62
66
|
</head>
|
63
67
|
<body>
|
64
68
|
<div id="container">
|
65
|
-
<p>
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
+
<p>
|
70
|
+
Hello
|
71
|
+
World!
|
72
|
+
</p>
|
73
|
+
<p>
|
74
|
+
dynamic text with
|
75
|
+
newline
|
76
|
+
</p>
|
69
77
|
</div>
|
70
78
|
</body>
|
71
79
|
</html>}
|
72
80
|
|
73
81
|
assert_html result, source
|
74
82
|
end
|
83
|
+
|
84
|
+
def test_partials
|
85
|
+
body = %q{body
|
86
|
+
== render content}
|
87
|
+
|
88
|
+
content = %q{div
|
89
|
+
| content}
|
90
|
+
|
91
|
+
source = %q{html
|
92
|
+
== render body, :scope => self, :locals => { :content => content }}
|
93
|
+
|
94
|
+
result = %q{<html>
|
95
|
+
<body>
|
96
|
+
<div>
|
97
|
+
content
|
98
|
+
</div>
|
99
|
+
</body>
|
100
|
+
</html>}
|
101
|
+
|
102
|
+
assert_html result, source, :scope => self, :locals => {:body => body, :content => content }
|
103
|
+
end
|
75
104
|
end
|
@@ -161,7 +161,9 @@ p
|
|
161
161
|
- test = 123
|
162
162
|
= "Hello from within a block! "
|
163
163
|
}
|
164
|
-
|
164
|
+
# FIXME: Tilt add stupid end;end;end at the end, this leads to wrong line numbers
|
165
|
+
# See also #342
|
166
|
+
assert_ruby_syntax_error "(__TEMPLATE__):7", source
|
165
167
|
end
|
166
168
|
|
167
169
|
def test_invalid_nested_output
|
@@ -170,7 +172,9 @@ p
|
|
170
172
|
= "Hello Ruby!"
|
171
173
|
= "Hello from within a block! "
|
172
174
|
}
|
173
|
-
|
175
|
+
# FIXME: Tilt add stupid end;end;end at the end, this leads to wrong line numbers
|
176
|
+
# See also #342
|
177
|
+
assert_ruby_syntax_error "(__TEMPLATE__):7", source
|
174
178
|
end
|
175
179
|
|
176
180
|
def test_invalid_embedded_engine
|
@@ -0,0 +1,169 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSlimTabs < TestSlim
|
4
|
+
|
5
|
+
def teardown
|
6
|
+
Slim::Engine.set_default_options :tabsize => 4
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_single_tab1_expansion
|
10
|
+
|
11
|
+
Slim::Engine.set_default_options :tabsize => 1
|
12
|
+
|
13
|
+
source = %Q{
|
14
|
+
|
|
15
|
+
\t0
|
16
|
+
\t1
|
17
|
+
\t2
|
18
|
+
\t3
|
19
|
+
\t4
|
20
|
+
\t5
|
21
|
+
\t6
|
22
|
+
\t7
|
23
|
+
\t8
|
24
|
+
}
|
25
|
+
|
26
|
+
result = %q{
|
27
|
+
0
|
28
|
+
1
|
29
|
+
2
|
30
|
+
3
|
31
|
+
4
|
32
|
+
5
|
33
|
+
6
|
34
|
+
7
|
35
|
+
8
|
36
|
+
}.strip
|
37
|
+
|
38
|
+
assert_html result, source
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_single_tab4_expansion
|
42
|
+
|
43
|
+
Slim::Engine.set_default_options :tabsize => 4
|
44
|
+
|
45
|
+
source = %Q{
|
46
|
+
|
|
47
|
+
\t0
|
48
|
+
\t1
|
49
|
+
\t2
|
50
|
+
\t3
|
51
|
+
\t4
|
52
|
+
\t5
|
53
|
+
\t6
|
54
|
+
\t7
|
55
|
+
\t8
|
56
|
+
}
|
57
|
+
|
58
|
+
result = %q{
|
59
|
+
0
|
60
|
+
1
|
61
|
+
2
|
62
|
+
3
|
63
|
+
4
|
64
|
+
5
|
65
|
+
6
|
66
|
+
7
|
67
|
+
8
|
68
|
+
}.strip
|
69
|
+
|
70
|
+
assert_html result, source
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_multi_tab1_expansion
|
74
|
+
|
75
|
+
Slim::Engine.set_default_options :tabsize => 1
|
76
|
+
|
77
|
+
source = %Q{
|
78
|
+
|
|
79
|
+
\t0
|
80
|
+
\t\t1
|
81
|
+
\t \t2
|
82
|
+
\t \t3
|
83
|
+
\t \t4
|
84
|
+
\t\t1
|
85
|
+
\t \t2
|
86
|
+
\t \t3
|
87
|
+
\t \t4
|
88
|
+
\t\t1
|
89
|
+
\t \t2
|
90
|
+
\t \t3
|
91
|
+
\t \t4
|
92
|
+
\t\t1
|
93
|
+
\t \t2
|
94
|
+
\t \t3
|
95
|
+
\t \t4
|
96
|
+
}
|
97
|
+
|
98
|
+
result = %q{
|
99
|
+
0
|
100
|
+
1
|
101
|
+
2
|
102
|
+
3
|
103
|
+
4
|
104
|
+
1
|
105
|
+
2
|
106
|
+
3
|
107
|
+
4
|
108
|
+
1
|
109
|
+
2
|
110
|
+
3
|
111
|
+
4
|
112
|
+
1
|
113
|
+
2
|
114
|
+
3
|
115
|
+
4
|
116
|
+
}.strip
|
117
|
+
|
118
|
+
assert_html result, source
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_multi_tab4_expansion
|
122
|
+
|
123
|
+
Slim::Engine.set_default_options :tabsize => 4
|
124
|
+
|
125
|
+
source = %Q{
|
126
|
+
|
|
127
|
+
\t0
|
128
|
+
\t\t1
|
129
|
+
\t \t2
|
130
|
+
\t \t3
|
131
|
+
\t \t4
|
132
|
+
\t\t1
|
133
|
+
\t \t2
|
134
|
+
\t \t3
|
135
|
+
\t \t4
|
136
|
+
\t\t1
|
137
|
+
\t \t2
|
138
|
+
\t \t3
|
139
|
+
\t \t4
|
140
|
+
\t\t1
|
141
|
+
\t \t2
|
142
|
+
\t \t3
|
143
|
+
\t \t4
|
144
|
+
}
|
145
|
+
|
146
|
+
result = %q{
|
147
|
+
0
|
148
|
+
1
|
149
|
+
2
|
150
|
+
3
|
151
|
+
4
|
152
|
+
1
|
153
|
+
2
|
154
|
+
3
|
155
|
+
4
|
156
|
+
1
|
157
|
+
2
|
158
|
+
3
|
159
|
+
4
|
160
|
+
1
|
161
|
+
2
|
162
|
+
3
|
163
|
+
4
|
164
|
+
}.strip
|
165
|
+
|
166
|
+
assert_html result, source
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|