slim 0.7.0.beta.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +6 -4
- data/README.md +23 -8
- data/Rakefile +22 -8
- data/benchmarks/run.rb +3 -3
- data/benchmarks/src/complex.slim +1 -1
- data/benchmarks/src/complex_view.rb +1 -1
- data/bin/slim +7 -0
- data/extra/slim-mode.el +409 -0
- data/{vim → extra}/slim.vim +0 -0
- data/extra/test.slim +41 -0
- data/lib/slim.rb +2 -1
- data/lib/slim/command.rb +80 -0
- data/lib/slim/compiler.rb +67 -28
- data/lib/slim/embedded_engine.rb +21 -30
- data/lib/slim/end_inserter.rb +3 -0
- data/lib/slim/engine.rb +4 -9
- data/lib/slim/filter.rb +4 -0
- data/lib/slim/helpers.rb +46 -2
- data/lib/slim/parser.rb +86 -73
- data/lib/slim/rails.rb +2 -1
- data/lib/slim/template.rb +21 -1
- data/lib/slim/version.rb +1 -1
- data/slim.gemspec +4 -3
- data/test/helper.rb +21 -3
- data/test/slim/test_code_evaluation.rb +2 -2
- data/test/slim/test_code_helpers.rb +18 -0
- data/test/slim/test_code_structure.rb +3 -2
- data/test/slim/test_embedded_engines.rb +11 -2
- data/test/slim/test_html_structure.rb +45 -0
- data/test/slim/test_parser_errors.rb +20 -11
- data/test/slim/test_ruby_errors.rb +116 -0
- metadata +31 -16
- data/vim/test.slim +0 -27
@@ -20,9 +20,9 @@ p
|
|
20
20
|
markdown:
|
21
21
|
#Header
|
22
22
|
Hello from #{"Markdown!"}
|
23
|
-
Second Line!
|
23
|
+
"Second Line!"
|
24
24
|
}
|
25
|
-
assert_html "<h1>Header</h1>\n\n<p>Hello from Markdown!\
|
25
|
+
assert_html "<h1>Header</h1>\n\n<p>Hello from Markdown!\n\"Second Line!\"</p>\n", source
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_render_with_javascript
|
@@ -52,4 +52,13 @@ p
|
|
52
52
|
}
|
53
53
|
assert_html "<p><span>before liquid block</span>\n</p>", source
|
54
54
|
end
|
55
|
+
|
56
|
+
def test_render_with_scss
|
57
|
+
source = %q{
|
58
|
+
scss:
|
59
|
+
$color: #f00;
|
60
|
+
body { color: $color; }
|
61
|
+
}
|
62
|
+
assert_html "<style type=\"text/css\">body {\n color: red; }\n</style>", source
|
63
|
+
end
|
55
64
|
end
|
@@ -13,6 +13,24 @@ html
|
|
13
13
|
assert_html '<html><head><title>Simple Test Title</title></head><body><p>Hello World, meet Slim.</p></body></html>', source
|
14
14
|
end
|
15
15
|
|
16
|
+
def test_html_namespaces
|
17
|
+
source = %q{
|
18
|
+
html:body
|
19
|
+
html:p html:id="test" Text
|
20
|
+
}
|
21
|
+
|
22
|
+
assert_html '<html:body><html:p html:id="test">Text</html:p></html:body>', source
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_doctype
|
26
|
+
source = %q{
|
27
|
+
! doctype 5
|
28
|
+
html
|
29
|
+
}
|
30
|
+
|
31
|
+
assert_html '<!DOCTYPE html><html></html>', source
|
32
|
+
end
|
33
|
+
|
16
34
|
def test_render_with_shortcut_attributes
|
17
35
|
source = %q{
|
18
36
|
h1#title This is my title
|
@@ -105,6 +123,33 @@ p There will be 3 spaces in front of this line.
|
|
105
123
|
assert_html '<p> There will be 3 spaces in front of this line.</p>', source
|
106
124
|
end
|
107
125
|
|
126
|
+
def test_paragraph_with_nested_text
|
127
|
+
source = %q{
|
128
|
+
p This is line one.
|
129
|
+
This is line two.
|
130
|
+
}
|
131
|
+
|
132
|
+
assert_html '<p>This is line one. This is line two.</p>', source
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_paragraph_with_padded_nested_text
|
136
|
+
source = %q{
|
137
|
+
p This is line one.
|
138
|
+
This is line two.
|
139
|
+
}
|
140
|
+
|
141
|
+
assert_html '<p> This is line one. This is line two.</p>', source
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_paragraph_with_attributes_and_nested_text
|
145
|
+
source = %q{
|
146
|
+
p#test class="paragraph" This is line one.
|
147
|
+
This is line two.
|
148
|
+
}
|
149
|
+
|
150
|
+
assert_html '<p id="test" class="paragraph">This is line one.This is line two.</p>', source
|
151
|
+
end
|
152
|
+
|
108
153
|
def test_output_code_with_leading_spaces
|
109
154
|
source = %q{
|
110
155
|
p= hello_world
|
@@ -1,13 +1,22 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestParserErrors < TestSlim
|
4
|
+
def test_correct_filename
|
5
|
+
source = %q{
|
6
|
+
! doctype 5
|
7
|
+
div Invalid
|
8
|
+
}
|
9
|
+
|
10
|
+
assert_syntax_error "Unexpected indentation\n test.slim, Line 3\n div Invalid\n ^\n ", source, :file => 'test.slim'
|
11
|
+
end
|
12
|
+
|
4
13
|
def test_unexpected_indentation
|
5
14
|
source = %q{
|
6
|
-
|
15
|
+
! doctype 5
|
7
16
|
div Invalid
|
8
17
|
}
|
9
18
|
|
10
|
-
assert_syntax_error "Unexpected indentation\n Line 3\n div Invalid\n ^\n ", source
|
19
|
+
assert_syntax_error "Unexpected indentation\n (__TEMPLATE__), Line 3\n div Invalid\n ^\n ", source
|
11
20
|
end
|
12
21
|
|
13
22
|
def test_unexpected_text_indentation
|
@@ -17,7 +26,7 @@ p
|
|
17
26
|
text
|
18
27
|
}
|
19
28
|
|
20
|
-
assert_syntax_error "Unexpected text indentation\n Line 4\n text\n ^\n ", source
|
29
|
+
assert_syntax_error "Unexpected text indentation\n (__TEMPLATE__), Line 4\n text\n ^\n ", source
|
21
30
|
end
|
22
31
|
|
23
32
|
def test_malformed_indentation
|
@@ -27,7 +36,7 @@ p
|
|
27
36
|
div Invalid
|
28
37
|
}
|
29
38
|
|
30
|
-
assert_syntax_error "Malformed indentation\n Line 4\n div Invalid\n ^\n ", source
|
39
|
+
assert_syntax_error "Malformed indentation\n (__TEMPLATE__), Line 4\n div Invalid\n ^\n ", source
|
31
40
|
end
|
32
41
|
|
33
42
|
def test_unknown_line_indicator
|
@@ -39,7 +48,7 @@ p
|
|
39
48
|
?invalid
|
40
49
|
}
|
41
50
|
|
42
|
-
assert_syntax_error "Unknown line indicator\n Line 6\n ?invalid\n ^\n ", source
|
51
|
+
assert_syntax_error "Unknown line indicator\n (__TEMPLATE__), Line 6\n ?invalid\n ^\n ", source
|
43
52
|
end
|
44
53
|
|
45
54
|
def test_expected_closing_delimiter
|
@@ -48,7 +57,7 @@ p
|
|
48
57
|
img(src="img.jpg" title={title}
|
49
58
|
}
|
50
59
|
|
51
|
-
assert_syntax_error "Expected closing attribute delimiter )\n Line 3\n img(src=\"img.jpg\" title={title}\n ^\n ", source
|
60
|
+
assert_syntax_error "Expected closing attribute delimiter )\n (__TEMPLATE__), Line 3\n img(src=\"img.jpg\" title={title}\n ^\n ", source
|
52
61
|
end
|
53
62
|
|
54
63
|
def test_expected_closing_delimiter
|
@@ -57,7 +66,7 @@ p
|
|
57
66
|
img src=[hash[1] + hash[2]
|
58
67
|
}
|
59
68
|
|
60
|
-
assert_syntax_error "Expected closing attribute delimiter ]\n Line 3\n img src=[hash[1] + hash[2]\n ^\n ", source
|
69
|
+
assert_syntax_error "Expected closing attribute delimiter ]\n (__TEMPLATE__), Line 3\n img src=[hash[1] + hash[2]\n ^\n ", source
|
61
70
|
end
|
62
71
|
|
63
72
|
def test_unexpected_closing
|
@@ -66,7 +75,7 @@ p
|
|
66
75
|
img src=(1+1)]
|
67
76
|
}
|
68
77
|
|
69
|
-
assert_syntax_error "Unexpected closing ]\n Line 3\n img src=(1+1)]\n ^\n ", source
|
78
|
+
assert_syntax_error "Unexpected closing ]\n (__TEMPLATE__), Line 3\n img src=(1+1)]\n ^\n ", source
|
70
79
|
end
|
71
80
|
|
72
81
|
def test_invalid_empty_attribute
|
@@ -75,7 +84,7 @@ p
|
|
75
84
|
img{src= }
|
76
85
|
}
|
77
86
|
|
78
|
-
assert_syntax_error "Invalid empty attribute\n Line 3\n img{src= }\n ^\n ", source
|
87
|
+
assert_syntax_error "Invalid empty attribute\n (__TEMPLATE__), Line 3\n img{src= }\n ^\n ", source
|
79
88
|
end
|
80
89
|
|
81
90
|
def test_invalid_empty_attribute2
|
@@ -84,7 +93,7 @@ p
|
|
84
93
|
img{src=}
|
85
94
|
}
|
86
95
|
|
87
|
-
assert_syntax_error "Invalid empty attribute\n Line 3\n img{src=}\n ^\n ", source
|
96
|
+
assert_syntax_error "Invalid empty attribute\n (__TEMPLATE__), Line 3\n img{src=}\n ^\n ", source
|
88
97
|
end
|
89
98
|
|
90
99
|
def test_invalid_empty_attribute3
|
@@ -93,6 +102,6 @@ p
|
|
93
102
|
img src=
|
94
103
|
}
|
95
104
|
|
96
|
-
assert_syntax_error "Invalid empty attribute\n Line 3\n img src=\n ^\n ", source
|
105
|
+
assert_syntax_error "Invalid empty attribute\n (__TEMPLATE__), Line 3\n img src=\n ^\n ", source
|
97
106
|
end
|
98
107
|
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSlimRubyErrors < TestSlim
|
4
|
+
def test_broken_output_line
|
5
|
+
source = %q{
|
6
|
+
p = hello_world + \
|
7
|
+
hello_world + \
|
8
|
+
unknown_ruby_method
|
9
|
+
}
|
10
|
+
|
11
|
+
assert_ruby_error NameError, "test.slim:4", source, :file => 'test.slim'
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_broken_output_line2
|
15
|
+
source = %q{
|
16
|
+
p = hello_world + \
|
17
|
+
hello_world
|
18
|
+
p Hello
|
19
|
+
= unknown_ruby_method
|
20
|
+
}
|
21
|
+
|
22
|
+
assert_ruby_error NameError,"(__TEMPLATE__):5", source
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_output_block
|
26
|
+
source = %q{
|
27
|
+
p = hello_world "Hello Ruby" do
|
28
|
+
= unknown_ruby_method
|
29
|
+
}
|
30
|
+
|
31
|
+
assert_ruby_error NameError,"(__TEMPLATE__):3", source
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_output_block2
|
35
|
+
source = %q{
|
36
|
+
p = hello_world "Hello Ruby" do
|
37
|
+
= "Hello from block"
|
38
|
+
p Hello
|
39
|
+
= unknown_ruby_method
|
40
|
+
}
|
41
|
+
|
42
|
+
assert_ruby_error NameError, "(__TEMPLATE__):5", source
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_text_block
|
46
|
+
source = %q{
|
47
|
+
p Text line 1
|
48
|
+
Text line 2
|
49
|
+
= unknown_ruby_method
|
50
|
+
}
|
51
|
+
|
52
|
+
assert_ruby_error NameError,"(__TEMPLATE__):4", source
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_text_block2
|
56
|
+
source = %q{
|
57
|
+
|
|
58
|
+
Text line 1
|
59
|
+
Text line 2
|
60
|
+
= unknown_ruby_method
|
61
|
+
}
|
62
|
+
|
63
|
+
assert_ruby_error NameError,"(__TEMPLATE__):5", source
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_comment
|
67
|
+
source = %q{
|
68
|
+
/ Comment line 1
|
69
|
+
Comment line 2
|
70
|
+
= unknown_ruby_method
|
71
|
+
}
|
72
|
+
|
73
|
+
assert_ruby_error NameError,"(__TEMPLATE__):4", source
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_embedded_ruby
|
77
|
+
source = %q{
|
78
|
+
ruby:
|
79
|
+
a = 1
|
80
|
+
b = 2
|
81
|
+
= a + b
|
82
|
+
= unknown_ruby_method
|
83
|
+
}
|
84
|
+
|
85
|
+
assert_ruby_error NameError,"(__TEMPLATE__):6", source
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_embedded_javascript
|
89
|
+
source = %q{
|
90
|
+
javascript:
|
91
|
+
alert();
|
92
|
+
alert();
|
93
|
+
= unknown_ruby_method
|
94
|
+
}
|
95
|
+
|
96
|
+
assert_ruby_error NameError,"(__TEMPLATE__):5", source
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_invalid_nested_code
|
100
|
+
source = %q{
|
101
|
+
p
|
102
|
+
- test = 123
|
103
|
+
= "Hello from within a block! "
|
104
|
+
}
|
105
|
+
assert_ruby_syntax_error "(__TEMPLATE__):5", source
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_invalid_nested_output
|
109
|
+
source = %q{
|
110
|
+
p
|
111
|
+
= "Hello Ruby!"
|
112
|
+
= "Hello from within a block! "
|
113
|
+
}
|
114
|
+
assert_ruby_syntax_error "(__TEMPLATE__):5", source
|
115
|
+
end
|
116
|
+
end
|
metadata
CHANGED
@@ -1,23 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
4
|
+
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 7
|
8
8
|
- 0
|
9
|
-
|
10
|
-
- 2
|
11
|
-
version: 0.7.0.beta.2
|
9
|
+
version: 0.7.0
|
12
10
|
platform: ruby
|
13
11
|
authors:
|
14
12
|
- Andrew Stone
|
15
13
|
- Fred Wu
|
14
|
+
- Daniel Mendler
|
16
15
|
autorequire:
|
17
16
|
bindir: bin
|
18
17
|
cert_chain: []
|
19
18
|
|
20
|
-
date: 2010-10-
|
19
|
+
date: 2010-10-25 00:00:00 -04:00
|
21
20
|
default_executable:
|
22
21
|
dependencies:
|
23
22
|
- !ruby/object:Gem::Dependency
|
@@ -46,8 +45,8 @@ dependencies:
|
|
46
45
|
segments:
|
47
46
|
- 0
|
48
47
|
- 1
|
49
|
-
-
|
50
|
-
version: 0.1.
|
48
|
+
- 3
|
49
|
+
version: 0.1.3
|
51
50
|
type: :runtime
|
52
51
|
version_requirements: *id002
|
53
52
|
- !ruby/object:Gem::Dependency
|
@@ -157,12 +156,26 @@ dependencies:
|
|
157
156
|
version: "0"
|
158
157
|
type: :development
|
159
158
|
version_requirements: *id010
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: yard
|
161
|
+
prerelease: false
|
162
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
163
|
+
none: false
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
segments:
|
168
|
+
- 0
|
169
|
+
version: "0"
|
170
|
+
type: :development
|
171
|
+
version_requirements: *id011
|
160
172
|
description: Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic.
|
161
173
|
email:
|
162
174
|
- andy@stonean.com
|
163
175
|
- ifredwu@gmail.com
|
164
|
-
|
165
|
-
|
176
|
+
- mail@daniel-mendler.de
|
177
|
+
executables:
|
178
|
+
- slim
|
166
179
|
extensions: []
|
167
180
|
|
168
181
|
extra_rdoc_files:
|
@@ -178,7 +191,12 @@ files:
|
|
178
191
|
- benchmarks/src/complex.haml
|
179
192
|
- benchmarks/src/complex.slim
|
180
193
|
- benchmarks/src/complex_view.rb
|
194
|
+
- bin/slim
|
195
|
+
- extra/slim-mode.el
|
196
|
+
- extra/slim.vim
|
197
|
+
- extra/test.slim
|
181
198
|
- lib/slim.rb
|
199
|
+
- lib/slim/command.rb
|
182
200
|
- lib/slim/compiler.rb
|
183
201
|
- lib/slim/embedded_engine.rb
|
184
202
|
- lib/slim/end_inserter.rb
|
@@ -201,9 +219,8 @@ files:
|
|
201
219
|
- test/slim/test_html_escaping.rb
|
202
220
|
- test/slim/test_html_structure.rb
|
203
221
|
- test/slim/test_parser_errors.rb
|
222
|
+
- test/slim/test_ruby_errors.rb
|
204
223
|
- test/slim/test_slim_template.rb
|
205
|
-
- vim/slim.vim
|
206
|
-
- vim/test.slim
|
207
224
|
has_rdoc: true
|
208
225
|
homepage: http://github.com/stonean/slim
|
209
226
|
licenses: []
|
@@ -224,13 +241,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
224
241
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
225
242
|
none: false
|
226
243
|
requirements:
|
227
|
-
- - "
|
244
|
+
- - ">="
|
228
245
|
- !ruby/object:Gem::Version
|
229
246
|
segments:
|
230
|
-
-
|
231
|
-
|
232
|
-
- 1
|
233
|
-
version: 1.3.1
|
247
|
+
- 0
|
248
|
+
version: "0"
|
234
249
|
requirements: []
|
235
250
|
|
236
251
|
rubyforge_project: slim
|
data/vim/test.slim
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
! doctype html
|
2
|
-
head
|
3
|
-
title Slim Vim Test
|
4
|
-
meta name="keywords" content="slim, vim, syntax"
|
5
|
-
body
|
6
|
-
h1 = @page_title
|
7
|
-
p id="notice"
|
8
|
-
'
|
9
|
-
Welcome to the the syntax test. This file is to excercise the various markup.
|
10
|
-
|
11
|
-
- unless @users.empty?
|
12
|
-
table
|
13
|
-
- for user in users do
|
14
|
-
tr
|
15
|
-
td = user.name
|
16
|
-
- else
|
17
|
-
p There are no users.
|
18
|
-
|
19
|
-
script type="text/javascript"
|
20
|
-
'
|
21
|
-
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
22
|
-
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
23
|
-
|
24
|
-
script type="text/javascript"
|
25
|
-
'
|
26
|
-
var pageTracker = _gat._getTracker("UA-12345678-9");
|
27
|
-
pageTracker._trackPageview();
|