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.
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ *.swp
2
+ pkg/*
3
+ *.gem
4
+ .bundle
5
+ readme.html
6
+ .yardoc/
7
+ doc/
8
+ coverage/
data/Gemfile CHANGED
@@ -1,8 +1,3 @@
1
1
  source :rubygems
2
2
 
3
- gemspec
4
-
5
- group :development do
6
- gem 'slim', :path => File.dirname(__FILE__)
7
- gem 'minitest' if RUBY_VERSION < '1.9'
8
- end
3
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,8 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slim (0.6.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.8)
14
- gemcutter (0.6.1)
15
- git (1.2.5)
16
- haml (3.0.21)
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
- rubyforge (2.0.4)
24
- json_pure (>= 1.1.7)
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
- jeweler
34
- rake
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 script is provided so you could test it yourself (`./benchmarks/run.rb`).
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
- * The pipe tells Slim to just copy the line. It essentially escapes any processing.
82
- * `
83
- * _Same as the pipe ('|')._
84
- * -
85
- * The dash denotes control code (similar to Haml). Examples of control code are loops and conditionals.
86
- * =
87
- * The equal sign tells Slim it's a Ruby call that produces output to add to the buffer (similar to Erb and Haml).
88
- * ==
89
- * Same as the single equal sign, but does not go through the escape_html method.
90
- * !
91
- * This is a directive. Most common example: `! doctype html # renders <!doctype html>`
92
- * /
93
- * Use the forward slash for ruby code comments - anything after it won't get displayed in the final render.
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
- * Standard Ruby syntax after '-' and '='
98
- * __end__ is not required
99
- * Can put content on same line or nest it.
100
- * If you nest content (e.g. put it on the next line), start the line with a pipe ('|') or a backtick ('`').
101
- * Indentation matters, but it's not as strict as Haml.
102
- * 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.
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
- # Either start on the same line as the tag
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
- # Or nest it. __Note:__ Must use a pipe or a backtick (followed by a space) to escape processing
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
- # Can make the call on the same line
148
+ Can make the call on the same line
120
149
 
121
150
  body
122
151
  h1 id="headline" = page_headline
123
152
 
124
- # Or nest it.
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
- # Similarly to Haml, you can specify the `id` and `class`
133
- # attributes in the following shortcut form
134
- # Note: the shortcut form does not evaluate ruby code
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
- # this is the same as
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
- # Use standard Ruby interpolation.
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
- tr id="user_#{user.id}"
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
- ### Call a method in content
198
+ ### Evaluate ruby code in text
171
199
 
172
- # Use standard Ruby interpolation.
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
- # To escape the interpolation (i.e. render as is)
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
- # Use a double equal sign
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
- # Use a pipe ('|') or backtick ('`') to start the escape.
193
- # Each following line that is indented greater than
194
- # the backtick is copied over.
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
- # The parsed result of the above:
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
- # The left margin is set at the indent of the backtick + one space.
206
- # Any additional spaces will be copied over.
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
- This line is on the left margin.
212
- This line will have one space in front of it.
213
- This line will have two spaces in front of it.
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
- # Use a forward slash for ruby code comments
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
- # The parsed result of the above:
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
- # Ubuntu 10.4 + Ruby 1.9.2
233
-
234
- Rehearsal --------------------------------------------------------
235
- erb 0.580000 0.010000 0.590000 ( 0.611149)
236
- erubis 0.480000 0.000000 0.480000 ( 0.506241)
237
- fast erubis 0.480000 0.010000 0.490000 ( 0.499427)
238
- slim 0.640000 0.000000 0.640000 ( 0.667160)
239
- haml 4.140000 0.000000 4.140000 ( 4.221195)
240
- haml ugly 3.960000 0.000000 3.960000 ( 4.018103)
241
- erb (cached) 0.200000 0.000000 0.200000 ( 0.208529)
242
- erubis (cached) 0.160000 0.000000 0.160000 ( 0.167134)
243
- fast erubis (cached) 0.140000 0.000000 0.140000 ( 0.152149)
244
- slim (cached) 0.150000 0.000000 0.150000 ( 0.159058)
245
- haml (cached) 0.450000 0.010000 0.460000 ( 0.462814)
246
- haml ugly (cached) 0.370000 0.000000 0.370000 ( 0.387312)
247
- ---------------------------------------------- total: 11.780000sec
248
-
249
- user system total real
250
- erb 0.560000 0.010000 0.570000 ( 0.574373)
251
- erubis 0.480000 0.000000 0.480000 ( 0.501512)
252
- fast erubis 0.470000 0.000000 0.470000 ( 0.481918)
253
- slim 0.610000 0.000000 0.610000 ( 0.612794)
254
- haml 3.930000 0.010000 3.940000 ( 3.939419)
255
- haml ugly 3.790000 0.010000 3.800000 ( 3.798528)
256
- erb (cached) 0.190000 0.000000 0.190000 ( 0.188593)
257
- erubis (cached) 0.160000 0.000000 0.160000 ( 0.159869)
258
- fast erubis (cached) 0.140000 0.000000 0.140000 ( 0.135476)
259
- slim (cached) 0.150000 0.000000 0.150000 ( 0.153698)
260
- haml (cached) 0.430000 0.000000 0.430000 ( 0.436980)
261
- haml ugly (cached) 0.370000 0.000000 0.370000 ( 0.372770)
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 'jeweler'
8
- Jeweler::Tasks.new do |gem|
9
- gem.name = "slim"
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
- begin
30
- require 'yard'
31
- YARD::Rake::YardocTask.new do |t|
32
- t.files = FileList['lib/**/*.rb']
33
- t.options = ['-r'] # optional
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