slim 0.6.1 → 0.7.0.beta.2
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.
- data/.gitignore +8 -0
- data/Gemfile +1 -6
- data/Gemfile.lock +20 -16
- data/README.md +137 -90
- data/Rakefile +9 -37
- data/benchmarks/run.rb +63 -0
- data/benchmarks/src/complex.erb +23 -0
- data/benchmarks/src/complex.haml +18 -0
- data/benchmarks/src/complex.slim +18 -0
- data/benchmarks/src/complex_view.rb +17 -0
- data/lib/slim.rb +15 -11
- data/lib/slim/compiler.rb +71 -137
- data/lib/slim/embedded_engine.rb +108 -0
- data/lib/slim/end_inserter.rb +57 -0
- data/lib/slim/engine.rb +16 -14
- data/lib/slim/filter.rb +44 -0
- data/lib/slim/helpers.rb +37 -0
- data/lib/slim/parser.rb +355 -0
- data/lib/slim/rails.rb +2 -2
- data/lib/slim/template.rb +18 -0
- data/lib/slim/version.rb +3 -0
- data/slim.gemspec +26 -66
- data/test/helper.rb +32 -4
- data/test/slim/test_code_blocks.rb +33 -0
- data/test/slim/test_code_escaping.rb +69 -0
- data/test/slim/test_code_evaluation.rb +199 -0
- data/test/slim/test_code_helpers.rb +12 -0
- data/test/slim/test_code_output.rb +116 -0
- data/test/slim/test_code_structure.rb +84 -0
- data/test/slim/test_embedded_engines.rb +55 -0
- data/test/slim/test_html_escaping.rb +32 -0
- data/test/slim/test_html_structure.rb +181 -0
- data/test/slim/test_parser_errors.rb +98 -0
- data/test/slim/test_slim_template.rb +128 -0
- data/vim/slim.vim +33 -0
- data/vim/test.slim +27 -0
- metadata +127 -34
- data/lib/slim/optimizer.rb +0 -70
- data/readme.html +0 -159
- data/test/slim/test_compiler.rb +0 -389
- data/test/slim/test_engine.rb +0 -458
- data/test/test_slim.rb +0 -4
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSlimCodeOutput < TestSlim
|
4
|
+
def test_render_with_call
|
5
|
+
source = %q{
|
6
|
+
p
|
7
|
+
= hello_world
|
8
|
+
}
|
9
|
+
|
10
|
+
assert_html '<p>Hello World from @env</p>', source
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_render_with_conditional_call
|
14
|
+
source = %q{
|
15
|
+
p
|
16
|
+
= hello_world if true
|
17
|
+
}
|
18
|
+
|
19
|
+
assert_html '<p>Hello World from @env</p>', source
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_render_with_parameterized_call
|
23
|
+
source = %q{
|
24
|
+
p
|
25
|
+
= hello_world("Hello Ruby!")
|
26
|
+
}
|
27
|
+
|
28
|
+
assert_html '<p>Hello Ruby!</p>', source
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_render_with_spaced_parameterized_call
|
32
|
+
source = %q{
|
33
|
+
p
|
34
|
+
= hello_world "Hello Ruby!"
|
35
|
+
}
|
36
|
+
|
37
|
+
assert_html '<p>Hello Ruby!</p>', source
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_render_with_spaced_parameterized_call_2
|
41
|
+
source = %q{
|
42
|
+
p
|
43
|
+
= hello_world "Hello Ruby!", :dummy => "value"
|
44
|
+
}
|
45
|
+
|
46
|
+
assert_html '<p>Hello Ruby!dummy value</p>', source
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_render_with_call_and_inline_text
|
50
|
+
source = %q{
|
51
|
+
h1 This is my title
|
52
|
+
p
|
53
|
+
= hello_world
|
54
|
+
}
|
55
|
+
|
56
|
+
assert_html '<h1>This is my title</h1><p>Hello World from @env</p>', source
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_render_with_attribute_starts_with_keyword
|
60
|
+
source = %q{
|
61
|
+
p = hello_world in_keyword
|
62
|
+
}
|
63
|
+
|
64
|
+
assert_html '<p>starts with keyword</p>', source
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_hash_call
|
68
|
+
source = %q{
|
69
|
+
p = hash[:a]
|
70
|
+
}
|
71
|
+
|
72
|
+
assert_html '<p>The letter a</p>', source
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_tag_output_without_space
|
76
|
+
source = %q{
|
77
|
+
p= hello_world
|
78
|
+
p=hello_world
|
79
|
+
}
|
80
|
+
|
81
|
+
assert_html '<p>Hello World from @env</p><p>Hello World from @env</p>', source
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_class_output_without_space
|
85
|
+
source = %q{
|
86
|
+
.test=hello_world
|
87
|
+
#test==hello_world
|
88
|
+
}
|
89
|
+
|
90
|
+
assert_html '<div class="test">Hello World from @env</div><div id="test">Hello World from @env</div>', source
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_attribute_output_without_space
|
94
|
+
source = %q{
|
95
|
+
p id="test"=hello_world
|
96
|
+
p(id="test")==hello_world
|
97
|
+
}
|
98
|
+
|
99
|
+
assert_html '<p id="test">Hello World from @env</p><p id="test">Hello World from @env</p>', source
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_render_with_backslash_end
|
103
|
+
source = %q{
|
104
|
+
p = \
|
105
|
+
"Hello" + \
|
106
|
+
" Ruby!"
|
107
|
+
- variable = 1 + \
|
108
|
+
2 + \
|
109
|
+
3
|
110
|
+
= variable + \
|
111
|
+
1
|
112
|
+
}
|
113
|
+
|
114
|
+
assert_html '<p>Hello Ruby!</p>7', source
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSlimCodeStructure < TestSlim
|
4
|
+
def test_render_with_conditional
|
5
|
+
source = %q{
|
6
|
+
div
|
7
|
+
- if show_first?
|
8
|
+
p The first paragraph
|
9
|
+
- else
|
10
|
+
p The second paragraph
|
11
|
+
}
|
12
|
+
|
13
|
+
assert_html '<div><p>The second paragraph</p></div>', source
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_render_with_conditional_and_end
|
17
|
+
source = %q{
|
18
|
+
div
|
19
|
+
- if show_first?
|
20
|
+
p The first paragraph
|
21
|
+
- else
|
22
|
+
p The second paragraph
|
23
|
+
- end
|
24
|
+
}
|
25
|
+
|
26
|
+
assert_html '<div><p>The second paragraph</p></div>', source
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_render_with_consecutive_conditionals
|
30
|
+
source = %q{
|
31
|
+
div
|
32
|
+
- if show_first? true
|
33
|
+
p The first paragraph
|
34
|
+
- if show_first? true
|
35
|
+
p The second paragraph
|
36
|
+
}
|
37
|
+
|
38
|
+
assert_html '<div><p>The first paragraph</p><p>The second paragraph</p></div>', source
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_render_with_parameterized_conditional
|
42
|
+
source = %q{
|
43
|
+
div
|
44
|
+
- if show_first? false
|
45
|
+
p The first paragraph
|
46
|
+
- else
|
47
|
+
p The second paragraph
|
48
|
+
}
|
49
|
+
|
50
|
+
assert_html '<div><p>The second paragraph</p></div>', source
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_render_with_inline_condition
|
54
|
+
source = %q{
|
55
|
+
p = hello_world if true
|
56
|
+
}
|
57
|
+
|
58
|
+
assert_html '<p>Hello World from @env</p>', source
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_render_with_case
|
62
|
+
source = %q{
|
63
|
+
p
|
64
|
+
- case 42
|
65
|
+
- when 41
|
66
|
+
| 1
|
67
|
+
- when 42
|
68
|
+
| 42
|
69
|
+
| is the answer
|
70
|
+
}
|
71
|
+
|
72
|
+
assert_html '<p>42 is the answer</p>', source
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_render_with_comments
|
76
|
+
source = %q{
|
77
|
+
p Hello
|
78
|
+
/ This is a comment
|
79
|
+
/ Another comment
|
80
|
+
}
|
81
|
+
|
82
|
+
assert_html '<p>Hello</p>', source
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
class TestSlimEmbeddedEngines < TestSlim
|
5
|
+
def test_render_with_embedded_template
|
6
|
+
source = %q{
|
7
|
+
p
|
8
|
+
- text = 'before erb block'
|
9
|
+
erb:
|
10
|
+
<b>Hello from <%= text.upcase %>!</b>
|
11
|
+
Second Line!
|
12
|
+
<% if true %><%= true %><% end %>
|
13
|
+
}
|
14
|
+
|
15
|
+
assert_html "<p><b>Hello from BEFORE ERB BLOCK!</b>\nSecond Line!\ntrue\n</p>", source
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_render_with_interpolated_embedded_template
|
19
|
+
source = %q{
|
20
|
+
markdown:
|
21
|
+
#Header
|
22
|
+
Hello from #{"Markdown!"}
|
23
|
+
Second Line!
|
24
|
+
}
|
25
|
+
assert_html "<h1>Header</h1>\n\n<p>Hello from Markdown!\nSecond Line!</p>\n", source
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_render_with_javascript
|
29
|
+
source = %q{
|
30
|
+
javascript:
|
31
|
+
$(function() {});
|
32
|
+
}
|
33
|
+
assert_html '<script type="text/javascript">$(function() {});</script>', source
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_render_with_ruby
|
37
|
+
source = %q{
|
38
|
+
ruby:
|
39
|
+
variable = 1 +
|
40
|
+
2
|
41
|
+
= variable
|
42
|
+
}
|
43
|
+
assert_html '3', source
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_render_with_liquid
|
47
|
+
source = %q{
|
48
|
+
p
|
49
|
+
- text = 'before liquid block'
|
50
|
+
liquid:
|
51
|
+
<span>{{text}}</span>
|
52
|
+
}
|
53
|
+
assert_html "<p><span>before liquid block</span>\n</p>", source
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSlimHtmlEscaping < TestSlim
|
4
|
+
def test_html_will_not_be_escaped
|
5
|
+
source = %q{
|
6
|
+
p <Hello> World, meet "Slim".
|
7
|
+
}
|
8
|
+
|
9
|
+
assert_html '<p><Hello> World, meet "Slim".</p>', source
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_html_with_newline_will_not_be_escaped
|
13
|
+
source = %q{
|
14
|
+
p
|
15
|
+
|
|
16
|
+
<Hello> World,
|
17
|
+
meet "Slim".
|
18
|
+
}
|
19
|
+
|
20
|
+
assert_html '<p><Hello> World, meet "Slim".</p>', source
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_html_with_escaped_interpolation
|
24
|
+
source = %q{
|
25
|
+
- x = '"'
|
26
|
+
- content = '<x>'
|
27
|
+
p class="#{x}" test #{content}
|
28
|
+
}
|
29
|
+
|
30
|
+
assert_html '<p class=""">test <x></p>', source
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSlimHtmlStructure < TestSlim
|
4
|
+
def test_simple_render
|
5
|
+
source = %q{
|
6
|
+
html
|
7
|
+
head
|
8
|
+
title Simple Test Title
|
9
|
+
body
|
10
|
+
p Hello World, meet Slim.
|
11
|
+
}
|
12
|
+
|
13
|
+
assert_html '<html><head><title>Simple Test Title</title></head><body><p>Hello World, meet Slim.</p></body></html>', source
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_render_with_shortcut_attributes
|
17
|
+
source = %q{
|
18
|
+
h1#title This is my title
|
19
|
+
#notice.hello.world
|
20
|
+
= hello_world
|
21
|
+
}
|
22
|
+
|
23
|
+
assert_html '<h1 id="title">This is my title</h1><div id="notice" class="hello world">Hello World from @env</div>', source
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_render_with_text_block
|
27
|
+
source = %q{
|
28
|
+
p
|
29
|
+
`
|
30
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
31
|
+
}
|
32
|
+
|
33
|
+
assert_html '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>', source
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_render_with_text_block_with_subsequent_markup
|
37
|
+
source = %q{
|
38
|
+
p
|
39
|
+
`
|
40
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
41
|
+
p Some more markup
|
42
|
+
}
|
43
|
+
|
44
|
+
assert_html '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p><p>Some more markup</p>', source
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_nested_text
|
48
|
+
source = %q{
|
49
|
+
p
|
50
|
+
|
|
51
|
+
This is line one.
|
52
|
+
This is line two.
|
53
|
+
This is line three.
|
54
|
+
This is line four.
|
55
|
+
p This is a new paragraph.
|
56
|
+
}
|
57
|
+
|
58
|
+
assert_html '<p>This is line one. This is line two. This is line three. This is line four.</p><p>This is a new paragraph.</p>', source
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_nested_text_with_nested_html_one_same_line
|
62
|
+
source = %q{
|
63
|
+
p
|
64
|
+
| This is line one.
|
65
|
+
This is line two.
|
66
|
+
span.bold This is a bold line in the paragraph.
|
67
|
+
| This is more content.
|
68
|
+
}
|
69
|
+
|
70
|
+
assert_html '<p>This is line one. This is line two.<span class="bold">This is a bold line in the paragraph.</span> This is more content.</p>', source
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_nested_text_with_nested_html_one_same_line2
|
74
|
+
source = %q{
|
75
|
+
p
|
76
|
+
|This is line one.
|
77
|
+
This is line two.
|
78
|
+
span.bold This is a bold line in the paragraph.
|
79
|
+
| This is more content.
|
80
|
+
}
|
81
|
+
|
82
|
+
assert_html '<p>This is line one. This is line two.<span class="bold">This is a bold line in the paragraph.</span> This is more content.</p>', source
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_nested_text_with_nested_html
|
86
|
+
source = %q{
|
87
|
+
p
|
88
|
+
|
|
89
|
+
This is line one.
|
90
|
+
This is line two.
|
91
|
+
This is line three.
|
92
|
+
This is line four.
|
93
|
+
span.bold This is a bold line in the paragraph.
|
94
|
+
| This is more content.
|
95
|
+
}
|
96
|
+
|
97
|
+
assert_html '<p>This is line one. This is line two. This is line three. This is line four.<span class="bold">This is a bold line in the paragraph.</span> This is more content.</p>', source
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_simple_paragraph_with_padding
|
101
|
+
source = %q{
|
102
|
+
p There will be 3 spaces in front of this line.
|
103
|
+
}
|
104
|
+
|
105
|
+
assert_html '<p> There will be 3 spaces in front of this line.</p>', source
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_output_code_with_leading_spaces
|
109
|
+
source = %q{
|
110
|
+
p= hello_world
|
111
|
+
p = hello_world
|
112
|
+
p = hello_world
|
113
|
+
}
|
114
|
+
|
115
|
+
assert_html '<p>Hello World from @env</p><p>Hello World from @env</p><p>Hello World from @env</p>', source
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_single_quoted_attributes
|
119
|
+
source = %q{
|
120
|
+
p class='underscored_class_name' = output_number
|
121
|
+
}
|
122
|
+
|
123
|
+
assert_html '<p class="underscored_class_name">1337</p>', source
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_nonstandard_attributes
|
127
|
+
source = %q{
|
128
|
+
p id="dashed-id" class="underscored_class_name" = output_number
|
129
|
+
}
|
130
|
+
|
131
|
+
assert_html '<p id="dashed-id" class="underscored_class_name">1337</p>', source
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_nonstandard_shortcut_attributes
|
135
|
+
source = %q{
|
136
|
+
p#dashed-id.underscored_class_name = output_number
|
137
|
+
}
|
138
|
+
|
139
|
+
assert_html '<p id="dashed-id" class="underscored_class_name">1337</p>', source
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_dashed_attributes
|
143
|
+
source = %q{
|
144
|
+
p data-info="Illudium Q-36" = output_number
|
145
|
+
}
|
146
|
+
|
147
|
+
assert_html '<p data-info="Illudium Q-36">1337</p>', source
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_dashed_attributes_with_shortcuts
|
151
|
+
source = %q{
|
152
|
+
p#marvin.martian data-info="Illudium Q-36" = output_number
|
153
|
+
}
|
154
|
+
|
155
|
+
assert_html '<p id="marvin" class="martian" data-info="Illudium Q-36">1337</p>', source
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_parens_around_attributes
|
159
|
+
source = %q{
|
160
|
+
p(id="marvin" class="martian" data-info="Illudium Q-36") = output_number
|
161
|
+
}
|
162
|
+
|
163
|
+
assert_html '<p id="marvin" class="martian" data-info="Illudium Q-36">1337</p>', source
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_square_brackets_around_attributes
|
167
|
+
source = %q{
|
168
|
+
p[id="marvin" class="martian" data-info="Illudium Q-36"] = output_number
|
169
|
+
}
|
170
|
+
|
171
|
+
assert_html '<p id="marvin" class="martian" data-info="Illudium Q-36">1337</p>', source
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_parens_around_attributes_with_equal_sign_snug_to_right_paren
|
175
|
+
source = %q{
|
176
|
+
p(id="marvin" class="martian" data-info="Illudium Q-36")= output_number
|
177
|
+
}
|
178
|
+
|
179
|
+
assert_html '<p id="marvin" class="martian" data-info="Illudium Q-36">1337</p>', source
|
180
|
+
end
|
181
|
+
end
|