slim 4.1.0 → 5.2.1
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 +4 -4
- data/.github/workflows/test.yml +107 -0
- data/.yardopts +1 -1
- data/CHANGES +44 -8
- data/Gemfile +18 -45
- data/LICENSE +1 -1
- data/README.jp.md +28 -41
- data/README.md +66 -43
- data/Rakefile +2 -9
- data/doc/jp/translator.md +1 -1
- data/doc/logic_less.md +1 -1
- data/doc/translator.md +1 -1
- data/lib/slim/code_attributes.rb +2 -1
- data/lib/slim/command.rb +2 -8
- data/lib/slim/controls.rb +1 -0
- data/lib/slim/do_inserter.rb +4 -3
- data/lib/slim/embedded.rb +17 -17
- data/lib/slim/end_inserter.rb +3 -2
- data/lib/slim/engine.rb +3 -0
- data/lib/slim/erb_converter.rb +1 -0
- data/lib/slim/filter.rb +1 -0
- data/lib/slim/grammar.rb +1 -0
- data/lib/slim/include.rb +1 -0
- data/lib/slim/interpolation.rb +1 -0
- data/lib/slim/logic_less/context.rb +6 -7
- data/lib/slim/logic_less/filter.rb +1 -0
- data/lib/slim/logic_less.rb +1 -0
- data/lib/slim/parser.rb +26 -39
- data/lib/slim/railtie.rb +19 -0
- data/lib/slim/smart/escaper.rb +1 -1
- data/lib/slim/smart/filter.rb +3 -2
- data/lib/slim/smart/parser.rb +4 -3
- data/lib/slim/smart.rb +1 -0
- data/lib/slim/splat/builder.rb +16 -8
- data/lib/slim/splat/filter.rb +6 -4
- data/lib/slim/template.rb +1 -14
- data/lib/slim/translator.rb +4 -3
- data/lib/slim/version.rb +2 -1
- data/lib/slim.rb +2 -0
- data/slim.gemspec +14 -5
- data/test/core/helper.rb +3 -11
- data/test/core/test_code_evaluation.rb +1 -0
- data/test/core/test_code_structure.rb +17 -0
- data/test/core/test_commands.rb +19 -22
- data/test/core/test_embedded_engines.rb +18 -14
- data/test/core/test_encoding.rb +2 -2
- data/test/core/test_erb_converter.rb +4 -6
- data/test/core/test_html_attributes.rb +8 -0
- data/test/core/test_html_structure.rb +54 -0
- data/test/core/test_pretty.rb +4 -7
- data/test/core/test_ruby_errors.rb +19 -0
- data/test/literate/TESTS.md +72 -22
- data/test/literate/helper.rb +1 -1
- data/test/literate/run.rb +3 -3
- data/test/logic_less/test_logic_less.rb +15 -0
- data/test/rails/app/controllers/slim_controller.rb +7 -1
- data/test/rails/app/views/layouts/application.html+testvariant.slim +10 -0
- data/test/rails/app/views/slim/attributes.html.slim +3 -0
- data/test/rails/app/views/slim/splat_with_delimiter.slim +1 -0
- data/test/rails/config/application.rb +1 -18
- data/test/rails/test/test_slim.rb +24 -12
- data/test/sinatra/helper.rb +0 -2
- metadata +27 -37
- data/.travis.yml +0 -38
- data/benchmarks/context.rb +0 -11
- data/benchmarks/profile-parser.rb +0 -10
- data/benchmarks/profile-render.rb +0 -12
- data/benchmarks/run-benchmarks.rb +0 -120
- data/benchmarks/run-diffbench.rb +0 -21
- data/benchmarks/view.erb +0 -25
- data/benchmarks/view.haml +0 -20
- data/benchmarks/view.slim +0 -19
- data/test/rails/config/initializers/secret_token.rb +0 -7
@@ -11,24 +11,26 @@ markdown:
|
|
11
11
|
|
12
12
|
#{1+2}
|
13
13
|
|
14
|
+
[#{1}](#{"#2"})
|
15
|
+
|
14
16
|
* one
|
15
17
|
* two
|
16
18
|
}
|
17
19
|
if ::Tilt['md'].name =~ /Redcarpet/
|
18
20
|
# redcarpet
|
19
|
-
assert_html "<h1>Header</h1>\n\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<ul>\n<li>one</li>\n<li>two</li>\n</ul>\n", source
|
21
|
+
assert_html "<h1>Header</h1>\n\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<p><a href=\"#2\">1</a></p>\n\n<ul>\n<li>one</li>\n<li>two</li>\n</ul>\n", source
|
20
22
|
elsif ::Tilt['md'].name =~ /RDiscount/
|
21
23
|
# rdiscount
|
22
|
-
assert_html "<h1>Header</h1>\n\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<ul>\n<li>one</li>\n<li>two</li>\n</ul>\n\n", source
|
24
|
+
assert_html "<h1>Header</h1>\n\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<p><a href=\"#2\">1</a></p>\n\n<ul>\n<li>one</li>\n<li>two</li>\n</ul>\n\n", source
|
23
25
|
else
|
24
26
|
# kramdown, :auto_ids by default
|
25
|
-
assert_html "<h1 id=\"header\">Header</h1>\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<ul>\n <li>one</li>\n <li>two</li>\n</ul>\n", source
|
27
|
+
assert_html "<h1 id=\"header\">Header</h1>\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<p><a href=\"#2\">1</a></p>\n\n<ul>\n <li>one</li>\n <li>two</li>\n</ul>\n", source
|
26
28
|
|
27
29
|
Slim::Embedded.with_options(markdown: {auto_ids: false}) do
|
28
|
-
assert_html "<h1>Header</h1>\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<ul>\n <li>one</li>\n <li>two</li>\n</ul>\n", source
|
30
|
+
assert_html "<h1>Header</h1>\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<p><a href=\"#2\">1</a></p>\n\n<ul>\n <li>one</li>\n <li>two</li>\n</ul>\n", source
|
29
31
|
end
|
30
32
|
|
31
|
-
assert_html "<h1 id=\"header\">Header</h1>\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<ul>\n <li>one</li>\n <li>two</li>\n</ul>\n", source
|
33
|
+
assert_html "<h1 id=\"header\">Header</h1>\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<p><a href=\"#2\">1</a></p>\n\n<ul>\n <li>one</li>\n <li>two</li>\n</ul>\n", source
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
@@ -37,7 +39,7 @@ markdown:
|
|
37
39
|
css:
|
38
40
|
h1 { color: blue }
|
39
41
|
}
|
40
|
-
assert_html "<style
|
42
|
+
assert_html "<style>h1 { color: blue }</style>", source
|
41
43
|
end
|
42
44
|
|
43
45
|
def test_render_with_css_empty_attributes
|
@@ -45,7 +47,7 @@ css:
|
|
45
47
|
css []:
|
46
48
|
h1 { color: blue }
|
47
49
|
}
|
48
|
-
assert_html "<style
|
50
|
+
assert_html "<style>h1 { color: blue }</style>", source
|
49
51
|
end
|
50
52
|
|
51
53
|
def test_render_with_css_attribute
|
@@ -53,7 +55,7 @@ css []:
|
|
53
55
|
css scoped = "true":
|
54
56
|
h1 { color: blue }
|
55
57
|
}
|
56
|
-
assert_html "<style scoped=\"true\"
|
58
|
+
assert_html "<style scoped=\"true\">h1 { color: blue }</style>", source
|
57
59
|
end
|
58
60
|
|
59
61
|
def test_render_with_css_multiple_attributes
|
@@ -61,7 +63,7 @@ css scoped = "true":
|
|
61
63
|
css class="myClass" scoped = "true" :
|
62
64
|
h1 { color: blue }
|
63
65
|
}
|
64
|
-
assert_html "<style class=\"myClass\" scoped=\"true\"
|
66
|
+
assert_html "<style class=\"myClass\" scoped=\"true\">h1 { color: blue }</style>", source
|
65
67
|
end
|
66
68
|
|
67
69
|
def test_render_with_javascript
|
@@ -163,13 +165,15 @@ ruby:
|
|
163
165
|
assert_html "foobar\n", source
|
164
166
|
end
|
165
167
|
|
168
|
+
# TODO: Reactivate sass tests
|
169
|
+
if false
|
166
170
|
def test_render_with_scss
|
167
171
|
source = %q{
|
168
172
|
scss:
|
169
173
|
$color: #f00;
|
170
174
|
body { color: $color; }
|
171
175
|
}
|
172
|
-
assert_html "<style
|
176
|
+
assert_html "<style>body{color:red}</style>", source
|
173
177
|
end
|
174
178
|
|
175
179
|
def test_render_with_scss_attribute
|
@@ -178,7 +182,7 @@ scss [class="myClass"]:
|
|
178
182
|
$color: #f00;
|
179
183
|
body { color: $color; }
|
180
184
|
}
|
181
|
-
assert_html "<style class=\"myClass\"
|
185
|
+
assert_html "<style class=\"myClass\">body{color:red}</style>", source
|
182
186
|
end
|
183
187
|
|
184
188
|
def test_render_with_sass
|
@@ -188,7 +192,7 @@ sass:
|
|
188
192
|
body
|
189
193
|
color: $color
|
190
194
|
}
|
191
|
-
assert_html "<style
|
195
|
+
assert_html "<style>body{color:red}</style>", source
|
192
196
|
end
|
193
197
|
|
194
198
|
def test_render_with_sass_attribute
|
@@ -198,9 +202,9 @@ sass [class="myClass"]:
|
|
198
202
|
body
|
199
203
|
color: $color
|
200
204
|
}
|
201
|
-
assert_html "<style class=\"myClass\"
|
205
|
+
assert_html "<style class=\"myClass\">body{color:red}</style>", source
|
202
206
|
end
|
203
|
-
|
207
|
+
end
|
204
208
|
|
205
209
|
def test_disabled_embedded_engine
|
206
210
|
source = %{
|
data/test/core/test_encoding.rb
CHANGED
@@ -8,10 +8,10 @@ class TestSlimEncoding < TestSlim
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_binary
|
11
|
-
source = "| \xFF\xFF"
|
11
|
+
source = "| \xFF\xFF".dup
|
12
12
|
source.force_encoding(Encoding::BINARY)
|
13
13
|
|
14
|
-
result = "\xFF\xFF"
|
14
|
+
result = "\xFF\xFF".dup
|
15
15
|
result.force_encoding(Encoding::BINARY)
|
16
16
|
|
17
17
|
out = render(source, default_encoding: 'binary')
|
@@ -21,9 +21,8 @@ html
|
|
21
21
|
/[if lt IE 9]
|
22
22
|
script src="old-ie1.js"
|
23
23
|
script src="old-ie2.js"
|
24
|
-
|
25
|
-
body
|
26
|
-
background-color: red
|
24
|
+
css:
|
25
|
+
body { background-color: red; }
|
27
26
|
body
|
28
27
|
#container
|
29
28
|
p Hello
|
@@ -51,9 +50,8 @@ multiline comment-->
|
|
51
50
|
</script><!--[if lt IE 9]>
|
52
51
|
<script src="old-ie1.js">
|
53
52
|
</script><script src="old-ie2.js">
|
54
|
-
</script><![endif]--><style
|
55
|
-
|
56
|
-
</style>
|
53
|
+
</script><![endif]--><style>
|
54
|
+
body { background-color: red; }</style>
|
57
55
|
</head><body>
|
58
56
|
<div id="container">
|
59
57
|
<p>Hello
|
@@ -116,6 +116,14 @@ option(selected class="clazz") Text
|
|
116
116
|
assert_html '<div class="alpha" data-a="alpha" data-b="beta" data-c-e="epsilon" data-c_d="gamma"></div>', source
|
117
117
|
end
|
118
118
|
|
119
|
+
def test_hyphenated_underscore_attribute
|
120
|
+
source = %{
|
121
|
+
.alpha data={a: 'alpha', b: 'beta', c_d: 'gamma', c: {e: 'epsilon'}}
|
122
|
+
}
|
123
|
+
|
124
|
+
assert_html '<div class="alpha" data-a="alpha" data-b="beta" data-c-d="gamma" data-c-e="epsilon"></div>', source, hyphen_underscore_attrs: true
|
125
|
+
end
|
126
|
+
|
119
127
|
def test_splat_without_content
|
120
128
|
source = %q{
|
121
129
|
*hash
|
@@ -115,6 +115,54 @@ h1#title This is my title
|
|
115
115
|
source, shortcut: {'^' => {tag: 'script', attr: 'data-binding', additional_attrs: { type: "application/json" }}}
|
116
116
|
end
|
117
117
|
|
118
|
+
def test_render_with_custom_lambda_shortcut
|
119
|
+
begin
|
120
|
+
Slim::Parser.options[:shortcut]['~'] = {attr: ->(v) {{class: "styled-#{v}", id: "id-#{v}"}}}
|
121
|
+
source = %q{
|
122
|
+
~foo Hello
|
123
|
+
}
|
124
|
+
assert_html '<div class="styled-foo" id="id-foo">Hello</div>', source
|
125
|
+
ensure
|
126
|
+
Slim::Parser.options[:shortcut].delete('~')
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_render_with_custom_lambda_shortcut_and_multiple_values
|
131
|
+
begin
|
132
|
+
Slim::Parser.options[:shortcut]['~'] = {attr: ->(v) {{class: "styled-#{v}"}}}
|
133
|
+
source = %q{
|
134
|
+
~foo~bar Hello
|
135
|
+
}
|
136
|
+
assert_html '<div class="styled-foo styled-bar">Hello</div>', source
|
137
|
+
ensure
|
138
|
+
Slim::Parser.options[:shortcut].delete('~')
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_render_with_custom_lambda_shortcut_and_existing_class
|
143
|
+
begin
|
144
|
+
Slim::Parser.options[:shortcut]['~'] = {attr: ->(v) {{class: "styled-#{v}"}}}
|
145
|
+
source = %q{
|
146
|
+
~foo.baz Hello
|
147
|
+
}
|
148
|
+
assert_html '<div class="styled-foo baz">Hello</div>', source
|
149
|
+
ensure
|
150
|
+
Slim::Parser.options[:shortcut].delete('~')
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_render_with_existing_class_and_custom_lambda_shortcut
|
155
|
+
begin
|
156
|
+
Slim::Parser.options[:shortcut]['~'] = {attr: ->(v) {{class: "styled-#{v}"}}}
|
157
|
+
source = %q{
|
158
|
+
.baz~foo Hello
|
159
|
+
}
|
160
|
+
assert_html '<div class="baz styled-foo">Hello</div>', source
|
161
|
+
ensure
|
162
|
+
Slim::Parser.options[:shortcut].delete('~')
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
118
166
|
def test_render_with_text_block
|
119
167
|
source = %q{
|
120
168
|
p
|
@@ -311,6 +359,12 @@ p[id="marvin" class="martian" data-info="Illudium Q-36"] = output_number
|
|
311
359
|
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', source
|
312
360
|
end
|
313
361
|
|
362
|
+
# Regression test for bug #796
|
363
|
+
def test_square_brackets_around_attributes_multiline_with_tabs
|
364
|
+
source = "div\n\tp[\n\t\tclass=\"martian\"\n\t]\n\tp Next line"
|
365
|
+
assert_html '<div><p class="martian"></p><p>Next line</p></div>', source
|
366
|
+
end
|
367
|
+
|
314
368
|
def test_parens_around_attributes_with_equal_sign_snug_to_right_paren
|
315
369
|
source = %q{
|
316
370
|
p(id="marvin" class="martian" data-info="Illudium Q-36")= output_number
|
data/test/core/test_pretty.rb
CHANGED
@@ -29,9 +29,8 @@ html
|
|
29
29
|
/[if lt IE 9]
|
30
30
|
script src="old-ie1.js"
|
31
31
|
script src="old-ie2.js"
|
32
|
-
|
33
|
-
body
|
34
|
-
background-color: red
|
32
|
+
css:
|
33
|
+
body { background-color: red; }
|
35
34
|
body
|
36
35
|
#container
|
37
36
|
p Hello
|
@@ -56,10 +55,8 @@ html
|
|
56
55
|
<script src="old-ie1.js"></script>
|
57
56
|
<script src="old-ie2.js"></script>
|
58
57
|
<![endif]-->
|
59
|
-
<style
|
60
|
-
body {
|
61
|
-
background-color: red;
|
62
|
-
}
|
58
|
+
<style>
|
59
|
+
body { background-color: red; }
|
63
60
|
</style>
|
64
61
|
</head>
|
65
62
|
<body>
|
@@ -106,6 +106,25 @@ ruby:
|
|
106
106
|
assert_ruby_error NameError,"(__TEMPLATE__):4", source
|
107
107
|
end
|
108
108
|
|
109
|
+
def test_embedded_ruby3
|
110
|
+
source = %q{
|
111
|
+
h1 before
|
112
|
+
ruby:
|
113
|
+
a = 1
|
114
|
+
|
115
|
+
h1 between
|
116
|
+
ruby:
|
117
|
+
b = a + 1
|
118
|
+
|
119
|
+
unknown_ruby_method
|
120
|
+
|
121
|
+
c = 3
|
122
|
+
h1 third
|
123
|
+
}
|
124
|
+
|
125
|
+
assert_ruby_error NameError,"(__TEMPLATE__):10", source
|
126
|
+
end
|
127
|
+
|
109
128
|
def test_embedded_markdown
|
110
129
|
source = %q{
|
111
130
|
markdown:
|
data/test/literate/TESTS.md
CHANGED
@@ -27,6 +27,22 @@ renders as
|
|
27
27
|
Text block
|
28
28
|
~~~
|
29
29
|
|
30
|
+
You can add leading or trailing white space with the `<` and `>` markers:
|
31
|
+
|
32
|
+
~~~ slim
|
33
|
+
|< Text with leading whitespace.
|
34
|
+
| Text with leading whitespace.
|
35
|
+
|> Text with trailing whitespace.
|
36
|
+
|<> Text with both leading and trailing whitespace.
|
37
|
+
~~~
|
38
|
+
|
39
|
+
renders as
|
40
|
+
|
41
|
+
~~~ html
|
42
|
+
Text with leading whitespace. Text with leading whitespace.Text with trailing whitespace. Text with both leading and trailing whitespace.
|
43
|
+
~~~
|
44
|
+
|
45
|
+
|
30
46
|
Multiple lines can be indented beneath the first text line.
|
31
47
|
|
32
48
|
~~~ slim
|
@@ -77,6 +93,30 @@ Text
|
|
77
93
|
lines
|
78
94
|
~~~
|
79
95
|
|
96
|
+
~~~ slim
|
97
|
+
|><
|
98
|
+
|
99
|
+
Text
|
100
|
+
block
|
101
|
+
|
102
|
+
with
|
103
|
+
|
104
|
+
multiple
|
105
|
+
lines
|
106
|
+
~~~
|
107
|
+
|
108
|
+
renders as
|
109
|
+
|
110
|
+
~~~ html
|
111
|
+
Text
|
112
|
+
block
|
113
|
+
|
114
|
+
with
|
115
|
+
|
116
|
+
multiple
|
117
|
+
lines
|
118
|
+
~~~
|
119
|
+
|
80
120
|
You can nest text blocks beneath tags.
|
81
121
|
|
82
122
|
~~~ slim
|
@@ -95,13 +135,23 @@ renders as
|
|
95
135
|
You can embed html code in the text which is not escaped.
|
96
136
|
|
97
137
|
~~~ slim
|
98
|
-
| <a href="http://slim-
|
138
|
+
| <a href="http://github.com/slim-template/slim">github.com/slim-template/slim</a>
|
139
|
+
~~~
|
140
|
+
|
141
|
+
renders as
|
142
|
+
|
143
|
+
~~~ html
|
144
|
+
<a href="http://github.com/slim-template/slim">github.com/slim-template/slim</a>
|
145
|
+
~~~
|
146
|
+
|
147
|
+
~~~ slim
|
148
|
+
|<a href="http://github.com/slim-template/slim">github.com/slim-template/slim</a>
|
99
149
|
~~~
|
100
150
|
|
101
151
|
renders as
|
102
152
|
|
103
153
|
~~~ html
|
104
|
-
<a href="http://slim-
|
154
|
+
<a href="http://github.com/slim-template/slim">github.com/slim-template/slim</a>
|
105
155
|
~~~
|
106
156
|
|
107
157
|
### Text with trailing white space `'`
|
@@ -122,13 +172,13 @@ This is especially useful if you use tags behind a text block.
|
|
122
172
|
|
123
173
|
~~~ slim
|
124
174
|
' Link to
|
125
|
-
a href="http://slim-
|
175
|
+
a href="http://github.com/slim-template/slim" github.com/slim-template/slim
|
126
176
|
~~~
|
127
177
|
|
128
178
|
renders as
|
129
179
|
|
130
180
|
~~~ html
|
131
|
-
Link to <a href="http://slim-
|
181
|
+
Link to <a href="http://github.com/slim-template/slim">github.com/slim-template/slim</a>
|
132
182
|
~~~
|
133
183
|
|
134
184
|
Multiple lines can be indented beneath the first text line.
|
@@ -186,13 +236,13 @@ lines
|
|
186
236
|
HTML can be written directly.
|
187
237
|
|
188
238
|
~~~ slim
|
189
|
-
<a href="http://slim-
|
239
|
+
<a href="http://github.com/slim-template/slim">github.com/slim-template/slim</a>
|
190
240
|
~~~
|
191
241
|
|
192
242
|
renders as
|
193
243
|
|
194
244
|
~~~ html
|
195
|
-
<a href="http://slim-
|
245
|
+
<a href="http://github.com/slim-template/slim">github.com/slim-template/slim</a>
|
196
246
|
~~~
|
197
247
|
|
198
248
|
HTML tags allow nested blocks inside.
|
@@ -800,31 +850,31 @@ If a delimiter makes the syntax more readable for you, you can use the character
|
|
800
850
|
|
801
851
|
~~~ slim
|
802
852
|
li
|
803
|
-
a(href="http://slim-
|
853
|
+
a(href="http://github.com/slim-template/slim" class="important") Link
|
804
854
|
li
|
805
|
-
a[href="http://slim-
|
855
|
+
a[href="http://github.com/slim-template/slim" class="important"] Link
|
806
856
|
li
|
807
|
-
a{href="http://slim-
|
857
|
+
a{href="http://github.com/slim-template/slim" class="important"} Link
|
808
858
|
~~~
|
809
859
|
|
810
860
|
renders as
|
811
861
|
|
812
862
|
~~~ html
|
813
863
|
<li>
|
814
|
-
<a class="important" href="http://slim-
|
864
|
+
<a class="important" href="http://github.com/slim-template/slim">Link</a>
|
815
865
|
</li>
|
816
866
|
<li>
|
817
|
-
<a class="important" href="http://slim-
|
867
|
+
<a class="important" href="http://github.com/slim-template/slim">Link</a>
|
818
868
|
</li>
|
819
869
|
<li>
|
820
|
-
<a class="important" href="http://slim-
|
870
|
+
<a class="important" href="http://github.com/slim-template/slim">Link</a>
|
821
871
|
</li>
|
822
872
|
~~~
|
823
873
|
|
824
874
|
If you wrap the attributes, you can spread them across multiple lines:
|
825
875
|
|
826
876
|
~~~ slim
|
827
|
-
a(href="http://slim-
|
877
|
+
a(href="http://github.com/slim-template/slim"
|
828
878
|
|
829
879
|
class="important") Link
|
830
880
|
~~~
|
@@ -832,7 +882,7 @@ a(href="http://slim-lang.com"
|
|
832
882
|
renders as
|
833
883
|
|
834
884
|
~~~ html
|
835
|
-
<a class="important" href="http://slim-
|
885
|
+
<a class="important" href="http://github.com/slim-template/slim">Link</a>
|
836
886
|
~~~
|
837
887
|
|
838
888
|
~~~ slim
|
@@ -872,19 +922,19 @@ renders as
|
|
872
922
|
You can use single or double quotes for simple text attributes.
|
873
923
|
|
874
924
|
~~~ slim
|
875
|
-
a href="http://slim-
|
925
|
+
a href="http://github.com/slim-template/slim" title='Slim Homepage' Goto the Slim homepage
|
876
926
|
~~~
|
877
927
|
|
878
928
|
renders as
|
879
929
|
|
880
930
|
~~~ html
|
881
|
-
<a href="http://slim-
|
931
|
+
<a href="http://github.com/slim-template/slim" title="Slim Homepage">Goto the Slim homepage</a>
|
882
932
|
~~~
|
883
933
|
|
884
934
|
You can use text interpolation in the quoted attributes:
|
885
935
|
|
886
936
|
~~~ slim
|
887
|
-
- url='slim-
|
937
|
+
- url='github.com/slim-template/slim'
|
888
938
|
a href="http://#{url}" Goto the #{url}
|
889
939
|
a href="{"test"}" Test of quoted text in braces
|
890
940
|
~~~
|
@@ -892,7 +942,7 @@ a href="{"test"}" Test of quoted text in braces
|
|
892
942
|
renders as
|
893
943
|
|
894
944
|
~~~ html
|
895
|
-
<a href="http://slim-
|
945
|
+
<a href="http://github.com/slim-template/slim">Goto the github.com/slim-template/slim</a><a href="{"test"}">Test of quoted text in braces</a>
|
896
946
|
~~~
|
897
947
|
|
898
948
|
The attribute value will be escaped by default. Use == if you want to disable escaping in the attribute.
|
@@ -1040,13 +1090,13 @@ You can configure attributes to be merged if multiple are given (See option `:me
|
|
1040
1090
|
this is done for class attributes with the white space as delimiter.
|
1041
1091
|
|
1042
1092
|
~~~ slim
|
1043
|
-
a.menu class="highlight" href="http://
|
1093
|
+
a.menu class="highlight" href="http://github.com/slim-template/slim/" github.com/slim-template/slim
|
1044
1094
|
~~~
|
1045
1095
|
|
1046
1096
|
renders as
|
1047
1097
|
|
1048
1098
|
~~~ html
|
1049
|
-
<a class="menu highlight" href="http://
|
1099
|
+
<a class="menu highlight" href="http://github.com/slim-template/slim/">github.com/slim-template/slim</a>
|
1050
1100
|
~~~
|
1051
1101
|
|
1052
1102
|
You can also use an `Array` as attribute value and the array elements will be merged using the delimiter.
|
@@ -1074,7 +1124,7 @@ with the :tag key.
|
|
1074
1124
|
~~~ slim
|
1075
1125
|
ruby:
|
1076
1126
|
def self.a_unless_current
|
1077
|
-
@page_current ? {tag: 'span'} : {tag: 'a', href: 'http://
|
1127
|
+
@page_current ? {tag: 'span'} : {tag: 'a', href: 'http://github.com/slim-template/slim/'}
|
1078
1128
|
end
|
1079
1129
|
- @page_current = true
|
1080
1130
|
*a_unless_current Link
|
@@ -1085,7 +1135,7 @@ ruby:
|
|
1085
1135
|
renders as
|
1086
1136
|
|
1087
1137
|
~~~ html
|
1088
|
-
<span>Link</span><a href="http://
|
1138
|
+
<span>Link</span><a href="http://github.com/slim-template/slim/">Link</a>
|
1089
1139
|
~~~
|
1090
1140
|
|
1091
1141
|
### Shortcuts
|
data/test/literate/helper.rb
CHANGED
@@ -8,7 +8,7 @@ Slim::Engine.after Slim::Parser, Temple::Filters::Validator, grammar: Slim::Gra
|
|
8
8
|
Slim::Engine.before :Pretty, Temple::Filters::Validator
|
9
9
|
Slim::Engine.set_options tr: false, logic_less: false
|
10
10
|
|
11
|
-
class
|
11
|
+
class Minitest::Spec
|
12
12
|
def render(source, options = {}, &block)
|
13
13
|
Slim::Template.new(options) { source }.render(self, &block)
|
14
14
|
end
|
data/test/literate/run.rb
CHANGED
@@ -63,11 +63,11 @@ class LiterateTest < Temple::Engine
|
|
63
63
|
def on_html(code)
|
64
64
|
raise Temple::FilterError, 'Html block must be preceded by slim block' unless @in_testcase
|
65
65
|
@in_testcase = false
|
66
|
-
result = " html = #{code.inspect}\n"
|
66
|
+
result = " html = #{code.inspect}\n".dup
|
67
67
|
if @opts.empty?
|
68
|
-
result << " render(slim).must_equal html\nend\n"
|
68
|
+
result << " _(render(slim)).must_equal html\nend\n"
|
69
69
|
else
|
70
|
-
result << " options = #{@opts.inspect}\n render(slim, options).must_equal html\nend\n"
|
70
|
+
result << " options = #{@opts.inspect}\n _(render(slim, options)).must_equal html\nend\n"
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -312,4 +312,19 @@ div
|
|
312
312
|
'This is the menu'
|
313
313
|
end
|
314
314
|
end
|
315
|
+
|
316
|
+
def test_render_parent_lambda
|
317
|
+
source = %q{
|
318
|
+
- list
|
319
|
+
== fn
|
320
|
+
p = string
|
321
|
+
}
|
322
|
+
|
323
|
+
assert_html '<fn><p>str</p></fn><fn><p>str</p></fn><fn><p>str</p></fn>',
|
324
|
+
source, scope: {
|
325
|
+
fn: ->(&block) { "<fn>#{block.call}</fn>" },
|
326
|
+
list: [ "item1", "item2", "item3" ],
|
327
|
+
string: "str"
|
328
|
+
}
|
329
|
+
end
|
315
330
|
end
|
@@ -26,11 +26,17 @@ class SlimController < ApplicationController
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def thread_options
|
29
|
-
|
29
|
+
default_shortcut = {'#' => {attr: 'id'}, '.' => {attr: 'class'} }
|
30
|
+
Slim::Engine.with_options(shortcut: default_shortcut.merge({'@' => { attr: params[:attr] }})) do
|
30
31
|
render
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
35
|
+
def variant
|
36
|
+
request.variant = :testvariant
|
37
|
+
render :normal
|
38
|
+
end
|
39
|
+
|
34
40
|
def content_for
|
35
41
|
@hello = "Hello Slim!"
|
36
42
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
.cute *{class: "nice"} Hello
|
@@ -5,10 +5,8 @@ require 'action_controller/railtie'
|
|
5
5
|
require 'action_view/railtie'
|
6
6
|
#require 'active_record/railtie'
|
7
7
|
#require 'action_mailer/railtie'
|
8
|
-
require 'sprockets/railtie'
|
9
|
-
|
8
|
+
#require 'sprockets/railtie'
|
10
9
|
require 'slim'
|
11
|
-
require 'slim-rails/register_engine'
|
12
10
|
|
13
11
|
module Dummy
|
14
12
|
class Application < Rails::Application
|
@@ -42,20 +40,5 @@ module Dummy
|
|
42
40
|
|
43
41
|
# Configure sensitive parameters which will be filtered from the log file.
|
44
42
|
config.filter_parameters += [:password]
|
45
|
-
|
46
|
-
# From slim-rails fix for "ActionView::Template::Error: Unknown line indicator"
|
47
|
-
# https://github.com/slim-template/slim-rails/blob/991589ea5648e5e896781e68912bc51beaf4102a/lib/slim-rails/register_engine.rb
|
48
|
-
if config.respond_to?(:assets)
|
49
|
-
config.assets.configure do |env|
|
50
|
-
if env.respond_to?(:register_transformer) && Sprockets::VERSION.to_i > 3
|
51
|
-
env.register_mime_type 'text/slim', extensions: ['.slim', '.slim.html']
|
52
|
-
env.register_transformer 'text/slim', 'text/html', Slim::Rails::RegisterEngine::Transformer
|
53
|
-
elsif env.respond_to?(:register_engine)
|
54
|
-
args = ['.slim', Slim::Template]
|
55
|
-
args << { silence_deprecation: true } if Sprockets::VERSION.start_with?('3')
|
56
|
-
env.register_engine(*args)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
43
|
end
|
61
44
|
end
|