slim 2.0.3 → 2.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 +4 -4
- data/.travis.yml +7 -8
- data/.yardopts +1 -1
- data/CHANGES +23 -0
- data/Gemfile +2 -1
- data/LICENSE +1 -1
- data/README.jp.md +497 -268
- data/README.md +505 -278
- data/Rakefile +14 -2
- data/benchmarks/view.haml +2 -2
- data/doc/include.md +20 -0
- data/doc/jp/include.md +20 -0
- data/doc/jp/logic_less.md +137 -0
- data/doc/jp/smart.md +102 -0
- data/doc/jp/translator.md +28 -0
- data/doc/smart.md +102 -0
- data/lib/slim/command.rb +8 -2
- data/lib/slim/controls.rb +4 -3
- data/lib/slim/do_inserter.rb +1 -1
- data/lib/slim/embedded.rb +26 -22
- data/lib/slim/end_inserter.rb +1 -1
- data/lib/slim/engine.rb +3 -2
- data/lib/slim/filter.rb +2 -2
- data/lib/slim/grammar.rb +3 -1
- data/lib/slim/include.rb +54 -0
- data/lib/slim/interpolation.rb +1 -1
- data/lib/slim/parser.rb +61 -46
- data/lib/slim/smart.rb +8 -0
- data/lib/slim/smart/escaper.rb +42 -0
- data/lib/slim/smart/filter.rb +96 -0
- data/lib/slim/smart/parser.rb +33 -0
- data/lib/slim/splat/builder.rb +3 -3
- data/lib/slim/splat/filter.rb +2 -2
- data/lib/slim/translator.rb +2 -2
- data/lib/slim/version.rb +1 -1
- data/slim.gemspec +1 -1
- data/test/core/helper.rb +5 -3
- data/test/core/test_code_blocks.rb +11 -0
- data/test/core/test_code_escaping.rb +14 -4
- data/test/core/test_embedded_engines.rb +26 -0
- data/test/core/test_html_structure.rb +39 -0
- data/test/core/test_parser_errors.rb +8 -25
- data/test/core/test_pretty.rb +15 -0
- data/test/core/test_ruby_errors.rb +0 -10
- data/test/include/files/recursive.slim +1 -0
- data/test/include/files/slimfile.slim +3 -0
- data/test/include/files/subdir/test.slim +1 -0
- data/test/include/files/textfile +1 -0
- data/test/include/test_include.rb +23 -0
- data/test/literate/TESTS.md +17 -2
- data/test/rails/test/test_slim.rb +1 -1
- data/test/smart/test_smart_text.rb +300 -0
- data/test/translator/test_translator.rb +7 -6
- metadata +22 -4
data/test/core/test_pretty.rb
CHANGED
@@ -98,4 +98,19 @@ html
|
|
98
98
|
|
99
99
|
assert_html result, source, :scope => self, :locals => {:body => body, :content => content }
|
100
100
|
end
|
101
|
+
|
102
|
+
def test_correct_line_number
|
103
|
+
source = %q{
|
104
|
+
html
|
105
|
+
head
|
106
|
+
body
|
107
|
+
p Slim
|
108
|
+
= ''
|
109
|
+
= ''
|
110
|
+
= ''
|
111
|
+
= unknown_ruby_method
|
112
|
+
}
|
113
|
+
|
114
|
+
assert_ruby_error NameError,"(__TEMPLATE__):9", source
|
115
|
+
end
|
101
116
|
end
|
@@ -173,16 +173,6 @@ p
|
|
173
173
|
assert_ruby_syntax_error "(__TEMPLATE__):3", source
|
174
174
|
end
|
175
175
|
|
176
|
-
def test_invalid_embedded_engine
|
177
|
-
source = %q{
|
178
|
-
p
|
179
|
-
embed_unknown:
|
180
|
-
1+1
|
181
|
-
}
|
182
|
-
|
183
|
-
assert_runtime_error 'Embedded engine embed_unknown not found', source
|
184
|
-
end
|
185
|
-
|
186
176
|
def test_explicit_end
|
187
177
|
source = %q{
|
188
178
|
div
|
@@ -0,0 +1 @@
|
|
1
|
+
| rec
|
@@ -0,0 +1 @@
|
|
1
|
+
| subdir
|
@@ -0,0 +1 @@
|
|
1
|
+
1+2=#{1+2}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'slim/include'
|
3
|
+
|
4
|
+
class TestSlimInclude < TestSlim
|
5
|
+
def test_include
|
6
|
+
source = %q{
|
7
|
+
a: include slimfile
|
8
|
+
b: include textfile
|
9
|
+
c: include slimfile.slim
|
10
|
+
d: include subdir/test
|
11
|
+
}
|
12
|
+
assert_html '<a>slim1recslim2</a><b>1+2=3</b><c>slim1recslim2</c><d>subdir</d>', source, :include_dirs => [File.expand_path('files', File.dirname(__FILE__))]
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_include_with_newline
|
16
|
+
source = %q{
|
17
|
+
a: include slimfile
|
18
|
+
|
19
|
+
.content
|
20
|
+
}
|
21
|
+
assert_html '<a>slim1recslim2</a><div class="content"></div>', source, :include_dirs => [File.expand_path('files', File.dirname(__FILE__))]
|
22
|
+
end
|
23
|
+
end
|
data/test/literate/TESTS.md
CHANGED
@@ -911,12 +911,13 @@ You can use text interpolation in the quoted attributes:
|
|
911
911
|
~~~ slim
|
912
912
|
- url='slim-lang.com'
|
913
913
|
a href="http://#{url}" Goto the #{url}
|
914
|
+
a href="{"test"}" Test of quoted text in braces
|
914
915
|
~~~
|
915
916
|
|
916
917
|
renders as
|
917
918
|
|
918
919
|
~~~ html
|
919
|
-
<a href="http://slim-lang.com">Goto the slim-lang.com</a>
|
920
|
+
<a href="http://slim-lang.com">Goto the slim-lang.com</a><a href="{"test"}">Test of quoted text in braces</a>
|
920
921
|
~~~
|
921
922
|
|
922
923
|
The attribute value will be escaped by default. Use == if you want to disable escaping in the attribute.
|
@@ -939,7 +940,21 @@ renders as
|
|
939
940
|
</li>
|
940
941
|
~~~
|
941
942
|
|
942
|
-
You can
|
943
|
+
You can use newlines in quoted attributes
|
944
|
+
|
945
|
+
~~~ slim
|
946
|
+
a data-title="help" data-content="extremely long help text that goes on
|
947
|
+
and one and one and then starts over...." Link
|
948
|
+
~~~
|
949
|
+
|
950
|
+
renders as
|
951
|
+
|
952
|
+
~~~ html
|
953
|
+
<a data-content="extremely long help text that goes on
|
954
|
+
and one and one and then starts over...." data-title="help">Link</a>
|
955
|
+
~~~
|
956
|
+
|
957
|
+
You can break quoted attributes with an backslash `\`
|
943
958
|
|
944
959
|
~~~ slim
|
945
960
|
a data-title="help" data-content="extremely long help text that goes on\
|
@@ -89,4 +89,4 @@ class TestSlim < ActionDispatch::IntegrationTest
|
|
89
89
|
expected = "<!DOCTYPE html><html><head><title>Dummy</title></head><body>#{options[:heading]}<div class=\"content\">#{expected}</div></body></html>" unless options[:skip_layout]
|
90
90
|
assert_equal expected, @response.body
|
91
91
|
end
|
92
|
-
end
|
92
|
+
end
|
@@ -0,0 +1,300 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
require 'slim/smart'
|
5
|
+
|
6
|
+
class TestSlimSmartText < TestSlim
|
7
|
+
|
8
|
+
def test_explicit_smart_text_recognition
|
9
|
+
source = %q{
|
10
|
+
>
|
11
|
+
a
|
12
|
+
>
|
13
|
+
b
|
14
|
+
|
15
|
+
>
|
16
|
+
|
17
|
+
c
|
18
|
+
>
|
19
|
+
|
20
|
+
d
|
21
|
+
|
22
|
+
> e
|
23
|
+
f
|
24
|
+
> g
|
25
|
+
h
|
26
|
+
i
|
27
|
+
}
|
28
|
+
|
29
|
+
result = %q{a
|
30
|
+
b
|
31
|
+
c
|
32
|
+
d
|
33
|
+
e
|
34
|
+
<f></f>
|
35
|
+
g
|
36
|
+
h
|
37
|
+
<i></i>}
|
38
|
+
|
39
|
+
assert_html result, source
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_implicit_smart_text_recognition
|
43
|
+
source = %q{
|
44
|
+
p
|
45
|
+
A
|
46
|
+
p
|
47
|
+
B
|
48
|
+
|
49
|
+
p
|
50
|
+
|
51
|
+
C
|
52
|
+
p
|
53
|
+
|
54
|
+
D
|
55
|
+
|
56
|
+
p E
|
57
|
+
F
|
58
|
+
p G
|
59
|
+
H
|
60
|
+
I
|
61
|
+
}
|
62
|
+
|
63
|
+
result = %q{<p>A</p><p>B</p><p>C</p><p>D</p><p>E</p>
|
64
|
+
F
|
65
|
+
<p>G
|
66
|
+
H</p>
|
67
|
+
I}
|
68
|
+
|
69
|
+
assert_html result, source
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_multi_line_smart_text
|
73
|
+
source = %q{
|
74
|
+
p
|
75
|
+
First line.
|
76
|
+
Second line.
|
77
|
+
Third line
|
78
|
+
with a continuation
|
79
|
+
and one more.
|
80
|
+
Fourth line.
|
81
|
+
}
|
82
|
+
|
83
|
+
result = %q{<p>First line.
|
84
|
+
Second line.
|
85
|
+
Third line
|
86
|
+
with a continuation
|
87
|
+
and one more.
|
88
|
+
Fourth line.</p>}
|
89
|
+
|
90
|
+
assert_html result, source
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_smart_text_escaping
|
94
|
+
source = %q{
|
95
|
+
| Not escaped <&>.
|
96
|
+
p Escaped <&>.
|
97
|
+
p
|
98
|
+
Escaped <&>.
|
99
|
+
> Escaped <&>.
|
100
|
+
Protected & < > © Á.
|
101
|
+
Protected  ÿ.
|
102
|
+
Escaped &#xx; f; &;.
|
103
|
+
}
|
104
|
+
|
105
|
+
result = %q{Not escaped <&>.<p>Escaped <&>.</p><p>Escaped <&>.
|
106
|
+
Escaped <&>.
|
107
|
+
Protected & < > © Á.
|
108
|
+
Protected  ÿ.
|
109
|
+
Escaped &#xx; &#1f; &;.</p>}
|
110
|
+
|
111
|
+
assert_html result, source
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_smart_text_disabled_escaping
|
115
|
+
Slim::Engine.with_options( :smart_text_escaping => false ) do
|
116
|
+
source = %q{
|
117
|
+
p Not escaped <&>.
|
118
|
+
| Not escaped <&>.
|
119
|
+
p
|
120
|
+
Not escaped <&>.
|
121
|
+
> Not escaped <&>.
|
122
|
+
Not escaped & < > © Á.
|
123
|
+
Not escaped  ÿ.
|
124
|
+
Not escaped &#xx; f; &;.
|
125
|
+
}
|
126
|
+
|
127
|
+
result = %q{<p>Not escaped <&>.</p>Not escaped <&>.<p>Not escaped <&>.
|
128
|
+
Not escaped <&>.
|
129
|
+
Not escaped & < > © Á.
|
130
|
+
Not escaped  ÿ.
|
131
|
+
Not escaped &#xx; f; &;.</p>}
|
132
|
+
|
133
|
+
assert_html result, source
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_smart_text_in_tag_escaping
|
138
|
+
source = %q{
|
139
|
+
p Escaped <&>.
|
140
|
+
Protected & < > © Á.
|
141
|
+
Protected  ÿ.
|
142
|
+
Escaped &#xx; f; &;.
|
143
|
+
}
|
144
|
+
|
145
|
+
result = %q{<p>Escaped <&>.
|
146
|
+
Protected & < > © Á.
|
147
|
+
Protected  ÿ.
|
148
|
+
Escaped &#xx; &#1f; &;.</p>}
|
149
|
+
|
150
|
+
assert_html result, source
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_smart_text_mixed_with_tags
|
154
|
+
source = %q{
|
155
|
+
p
|
156
|
+
Text
|
157
|
+
br
|
158
|
+
>is
|
159
|
+
strong really
|
160
|
+
> recognized.
|
161
|
+
|
162
|
+
More
|
163
|
+
b text
|
164
|
+
.
|
165
|
+
|
166
|
+
And
|
167
|
+
i more
|
168
|
+
...
|
169
|
+
|
170
|
+
span Really
|
171
|
+
?!?
|
172
|
+
|
173
|
+
.bold Really
|
174
|
+
!!!
|
175
|
+
|
176
|
+
#id
|
177
|
+
#{'Good'}
|
178
|
+
!
|
179
|
+
}
|
180
|
+
|
181
|
+
result = %q{<p>Text
|
182
|
+
<br />
|
183
|
+
is
|
184
|
+
<strong>really</strong>
|
185
|
+
recognized.
|
186
|
+
More
|
187
|
+
<b>text</b>.
|
188
|
+
And
|
189
|
+
<i>more</i>...
|
190
|
+
<span>Really</span>?!?
|
191
|
+
<div class="bold">Really</div>!!!
|
192
|
+
<div id="id">Good</div>!</p>}
|
193
|
+
|
194
|
+
assert_html result, source
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_smart_text_mixed_with_links
|
198
|
+
source = %q{
|
199
|
+
p
|
200
|
+
Text with
|
201
|
+
a href="#1" link
|
202
|
+
.
|
203
|
+
|
204
|
+
Text with
|
205
|
+
a href="#2" another
|
206
|
+
link
|
207
|
+
> to somewhere else.
|
208
|
+
|
209
|
+
a href="#3"
|
210
|
+
This link
|
211
|
+
> goes
|
212
|
+
elsewhere.
|
213
|
+
|
214
|
+
See (
|
215
|
+
a href="#4" link
|
216
|
+
)?
|
217
|
+
}
|
218
|
+
|
219
|
+
result = %q{<p>Text with
|
220
|
+
<a href="#1">link</a>.
|
221
|
+
Text with
|
222
|
+
<a href="#2">another
|
223
|
+
link</a>
|
224
|
+
to somewhere else.
|
225
|
+
<a href="#3">This link</a>
|
226
|
+
goes
|
227
|
+
elsewhere.
|
228
|
+
See (<a href="#4">link</a>)?</p>}
|
229
|
+
|
230
|
+
assert_html result, source
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_smart_text_mixed_with_code
|
234
|
+
source = %q{
|
235
|
+
p
|
236
|
+
Try a list
|
237
|
+
ul
|
238
|
+
- 2.times do |i|
|
239
|
+
li
|
240
|
+
Item: #{i}
|
241
|
+
> which stops
|
242
|
+
b here
|
243
|
+
. Right?
|
244
|
+
}
|
245
|
+
|
246
|
+
result = %q{<p>Try a list
|
247
|
+
<ul><li>Item: 0</li><li>Item: 1</li></ul>
|
248
|
+
which stops
|
249
|
+
<b>here</b>. Right?</p>}
|
250
|
+
|
251
|
+
assert_html result, source
|
252
|
+
end
|
253
|
+
|
254
|
+
# Without unicode support, we can't distinguish uppercase and lowercase
|
255
|
+
# unicode characters reliably. So we only test the basic text, not tag names.
|
256
|
+
def test_basic_unicode_smart_text
|
257
|
+
source = %q{
|
258
|
+
p
|
259
|
+
是
|
260
|
+
čip
|
261
|
+
Čip
|
262
|
+
Žůžo
|
263
|
+
šíp
|
264
|
+
}
|
265
|
+
|
266
|
+
result = %q{<p>是
|
267
|
+
čip
|
268
|
+
Čip
|
269
|
+
Žůžo
|
270
|
+
šíp</p>}
|
271
|
+
|
272
|
+
assert_html result, source
|
273
|
+
end
|
274
|
+
|
275
|
+
if ''.respond_to?(:encoding)
|
276
|
+
|
277
|
+
def test_unicode_smart_text
|
278
|
+
|
279
|
+
source = %q{
|
280
|
+
p
|
281
|
+
是
|
282
|
+
čip
|
283
|
+
Čip
|
284
|
+
Žůžo
|
285
|
+
šíp
|
286
|
+
.řek
|
287
|
+
.
|
288
|
+
}
|
289
|
+
|
290
|
+
result = %q{<p>是
|
291
|
+
čip
|
292
|
+
Čip
|
293
|
+
Žůžo
|
294
|
+
šíp
|
295
|
+
<div class="řek">.</div></p>}
|
296
|
+
|
297
|
+
assert_html result, source
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
@@ -26,18 +26,19 @@ markdown:
|
|
26
26
|
* one
|
27
27
|
* two
|
28
28
|
}
|
29
|
-
|
30
|
-
|
29
|
+
|
30
|
+
case Tilt['md'].name.downcase
|
31
|
+
when /redcarpet/
|
31
32
|
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, :tr_mode => :dynamic
|
32
33
|
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, :tr_mode => :static
|
33
|
-
|
34
|
-
# rdiscount
|
34
|
+
when /rdiscount/
|
35
35
|
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, :tr_mode => :dynamic
|
36
36
|
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, :tr_mode => :static
|
37
|
-
|
38
|
-
# kramdown
|
37
|
+
when /kramdown/
|
39
38
|
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, :tr_mode => :dynamic
|
40
39
|
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, :tr_mode => :static
|
40
|
+
else
|
41
|
+
raise "Missing test for #{Tilt['md']}"
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Mendler
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-10-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: temple
|
@@ -18,14 +18,14 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.6.
|
21
|
+
version: 0.6.9
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: 0.6.
|
28
|
+
version: 0.6.9
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: tilt
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,7 +75,13 @@ files:
|
|
75
75
|
- benchmarks/view.haml
|
76
76
|
- benchmarks/view.slim
|
77
77
|
- bin/slimrb
|
78
|
+
- doc/include.md
|
79
|
+
- doc/jp/include.md
|
80
|
+
- doc/jp/logic_less.md
|
81
|
+
- doc/jp/smart.md
|
82
|
+
- doc/jp/translator.md
|
78
83
|
- doc/logic_less.md
|
84
|
+
- doc/smart.md
|
79
85
|
- doc/translator.md
|
80
86
|
- lib/slim.rb
|
81
87
|
- lib/slim/code_attributes.rb
|
@@ -88,11 +94,16 @@ files:
|
|
88
94
|
- lib/slim/erb_converter.rb
|
89
95
|
- lib/slim/filter.rb
|
90
96
|
- lib/slim/grammar.rb
|
97
|
+
- lib/slim/include.rb
|
91
98
|
- lib/slim/interpolation.rb
|
92
99
|
- lib/slim/logic_less.rb
|
93
100
|
- lib/slim/logic_less/context.rb
|
94
101
|
- lib/slim/logic_less/filter.rb
|
95
102
|
- lib/slim/parser.rb
|
103
|
+
- lib/slim/smart.rb
|
104
|
+
- lib/slim/smart/escaper.rb
|
105
|
+
- lib/slim/smart/filter.rb
|
106
|
+
- lib/slim/smart/parser.rb
|
96
107
|
- lib/slim/splat/builder.rb
|
97
108
|
- lib/slim/splat/filter.rb
|
98
109
|
- lib/slim/template.rb
|
@@ -119,6 +130,11 @@ files:
|
|
119
130
|
- test/core/test_text_interpolation.rb
|
120
131
|
- test/core/test_thread_options.rb
|
121
132
|
- test/core/test_unicode.rb
|
133
|
+
- test/include/files/recursive.slim
|
134
|
+
- test/include/files/slimfile.slim
|
135
|
+
- test/include/files/subdir/test.slim
|
136
|
+
- test/include/files/textfile
|
137
|
+
- test/include/test_include.rb
|
122
138
|
- test/literate/TESTS.md
|
123
139
|
- test/literate/helper.rb
|
124
140
|
- test/literate/run.rb
|
@@ -158,6 +174,7 @@ files:
|
|
158
174
|
- test/rails/script/rails
|
159
175
|
- test/rails/test/helper.rb
|
160
176
|
- test/rails/test/test_slim.rb
|
177
|
+
- test/smart/test_smart_text.rb
|
161
178
|
- test/translator/test_translator.rb
|
162
179
|
homepage: http://slim-lang.com/
|
163
180
|
licenses:
|
@@ -184,3 +201,4 @@ signing_key:
|
|
184
201
|
specification_version: 4
|
185
202
|
summary: Slim is a template language.
|
186
203
|
test_files: []
|
204
|
+
has_rdoc:
|