slim 0.6.1 → 0.7.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,70 +0,0 @@
1
- module Slim
2
- # Given the following example:
3
- # html
4
- # head
5
- # meta name="description" content="This is a Slim Test, that's all"
6
- # title Simple Test Title
7
- # body
8
- # - if logged_in?
9
- # p
10
- # ` Welcome!
11
- # - else
12
- # p
13
- # ` Please sign in.
14
- #
15
- # When compiling the above code to be eval'd, Slim produces a
16
- # compiled string that looks like:
17
- #
18
- # buf = [];
19
- # _buf << "<html>";
20
- # _buf << "<head>";
21
- # _buf << "<meta name=\"description\" content=\"This is a Slim Test, that's all\"/>";
22
- # _buf << "<title>";
23
- # _buf << "Simple Test Title";
24
- # _buf << "</title>";
25
- # _buf << "</head>";
26
- # _buf << "<body>";
27
- # if logged_in?;
28
- # _buf << "<p>";
29
- # _buf << "Welcome!";
30
- # _buf << "</p>";
31
- # else;
32
- # _buf << "<p>";
33
- # _buf << "Please sign in.";
34
- # _buf << "</p>";
35
- # end;
36
- # _buf << "</body>";
37
- # _buf << "</html>";
38
- # _buf.join;
39
- #
40
- # The optimized string after:
41
- #
42
- # buf = [];
43
- # _buf << "<html><head><meta name=\"description\" content=\"This is a Slim Test, that's all\"/><title>Simple Test Title</title></head><body>";
44
- # if logged_in?;
45
- # _buf << "<p>Welcome!</p>";
46
- # else;
47
- # _buf << "<p>Please sign in.</p>";
48
- # end;
49
- # _buf << "</body></html>";
50
- # _buf.join;
51
- module Optimizer
52
- def optimize!
53
- optimized = ""
54
- string = nil
55
-
56
- @_buffer.each do |line|
57
- if line =~ /^_buf << "(.+)"/
58
- string ||= ""
59
- string << $1
60
- else
61
- optimized << "_buf << \"#{string}\";" if string
62
- optimized << line
63
- string = nil
64
- end
65
- end
66
-
67
- optimized
68
- end
69
- end # Optimizer
70
- end # Slim
data/readme.html DELETED
@@ -1,159 +0,0 @@
1
- <h2>Slim</h2>
2
-
3
- <p>Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic. </p>
4
-
5
- <h2>What?</h2>
6
-
7
- <p>Slim is a Rails 3, Ruby 1.9.2 templating option. I do not intend on making a Rails 2.x compatible version. I don't think it would be difficult, so if you want it, I will happily accept contributions with tests.</p>
8
-
9
- <h2>Why?</h2>
10
-
11
- <p>Simply put, I wanted to see if I could pull of a template language that required minimum use of special characters and at least matched Erb's speed. Yes, Slim is speedy.</p>
12
-
13
- <h3>The syntax</h3>
14
-
15
- <p>I actually like the indentation and tag closing nature of Haml. I don't like the overall result of the markup though, it's a little cryptic. I'm sure, with practice, people read it like the Matrix, but it's never suited me. So why not try to improve it for me? There may be one or two other people with the same thoughts.</p>
16
-
17
- <p>So here's what I came up with:</p>
18
-
19
- <pre><code>! doctype html
20
- html
21
- head
22
- title Slim Examples
23
- meta name="keywords" content="template language"
24
- body
25
- h1 Markup examples
26
- div id="content" class="example1"
27
- p Nest by indentation
28
-
29
- = yield
30
-
31
- - unless items.empty?
32
- table
33
- - for item in items do
34
- tr
35
- td
36
- = item.name
37
- td
38
- = item.price
39
- - else
40
- p No items found
41
-
42
- div id="footer"
43
- ` Copyright &amp;copy; 2010 Andrew Stone
44
-
45
- = render partial: 'tracking_code'
46
-
47
- script
48
- ` $(content).do_something();
49
- </code></pre>
50
-
51
- <h3>How do I?</h3>
52
-
53
- <h4>Add content to a tag</h4>
54
-
55
- <pre><code> # Either start on the same line as the tag
56
-
57
- body
58
- h1 id="headline" Welcome to my site.
59
-
60
- # Or nest it. __Note:__ Must use backtick (with following space) to escape processing
61
-
62
- body
63
- h1 id="headline"
64
- ` Welcome to my site.
65
- </code></pre>
66
-
67
- <h4>Add content to a tag with code</h4>
68
-
69
- <pre><code> # Can make the call on the same line
70
-
71
- body
72
- h1 id="headline" = page_headline
73
-
74
- # Or nest it.
75
-
76
- body
77
- h1 id="headline"
78
- = page_headline
79
- </code></pre>
80
-
81
- <h4>Set an attribute's value with a method?</h4>
82
-
83
- <pre><code> # Just use standard Ruby interpolation.
84
-
85
- body
86
- table
87
- - for user in users do
88
- tr id="user_#{user.id}"
89
- </code></pre>
90
-
91
- <h4>Treat multiple lines of code as text that should bypass parsing.</h4>
92
-
93
- <pre><code> # Use a backtick to start the escape. Each following line that is
94
- # indented greater than the backtick is copied over.
95
-
96
- body
97
- p
98
- '
99
- This is a test of the text block.
100
-
101
- # The parsed result of the above:
102
-
103
- &lt;body&gt;&lt;p&gt;This is a test of the text block.&lt;/p&gt;&lt;/body&gt;
104
-
105
- # The left margin is set at the indent of the backtick + one space.
106
- # Any additional spaces will be copied over.
107
-
108
- body
109
- p
110
- '
111
- This line is on the left margin.
112
- This line will have one space in front of it.
113
- This line will have two spaces in front of it.
114
- And so on...
115
- </code></pre>
116
-
117
- <h3>Things to know:</h3>
118
-
119
- <ul>
120
- <li>Standard Ruby syntax after '-' and '='
121
- <ul>
122
- <li><strong>end</strong> is not required</li>
123
- <li>If you're making a method call, wrap the arguments in parenthesis (<strong>TODO:</strong> make this a non requirement)</li>
124
- </ul></li>
125
- <li>Can put content on same line or nest it.
126
- <ul>
127
- <li>If you nest content (e.g. put it on the next line), start the line with a backtick ('`')</li>
128
- </ul></li>
129
- <li>Indentation matters, but it's not as strict as Haml.
130
- <ul>
131
- <li>If you want to indent 2 spaces, then 5. It's your choice. To nest markup you only need to indent by one space, the rest is gravy.</li>
132
- </ul></li>
133
- </ul>
134
-
135
- <h3>Line indicators:</h3>
136
-
137
- <p><strong>Please note that all line indicators must be followed by a space</strong></p>
138
-
139
- <ul>
140
- <li>`
141
- <ul>
142
- <li>The backtick tells Slim to just copy the line. It essentially escapes any processing.</li>
143
- </ul></li>
144
- <li>-
145
- <ul>
146
- <li>The dash denotes control code (similar to Haml). Examples of control code are loops and conditionals.</li>
147
- </ul></li>
148
- <li>=
149
- <ul>
150
- <li>The equal sign tells Slim it's a Ruby call that produces output to add to the buffer (similar to Erb and Haml). </li>
151
- </ul></li>
152
- <li>!
153
- <ul>
154
- <li>This is a directive. Most common example:
155
- <code>! doctype html renders &lt;!doctype html&gt;</code></li>
156
- </ul></li>
157
- </ul>
158
-
159
- <h3>Please add feature requests and bugs to the Github issue tracker.</h3>
@@ -1,389 +0,0 @@
1
- require 'helper'
2
-
3
- class TestEngine
4
- include Slim::Compiler
5
-
6
- def initialize(template)
7
- @template = template
8
- compile
9
- end
10
-
11
- def compiled
12
- @compiled
13
- end
14
- end
15
-
16
- class TestSlimEngine < MiniTest::Unit::TestCase
17
-
18
- def test_simple_html
19
- string = <<HTML
20
- html
21
- head
22
- title Simple Test Title
23
- body
24
- p Hello World, meet Slim.
25
- HTML
26
-
27
- expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "</head>";_buf << "<body>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
28
-
29
- assert_equal expected, TestEngine.new(string).compiled
30
- end
31
-
32
- def test_simple_html_with_empty_lines
33
- string = <<HTML
34
- body
35
-
36
- p Hello World, meet Slim.
37
- HTML
38
-
39
- expected = %q|_buf = [];_buf << "<body>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "</body>";_buf.join;|
40
-
41
- assert_equal expected, TestEngine.new(string).compiled
42
- end
43
-
44
- def test_simple_html_with_wraparound_text
45
- string = <<HTML
46
- html
47
- head
48
- title Simple Test Title
49
- body
50
- p Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean gravida porta neque eu tincidunt. Aenean auctor blandit est sed consectetur. Quisque feugiat massa quis diam vestibulum accumsan. Morbi pharetra accumsan augue, in imperdiet sapien viverra non. Suspendisse molestie metus in sapien hendrerit dictum sit amet et leo. Donec accumsan, justo id porttitor luctus, velit erat tincidunt lorem, eu euismod enim nisl quis justo. Aliquam orci odio, ultricies sed ultrices nec, ultrices at mi. Vestibulum vel lacus eu massa mattis venenatis. In porta, quam ut dignissim varius, neque lectus laoreet felis, eget scelerisque odio lacus sed massa. Donec fringilla laoreet mi in dignissim. Curabitur porttitor ullamcorper ultrices. Quisque hendrerit odio ut ipsum blandit quis molestie diam vehicula. Suspendisse diam nibh, sollicitudin id faucibus et, pharetra sit amet massa. Mauris molestie elit id nulla euismod tempus.
51
- HTML
52
-
53
- expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "</head>";_buf << "<body>";_buf << "<p>";_buf << "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean gravida porta neque eu tincidunt. Aenean auctor blandit est sed consectetur. Quisque feugiat massa quis diam vestibulum accumsan. Morbi pharetra accumsan augue, in imperdiet sapien viverra non. Suspendisse molestie metus in sapien hendrerit dictum sit amet et leo. Donec accumsan, justo id porttitor luctus, velit erat tincidunt lorem, eu euismod enim nisl quis justo. Aliquam orci odio, ultricies sed ultrices nec, ultrices at mi. Vestibulum vel lacus eu massa mattis venenatis. In porta, quam ut dignissim varius, neque lectus laoreet felis, eget scelerisque odio lacus sed massa. Donec fringilla laoreet mi in dignissim. Curabitur porttitor ullamcorper ultrices. Quisque hendrerit odio ut ipsum blandit quis molestie diam vehicula. Suspendisse diam nibh, sollicitudin id faucibus et, pharetra sit amet massa. Mauris molestie elit id nulla euismod tempus.";_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
54
-
55
- assert_equal expected, TestEngine.new(string).compiled
56
- end
57
-
58
-
59
- def test_simple_html_with_doctype
60
- string = <<HTML
61
- ! doctype html5
62
- html
63
- body
64
- p Hello World, meet Slim.
65
- HTML
66
-
67
- expected = %q|_buf = [];_buf << "<!doctype html5>";_buf << "<html>";_buf << "<body>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
68
-
69
- assert_equal expected, TestEngine.new(string).compiled
70
- end
71
-
72
-
73
- def test_simple_html_with_params
74
- string = <<HTML
75
- html
76
- head
77
- title Simple Test Title
78
- meta name="description" content="This is a Slim Test, that's all"
79
- HTML
80
-
81
- expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "<meta name=\"description\" content=\"This is a Slim Test, that's all\"/>";_buf << "</head>";_buf << "</html>";_buf.join;|
82
-
83
- assert_equal expected, TestEngine.new(string).compiled
84
- end
85
-
86
- def test_simple_html_with_params_meta_first
87
- string = <<HTML
88
- html
89
- head
90
- meta name="description" content="This is a Slim Test, that's all"
91
- title Simple Test Title
92
- HTML
93
-
94
- expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<meta name=\"description\" content=\"This is a Slim Test, that's all\"/>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "</head>";_buf << "</html>";_buf.join;|
95
-
96
- assert_equal expected, TestEngine.new(string).compiled
97
- end
98
-
99
- def test_nested_content
100
- string = <<HTML
101
- body
102
- p
103
- ` Hello World, meet Slim.
104
- p
105
- | Hello World, meet Slim again.
106
- HTML
107
-
108
- expected = %q|_buf = [];_buf << "<body>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "<p>";_buf << "Hello World, meet Slim again.";_buf << "</p>";_buf << "</body>";_buf.join;|
109
-
110
- assert_equal expected, TestEngine.new(string).compiled
111
- end
112
-
113
- def test_closing_tag_without_content_or_attributes
114
- string = <<HTML
115
- hr
116
- p
117
- ` Hello World, meet Slim.
118
- HTML
119
-
120
- expected = %q|_buf = [];_buf << "<hr/>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf.join;|
121
-
122
- assert_equal expected, TestEngine.new(string).compiled
123
- end
124
-
125
-
126
- def test_closing_tag_without_content
127
- string = <<HTML
128
- img width="100" height="50" src="/images/test.jpg"
129
- p
130
- ` Hello World, meet Slim.
131
- HTML
132
-
133
- expected = %q|_buf = [];_buf << "<img width=\"100\" height=\"50\" src=\"/images/test.jpg\"/>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf.join;|
134
-
135
- assert_equal expected, TestEngine.new(string).compiled
136
- end
137
-
138
-
139
- def test_text_that_starts_with_tag_name
140
- string = <<HTML
141
- p
142
- ` another one bites the dust
143
- p
144
- ` i am iron man
145
- HTML
146
-
147
- expected = %q|_buf = [];_buf << "<p>";_buf << "another one bites the dust";_buf << "</p>";_buf << "<p>";_buf << "i am iron man";_buf << "</p>";_buf.join;|
148
-
149
- assert_equal expected, TestEngine.new(string).compiled
150
- end
151
-
152
-
153
- def test_simple_if_code_block
154
- string = <<HTML
155
- body
156
- - if something
157
- p
158
- ` another one bites the dust
159
- - else
160
- p
161
- ` i am iron man
162
- HTML
163
-
164
- expected = %q|_buf = [];_buf << "<body>";if something;_buf << "<p>";_buf << "another one bites the dust";_buf << "</p>";else;_buf << "<p>";_buf << "i am iron man";_buf << "</p>";end;_buf << "</body>";_buf.join;|
165
-
166
- assert_equal expected, TestEngine.new(string).compiled
167
- end
168
-
169
- def test_consecutive_if_code_blocks
170
- string = <<HTML
171
- body
172
- - if something
173
- p
174
- ` another one bites the dust
175
- - if something_else
176
- p
177
- ` i am iron man
178
- HTML
179
-
180
- expected = %q|_buf = [];_buf << "<body>";if something;_buf << "<p>";_buf << "another one bites the dust";_buf << "</p>";end;if something_else;_buf << "<p>";_buf << "i am iron man";_buf << "</p>";end;_buf << "</body>";_buf.join;|
181
-
182
- assert_equal expected, TestEngine.new(string).compiled
183
- end
184
-
185
- def test_simple_output_code
186
- string = <<HTML
187
- p
188
- = hello_world
189
- HTML
190
-
191
- expected = %q|_buf = [];_buf << "<p>";_buf << Slim.escape_html(hello_world);_buf << "</p>";_buf.join;|
192
-
193
- assert_equal expected, TestEngine.new(string).compiled
194
- end
195
-
196
- def test_simple_output_code_with_params
197
- string = <<HTML
198
- p
199
- = hello_world(params[:key])
200
- HTML
201
-
202
- expected = %q|_buf = [];_buf << "<p>";_buf << Slim.escape_html(hello_world(params[:key]));_buf << "</p>";_buf.join;|
203
-
204
- assert_equal expected, TestEngine.new(string).compiled
205
- end
206
-
207
- def test_simple_html_with_params_and_content_on_same_line
208
- string = <<TEMPLATE
209
- body
210
- p id="first" class="hello world" Hello World, meet Slim.
211
- TEMPLATE
212
-
213
- expected = %q|_buf = [];_buf << "<body>";_buf << "<p id=\"first\" class=\"hello world\">";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "</body>";_buf.join;|
214
-
215
- assert_equal expected, TestEngine.new(string).compiled
216
- end
217
-
218
- def test_simple_html_with_params_and_code_call
219
- string = <<TEMPLATE
220
- body
221
- p id="first" = hello_world
222
- TEMPLATE
223
-
224
- expected = %q|_buf = [];_buf << "<body>";_buf << "<p id=\"first\">";_buf << Slim.escape_html(hello_world);_buf << "</p>";_buf << "</body>";_buf.join;|
225
-
226
- assert_equal expected, TestEngine.new(string).compiled
227
- end
228
-
229
- def test_simple_html_with_params_and_parameterized_code_call
230
- string = <<TEMPLATE
231
- body
232
- p id="first" = hello_world("Hello Ruby!")
233
- TEMPLATE
234
-
235
- expected = %q|_buf = [];_buf << "<body>";_buf << "<p id=\"first\">";_buf << Slim.escape_html(hello_world("Hello Ruby!"));_buf << "</p>";_buf << "</body>";_buf.join;|
236
-
237
- assert_equal expected, TestEngine.new(string).compiled
238
- end
239
-
240
- def test_simple_html_with_params_and_spaced_parameterized_code_call
241
- string = <<TEMPLATE
242
- body
243
- p id="first" = hello_world "Hello Ruby!"
244
- TEMPLATE
245
-
246
- expected = %q|_buf = [];_buf << "<body>";_buf << "<p id=\"first\">";_buf << Slim.escape_html(hello_world("Hello Ruby!"));_buf << "</p>";_buf << "</body>";_buf.join;|
247
-
248
- assert_equal expected, TestEngine.new(string).compiled
249
- end
250
-
251
- def test_simple_html_with_params_and_spaced_parameterized_code_call_2
252
- string = <<TEMPLATE
253
- body
254
- p id="first" = hello_world "Hello Ruby!", :dummy => "value"
255
- TEMPLATE
256
-
257
- expected = %q|_buf = [];_buf << "<body>";_buf << "<p id=\"first\">";_buf << Slim.escape_html(hello_world("Hello Ruby!", :dummy => "value"));_buf << "</p>";_buf << "</body>";_buf.join;|
258
-
259
- assert_equal expected, TestEngine.new(string).compiled
260
- end
261
-
262
- def test_simple_html_with_multiple_wraparound_text
263
- string = <<HTML
264
- p
265
- `
266
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam malesuada, dui at condimentum dapibus, purus sapien fringilla est, vel eleifend massa purus ut lectus. Praesent aliquam, ipsum eu ornare porta, tellus lacus viverra diam, nec scelerisque ipsum nunc et lacus. Nam adipiscing velit eget dolor ultricies in dignissim augue ultricies. Sed sed leo in sapien pretium dictum. Fusce sem quam, tincidunt vel lobortis sed, tincidunt vulputate est. Phasellus et ipsum quam, ac fringilla orci. In facilisis est et ante tempus suscipit. Morbi elementum quam ut urna laoreet vel malesuada justo adipiscing. Suspendisse eu lorem id lacus molestie dapibus fringilla ut orci. Cras pellentesque auctor leo, nec bibendum est suscipit id. Mauris dignissim aliquet libero vitae vulputate. Maecenas viverra sodales suscipit. Aenean eu nisi velit.
267
-
268
- Phasellus ultricies vulputate lacus, eget pretium orci tincidunt tristique. Duis vitae luctus risus. Aliquam turpis massa, adipiscing in adipiscing ut, congue sed justo. Sed egestas ullamcorper nisl placerat dictum. Sed a leo lectus, sit amet vehicula nisl. Duis adipiscing congue tortor ut vulputate. Phasellus ligula lectus, congue non lobortis sed, dictum sed tellus. Vestibulum viverra vestibulum felis convallis pharetra. Phasellus a dignissim tellus. Proin dapibus malesuada lorem, et porttitor diam bibendum a. Donec et dui mauris, et tempus metus. Etiam pharetra varius dignissim. Maecenas lacinia, ligula ut tincidunt porttitor, sapien nisi pulvinar magna, nec sollicitudin libero odio bibendum nisi. Aenean ipsum eros, convallis id consequat nec, commodo eget diam. Integer malesuada, libero non dignissim varius, velit metus malesuada lectus, a consequat turpis purus ut elit.
269
- HTML
270
-
271
- expected = %q|_buf = [];_buf << "<p>";_buf << " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam malesuada, dui at condimentum dapibus, purus sapien fringilla est, vel eleifend massa purus ut lectus. Praesent aliquam, ipsum eu ornare porta, tellus lacus viverra diam, nec scelerisque ipsum nunc et lacus. Nam adipiscing velit eget dolor ultricies in dignissim augue ultricies. Sed sed leo in sapien pretium dictum. Fusce sem quam, tincidunt vel lobortis sed, tincidunt vulputate est. Phasellus et ipsum quam, ac fringilla orci. In facilisis est et ante tempus suscipit. Morbi elementum quam ut urna laoreet vel malesuada justo adipiscing. Suspendisse eu lorem id lacus molestie dapibus fringilla ut orci. Cras pellentesque auctor leo, nec bibendum est suscipit id. Mauris dignissim aliquet libero vitae vulputate. Maecenas viverra sodales suscipit. Aenean eu nisi velit.";_buf << "<br/>";_buf << "Phasellus ultricies vulputate lacus, eget pretium orci tincidunt tristique. Duis vitae luctus risus. Aliquam turpis massa, adipiscing in adipiscing ut, congue sed justo. Sed egestas ullamcorper nisl placerat dictum. Sed a leo lectus, sit amet vehicula nisl. Duis adipiscing congue tortor ut vulputate. Phasellus ligula lectus, congue non lobortis sed, dictum sed tellus. Vestibulum viverra vestibulum felis convallis pharetra. Phasellus a dignissim tellus. Proin dapibus malesuada lorem, et porttitor diam bibendum a. Donec et dui mauris, et tempus metus. Etiam pharetra varius dignissim. Maecenas lacinia, ligula ut tincidunt porttitor, sapien nisi pulvinar magna, nec sollicitudin libero odio bibendum nisi. Aenean ipsum eros, convallis id consequat nec, commodo eget diam. Integer malesuada, libero non dignissim varius, velit metus malesuada lectus, a consequat turpis purus ut elit.";_buf << "</p>";_buf.join;|
272
-
273
- iterate_it expected, TestEngine.new(string).compiled
274
- end
275
-
276
- def test_shortcut_html_with_params
277
- string = <<TEMPLATE
278
- body
279
- p#first.hello.world Hello World, meet Slim.
280
- TEMPLATE
281
-
282
- expected = %q|_buf = [];_buf << "<body>";_buf << "<p id=\"first\" class=\"hello world\">";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "</body>";_buf.join;|
283
-
284
- assert_equal expected, TestEngine.new(string).compiled
285
- end
286
-
287
- def test_shortcut_div_tag_with_params
288
- string = <<TEMPLATE
289
- body
290
- #first.hello.world Hello World, meet Slim.
291
- TEMPLATE
292
-
293
- expected = %q|_buf = [];_buf << "<body>";_buf << "<div id=\"first\" class=\"hello world\">";_buf << "Hello World, meet Slim.";_buf << "</div>";_buf << "</body>";_buf.join;|
294
-
295
- assert_equal expected, TestEngine.new(string).compiled
296
- end
297
-
298
- def test_control_code_loop
299
- string = <<TEMPLATE
300
- p
301
- - 3.times do
302
- | Hey!
303
- TEMPLATE
304
-
305
- expected = %q|_buf = [];_buf << "<p>";3.times do;_buf << "Hey!";end;_buf << "</p>";_buf.join;|
306
-
307
- assert_equal expected, TestEngine.new(string).compiled
308
- end
309
-
310
- def test_call_to_hash
311
- string = <<TEMPLATE
312
- p = session[:id]
313
- TEMPLATE
314
-
315
- expected = %q|_buf = [];_buf << "<p>";_buf << Slim.escape_html(session[:id]);_buf << "</p>";_buf.join;|
316
-
317
- assert_equal expected, TestEngine.new(string).compiled
318
- end
319
-
320
- def test_escape_escaping
321
- string = <<TEMPLATE
322
- p == session[:id]
323
- TEMPLATE
324
-
325
- expected = %q|_buf = [];_buf << "<p>";_buf << session[:id];_buf << "</p>";_buf.join;|
326
-
327
- assert_equal expected, TestEngine.new(string).compiled
328
- end
329
-
330
- def test_escape_escaping2
331
- string = <<TEMPLATE
332
- p == safe_method_call
333
- TEMPLATE
334
-
335
- expected = %q|_buf = [];_buf << "<p>";_buf << safe_method_call;_buf << "</p>";_buf.join;|
336
-
337
- assert_equal expected, TestEngine.new(string).compiled
338
- end
339
-
340
- def test_ruby_comments
341
- string = <<TEMPLATE
342
- p
343
- / This is a ruby comment, it won't be displayed in the final render.
344
- / Neither does this line.
345
- | But this line should be there.
346
- TEMPLATE
347
-
348
- expected = %q|_buf = [];_buf << "<p>";_buf << "But this line should be there.";_buf << "</p>";_buf.join;|
349
-
350
- assert_equal expected, TestEngine.new(string).compiled
351
- end
352
-
353
- def test_irregular_indentions
354
- string = <<TEMPLATE
355
- body
356
- p
357
- | hey
358
- == hello
359
- TEMPLATE
360
-
361
- expected = %q|_buf = [];_buf << "<body>";_buf << "<p>";_buf << "hey";_buf << hello;_buf << "</p>";_buf << "</body>";_buf.join;|
362
-
363
- assert_equal expected, TestEngine.new(string).compiled
364
- end
365
-
366
- def test_code_block
367
- string = <<TEMPLATE
368
- - unless items.empty?
369
- ul
370
- - items.each do |item|
371
- li = item
372
- - else
373
- p No items
374
- TEMPLATE
375
-
376
- expected = %q|_buf = [];unless items.empty?;_buf << "<ul>";items.each do \|item\|;_buf << "<li>";_buf << Slim.escape_html(item);_buf << "</li>";end;_buf << "</ul>";else;_buf << "<p>";_buf << "No items";_buf << "</p>";end;_buf.join;|
377
-
378
- assert_equal expected, TestEngine.new(string).compiled
379
- end
380
-
381
- # Use this to do a line by line check. Much easier to see where the problem is.
382
- def iterate_it(expected, output)
383
- es = expected.split(';')
384
- output.split(';').each_with_index do |text, index|
385
- assert_equal(text, es[index])
386
- end
387
- end
388
-
389
- end