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
data/.gitignore
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
slim (0.
|
5
|
-
escape_utils
|
4
|
+
slim (0.7.0.beta.1)
|
5
|
+
escape_utils (>= 0.1.9)
|
6
|
+
temple (~> 0.1.2)
|
7
|
+
tilt (~> 1.1)
|
6
8
|
|
7
9
|
GEM
|
8
10
|
remote: http://rubygems.org/
|
@@ -10,26 +12,28 @@ GEM
|
|
10
12
|
abstract (1.0.0)
|
11
13
|
erubis (2.6.6)
|
12
14
|
abstract (>= 1.0.0)
|
13
|
-
escape_utils (0.1.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
jeweler (1.4.0)
|
18
|
-
gemcutter (>= 0.1.0)
|
19
|
-
git (>= 1.2.5)
|
20
|
-
rubyforge (>= 2.0.0)
|
21
|
-
json_pure (1.4.6)
|
15
|
+
escape_utils (0.1.9)
|
16
|
+
haml (3.0.22)
|
17
|
+
liquid (2.2.2)
|
18
|
+
minitest (1.7.2)
|
22
19
|
rake (0.8.7)
|
23
|
-
|
24
|
-
|
20
|
+
rcov (0.9.9)
|
21
|
+
rdiscount (1.6.5)
|
22
|
+
temple (0.1.2)
|
23
|
+
tilt (1.1)
|
25
24
|
|
26
25
|
PLATFORMS
|
27
26
|
ruby
|
28
27
|
|
29
28
|
DEPENDENCIES
|
30
29
|
erubis
|
31
|
-
escape_utils
|
30
|
+
escape_utils (>= 0.1.9)
|
32
31
|
haml
|
33
|
-
|
34
|
-
|
32
|
+
liquid
|
33
|
+
minitest
|
34
|
+
rake (>= 0.8.7)
|
35
|
+
rcov
|
36
|
+
rdiscount
|
35
37
|
slim!
|
38
|
+
temple (~> 0.1.2)
|
39
|
+
tilt (~> 1.1)
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ Slim is a fast, lightweight templating engine for __Rails 3__. It has been teste
|
|
12
12
|
|
13
13
|
Within the Rails community, _Erb_ and _Haml_ are without doubt the two most popular templating engines. However, _Erb_'s syntax is cumbersome and Haml's performance isn't exactly the best. Slim was born to bring the minimalist syntax approach of _Haml_ and the higher performance of Erb into once solution.
|
14
14
|
|
15
|
-
___Yes, Slim is speedy!___ Benchmarks are provided at the end of this README file. Alternatively, a benchmark
|
15
|
+
___Yes, Slim is speedy!___ Benchmarks are provided at the end of this README file. Alternatively, a benchmark rake task is provided so you could test it yourself (`rake bench`).
|
16
16
|
|
17
17
|
|
18
18
|
## How?
|
@@ -77,38 +77,67 @@ Here's a quick example to demonstrate what a Slim template looks like:
|
|
77
77
|
|
78
78
|
__Please note that all line indicators must be followed by a space__
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
80
|
+
#### `|`
|
81
|
+
|
82
|
+
> The pipe tells Slim to just copy the line. It essentially escapes any processing.
|
83
|
+
|
84
|
+
#### `` ` `` or `'`
|
85
|
+
|
86
|
+
> _Same as the pipe (`|`)._
|
87
|
+
|
88
|
+
#### `-`
|
89
|
+
|
90
|
+
> The dash denotes control code (similar to Haml). Examples of control code are loops and conditionals.
|
91
|
+
|
92
|
+
#### `=`
|
93
|
+
|
94
|
+
> The equal sign tells Slim it's a Ruby call that produces output to add to the buffer (similar to Erb and Haml).
|
95
|
+
|
96
|
+
#### `==`
|
97
|
+
|
98
|
+
> Same as the single equal sign, but does not go through the escape_html method.
|
99
|
+
|
100
|
+
#### `!`
|
101
|
+
|
102
|
+
> This is a directive. Most common example: `! doctype html # renders <!doctype html>`
|
103
|
+
|
104
|
+
#### `/`
|
105
|
+
|
106
|
+
> Use the forward slash for ruby code comments - anything after it won't get displayed in the final render.
|
94
107
|
|
95
108
|
### Things to know
|
96
109
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
110
|
+
#### Standard Ruby syntax after `-` and `=`
|
111
|
+
`end` is not required but can be used if you don't want to omit it
|
112
|
+
|
113
|
+
#### Can put content on same line or nest it.
|
114
|
+
If you nest content (e.g. put it on the next line), start the line with a pipe (`|`) or a backtick (`` ` ``).
|
115
|
+
|
116
|
+
#### Indentation matters, but it's not as strict as Haml.
|
117
|
+
If you want to first indent 2 spaces, then 5 spaces, it's your choice. To nest markup you only need to indent by one space, the rest is gravy.
|
118
|
+
|
119
|
+
#### If your ruby code needs to use multiple lines, append a `\` at the end of the lines, for example:
|
120
|
+
`javascript_include_tag \
|
121
|
+
"jquery", \
|
122
|
+
"application"`
|
123
|
+
|
124
|
+
### Wrap attributes with delimiters
|
125
|
+
|
126
|
+
If a delimiter makes the syntax more readable for you,
|
127
|
+
you can use the characters {...}, (...), [...] to wrap the attributes.
|
128
|
+
|
129
|
+
body
|
130
|
+
h1(id="logo") = page_logo
|
131
|
+
h2[id="tagline" class="small tagline"] = page_tagline
|
103
132
|
|
104
133
|
### Add content to a tag
|
105
134
|
|
106
|
-
|
135
|
+
Either start on the same line as the tag
|
107
136
|
|
108
137
|
body
|
109
138
|
h1 id="headline" Welcome to my site.
|
110
139
|
|
111
|
-
|
140
|
+
Or nest it. __Note:__ Must use a pipe or a backtick (followed by a space) to escape processing
|
112
141
|
|
113
142
|
body
|
114
143
|
h1 id="headline"
|
@@ -116,12 +145,12 @@ __Please note that all line indicators must be followed by a space__
|
|
116
145
|
|
117
146
|
### Add content to a tag with code
|
118
147
|
|
119
|
-
|
148
|
+
Can make the call on the same line
|
120
149
|
|
121
150
|
body
|
122
151
|
h1 id="headline" = page_headline
|
123
152
|
|
124
|
-
|
153
|
+
Or nest it.
|
125
154
|
|
126
155
|
body
|
127
156
|
h1 id="headline"
|
@@ -129,9 +158,9 @@ __Please note that all line indicators must be followed by a space__
|
|
129
158
|
|
130
159
|
### Shortcut form for `id` and `class` attributes
|
131
160
|
|
132
|
-
|
133
|
-
|
134
|
-
|
161
|
+
Similarly to Haml, you can specify the `id` and `class`
|
162
|
+
attributes in the following shortcut form
|
163
|
+
Note: the shortcut form does not evaluate ruby code
|
135
164
|
|
136
165
|
body
|
137
166
|
h1#headline
|
@@ -141,7 +170,7 @@ __Please note that all line indicators must be followed by a space__
|
|
141
170
|
.content
|
142
171
|
= show_content
|
143
172
|
|
144
|
-
|
173
|
+
this is the same as
|
145
174
|
|
146
175
|
body
|
147
176
|
h1 id="headline"
|
@@ -151,37 +180,36 @@ __Please note that all line indicators must be followed by a space__
|
|
151
180
|
div class="content"
|
152
181
|
= show_content
|
153
182
|
|
154
|
-
### Wrap attributes with parens
|
155
|
-
|
156
|
-
# If parens make the syntax more readable for you
|
157
|
-
|
158
|
-
body
|
159
|
-
h1(id="tagline" class="small tagline") = page_tagline
|
160
|
-
|
161
183
|
### Set an attribute's value with a method
|
162
184
|
|
163
|
-
|
185
|
+
* Alternative 1: Use parentheses (), {}, []. The code in the parentheses will be evaluated.
|
186
|
+
* Alternative 2: If the code doesn't contain any spaces you can omit the parentheses.
|
187
|
+
* Alternative 3: Use standard ruby interpolation #{}
|
188
|
+
|
189
|
+
Attributes will always be html escaped.
|
164
190
|
|
165
191
|
body
|
166
192
|
table
|
167
193
|
- for user in users do
|
168
|
-
|
194
|
+
td id="user_#{user.id}" class=user.role
|
195
|
+
a href=user_action(user, :edit) Edit #{user.name}
|
196
|
+
a href={path_to_user user} = user.name
|
169
197
|
|
170
|
-
###
|
198
|
+
### Evaluate ruby code in text
|
171
199
|
|
172
|
-
|
200
|
+
Use standard Ruby interpolation. The text will always be html escaped.
|
173
201
|
|
174
202
|
body
|
175
203
|
h1 Welcome #{current_user.name} to the show.
|
176
204
|
|
177
|
-
|
205
|
+
To escape the interpolation (i.e. render as is)
|
178
206
|
|
179
207
|
body
|
180
208
|
h1 Welcome \#{current_user.name} to the show.
|
181
209
|
|
182
|
-
### Skip the escaping
|
210
|
+
### Skip the html escaping
|
183
211
|
|
184
|
-
|
212
|
+
Use a double equal sign
|
185
213
|
|
186
214
|
body
|
187
215
|
h1 id="headline"
|
@@ -189,79 +217,98 @@ __Please note that all line indicators must be followed by a space__
|
|
189
217
|
|
190
218
|
### Treat multiple lines of code as text that should bypass parsing
|
191
219
|
|
192
|
-
|
193
|
-
|
194
|
-
|
220
|
+
Use a pipe (`|`) or backtick (`` ` ``) to start the escape.
|
221
|
+
Each following line that is indented greater than
|
222
|
+
the backtick is copied over.
|
195
223
|
|
196
224
|
body
|
197
225
|
p
|
198
226
|
|
|
199
227
|
This is a test of the text block.
|
200
228
|
|
201
|
-
|
229
|
+
The parsed result of the above:
|
202
230
|
|
203
231
|
<body><p>This is a test of the text block.</p></body>
|
204
232
|
|
205
|
-
|
206
|
-
|
233
|
+
The left margin is set at the indent of the backtick + one space.
|
234
|
+
Any additional spaces will be copied over.
|
207
235
|
|
208
236
|
body
|
209
237
|
p
|
210
|
-
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
And so on...
|
238
|
+
| This line is on the left margin.
|
239
|
+
This line will have one space in front of it.
|
240
|
+
This line will have two spaces in front of it.
|
241
|
+
And so on...
|
215
242
|
|
216
243
|
### Add code comments
|
217
244
|
|
218
|
-
|
219
|
-
|
245
|
+
Use a forward slash for ruby code comments
|
246
|
+
|
220
247
|
body
|
221
248
|
p
|
222
249
|
/ This line won't get displayed.
|
223
250
|
/ Neither does this line.
|
224
|
-
|
225
|
-
|
226
|
-
|
251
|
+
|
252
|
+
The parsed result of the above:
|
253
|
+
|
227
254
|
<body><p></p></body>
|
228
255
|
|
229
256
|
|
230
257
|
## Benchmarks
|
231
258
|
|
232
|
-
#
|
233
|
-
|
234
|
-
|
235
|
-
erb 0.
|
236
|
-
erubis 0.
|
237
|
-
fast erubis 0.
|
238
|
-
slim
|
239
|
-
haml
|
240
|
-
haml ugly
|
241
|
-
erb (cached) 0.
|
242
|
-
erubis (cached) 0.
|
243
|
-
fast erubis (cached) 0.
|
244
|
-
slim (cached) 0.
|
245
|
-
haml (cached) 0.
|
246
|
-
haml ugly (cached) 0.
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
haml
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
haml
|
262
|
-
|
259
|
+
# OS X 10.6 + Ruby 1.9.2
|
260
|
+
|
261
|
+
user system total real
|
262
|
+
erb 0.410000 0.010000 0.420000 ( 0.421608)
|
263
|
+
erubis 0.350000 0.000000 0.350000 ( 0.357187)
|
264
|
+
fast erubis 0.340000 0.000000 0.340000 ( 0.351943)
|
265
|
+
slim 2.360000 0.020000 2.380000 ( 2.495331)
|
266
|
+
haml 2.970000 0.010000 2.980000 ( 3.023121)
|
267
|
+
haml ugly 2.870000 0.010000 2.880000 ( 2.968662)
|
268
|
+
erb (cached) 0.150000 0.000000 0.150000 ( 0.149980)
|
269
|
+
erubis (cached) 0.120000 0.000000 0.120000 ( 0.122935)
|
270
|
+
fast erubis (cached) 0.100000 0.000000 0.100000 ( 0.105832)
|
271
|
+
slim (cached) 0.020000 0.000000 0.020000 ( 0.020290)
|
272
|
+
haml (cached) 0.330000 0.000000 0.330000 ( 0.335519)
|
273
|
+
haml ugly (cached) 0.280000 0.000000 0.280000 ( 0.286695)
|
274
|
+
|
275
|
+
# OS X 10.6 + REE 1.8.7
|
276
|
+
|
277
|
+
user system total real
|
278
|
+
erb 0.440000 0.010000 0.450000 ( 0.463941)
|
279
|
+
erubis 0.310000 0.000000 0.310000 ( 0.322083)
|
280
|
+
fast erubis 0.310000 0.000000 0.310000 ( 0.309852)
|
281
|
+
slim 2.420000 0.020000 2.440000 ( 2.470208)
|
282
|
+
haml 2.990000 0.020000 3.010000 ( 3.040942)
|
283
|
+
haml ugly 2.900000 0.020000 2.920000 ( 3.101786)
|
284
|
+
erb (cached) 0.080000 0.000000 0.080000 ( 0.079252)
|
285
|
+
erubis (cached) 0.070000 0.000000 0.070000 ( 0.066370)
|
286
|
+
fast erubis (cached) 0.060000 0.000000 0.060000 ( 0.062001)
|
287
|
+
slim (cached) 0.030000 0.000000 0.030000 ( 0.023835)
|
288
|
+
haml (cached) 0.270000 0.010000 0.280000 ( 0.279409)
|
289
|
+
haml ugly (cached) 0.210000 0.000000 0.210000 ( 0.221059)
|
290
|
+
|
291
|
+
# OSX 10.6 + JRuby 1.5.3
|
292
|
+
|
293
|
+
user system total real
|
294
|
+
erb 0.970000 0.000000 0.970000 ( 0.970000)
|
295
|
+
erubis 0.672000 0.000000 0.672000 ( 0.672000)
|
296
|
+
fast erubis 0.624000 0.000000 0.624000 ( 0.624000)
|
297
|
+
slim 2.694000 0.000000 2.694000 ( 2.694000)
|
298
|
+
haml 3.368000 0.000000 3.368000 ( 3.368000)
|
299
|
+
haml ugly 3.462000 0.000000 3.462000 ( 3.462000)
|
300
|
+
erb (cached) 0.736000 0.000000 0.736000 ( 0.736000)
|
301
|
+
erubis (cached) 0.413000 0.000000 0.413000 ( 0.413000)
|
302
|
+
fast erubis (cached) 0.340000 0.000000 0.340000 ( 0.340000)
|
303
|
+
slim (cached) 0.069000 0.000000 0.069000 ( 0.069000)
|
304
|
+
haml (cached) 1.001000 0.000000 1.001000 ( 1.001000)
|
305
|
+
haml ugly (cached) 0.763000 0.000000 0.763000 ( 0.763000)
|
263
306
|
|
264
307
|
## Authors
|
265
308
|
|
266
309
|
* [Andrew Stone](http://github.com/stonean)
|
267
310
|
* [Fred Wu](http://github.com/fredwu)
|
311
|
+
|
312
|
+
## Discuss
|
313
|
+
|
314
|
+
[Google Group](http://groups.google.com/group/slim-template)
|
data/Rakefile
CHANGED
@@ -1,44 +1,16 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
require File.join(File.dirname(__FILE__), "lib", "slim")
|
5
|
-
|
6
1
|
begin
|
7
|
-
require '
|
8
|
-
|
9
|
-
|
10
|
-
gem.version = Slim.version
|
11
|
-
gem.rubyforge_project = gem.name
|
12
|
-
gem.summary = "Slim is a template language."
|
13
|
-
gem.description = "Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic."
|
14
|
-
gem.homepage = "http://github.com/stonean/slim"
|
15
|
-
gem.authors = ["Andrew Stone", "Fred Wu"]
|
16
|
-
gem.email = ["andy@stonean.com", "ifredwu@gmail.com"]
|
17
|
-
gem.files = ['*', 'lib/**/*', 'test/**/*']
|
18
|
-
gem.add_dependency 'escape_utils'
|
19
|
-
gem.add_development_dependency 'rake'
|
20
|
-
gem.add_development_dependency 'jeweler'
|
21
|
-
gem.add_development_dependency 'haml'
|
22
|
-
gem.add_development_dependency 'erubis'
|
23
|
-
end
|
24
|
-
Jeweler::GemcutterTasks.new
|
25
|
-
rescue LoadError
|
26
|
-
puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
|
2
|
+
require 'bundler'
|
3
|
+
Bundler::GemHelper.install_tasks
|
4
|
+
rescue Exception => e
|
27
5
|
end
|
28
6
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
rescue LoadError
|
36
|
-
task :yard do
|
37
|
-
abort "YARD is not available. In order to run yard, you must: gem install yard"
|
38
|
-
end
|
7
|
+
require 'rake/testtask'
|
8
|
+
|
9
|
+
desc 'Run Slim benchmarks! (Default :iterations is 1000)'
|
10
|
+
task :bench, :iterations do |t, args|
|
11
|
+
ruby("benchmarks/run.rb #{args[:iterations]}")
|
39
12
|
end
|
40
13
|
|
41
|
-
require 'rake/testtask'
|
42
14
|
Rake::TestTask.new(:test) do |test|
|
43
15
|
test.libs << 'lib' << 'test'
|
44
16
|
test.pattern = 'test/**/test_*.rb'
|
@@ -48,7 +20,7 @@ end
|
|
48
20
|
begin
|
49
21
|
require 'rcov/rcovtask'
|
50
22
|
Rcov::RcovTask.new do |test|
|
51
|
-
test.libs << 'test'
|
23
|
+
test.libs << 'lib' << 'test'
|
52
24
|
test.pattern = 'test/**/test_*.rb'
|
53
25
|
test.verbose = true
|
54
26
|
end
|