slim 1.3.9 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -8
- data/.travis.yml +8 -7
- data/CHANGES +35 -0
- data/Gemfile +9 -9
- data/README.md +94 -176
- data/Rakefile +7 -14
- data/benchmarks/run-benchmarks.rb +9 -37
- data/doc/logic_less.md +140 -0
- data/doc/translator.md +31 -0
- data/lib/slim.rb +3 -1
- data/lib/slim/code_attributes.rb +20 -20
- data/lib/slim/command.rb +16 -6
- data/lib/slim/do_inserter.rb +33 -0
- data/lib/slim/embedded.rb +0 -6
- data/lib/slim/end_inserter.rb +2 -2
- data/lib/slim/engine.rb +9 -23
- data/lib/slim/erb_converter.rb +14 -0
- data/lib/slim/filter.rb +2 -2
- data/lib/slim/logic_less/context.rb +8 -0
- data/lib/slim/logic_less/filter.rb +12 -11
- data/lib/slim/parser.rb +57 -113
- data/lib/slim/splat/builder.rb +79 -0
- data/lib/slim/splat/filter.rb +93 -0
- data/lib/slim/version.rb +1 -1
- data/slim.gemspec +1 -1
- data/test/core/helper.rb +1 -3
- data/test/core/test_code_blocks.rb +51 -0
- data/test/core/test_code_evaluation.rb +4 -12
- data/test/core/test_embedded_engines.rb +18 -44
- data/test/core/test_encoding.rb +8 -1
- data/test/core/test_erb_converter.rb +67 -0
- data/test/core/test_html_attributes.rb +19 -25
- data/test/core/test_html_escaping.rb +10 -2
- data/test/core/test_html_structure.rb +6 -6
- data/test/core/test_parser_errors.rb +1 -1
- data/test/core/test_ruby_errors.rb +2 -6
- data/test/core/test_thread_options.rb +4 -4
- data/test/core/test_unicode.rb +18 -0
- data/test/literate/TESTS.md +193 -34
- data/test/logic_less/test_logic_less.rb +17 -0
- data/test/rails/app/controllers/application_controller.rb +0 -1
- data/test/rails/app/controllers/entries_controller.rb +5 -0
- data/test/rails/app/controllers/slim_controller.rb +3 -0
- data/test/rails/app/models/entry.rb +16 -0
- data/test/rails/app/views/entries/edit.html.slim +3 -0
- data/test/rails/app/views/slim/form_for.html.slim +2 -0
- data/test/rails/app/views/slim/xml.slim +1 -0
- data/test/rails/config/application.rb +2 -2
- data/test/rails/config/environments/test.rb +1 -1
- data/test/rails/config/routes.rb +1 -1
- data/test/rails/test/helper.rb +0 -3
- data/test/rails/test/test_slim.rb +13 -8
- data/test/translator/test_translator.rb +13 -2
- metadata +17 -14
- data/lib/slim/splat_attributes.rb +0 -113
- data/test/rails/app/controllers/parents_controller.rb +0 -85
- data/test/rails/app/models/child.rb +0 -3
- data/test/rails/app/models/parent.rb +0 -4
- data/test/rails/app/views/parents/_form.html.slim +0 -8
- data/test/rails/app/views/parents/edit.html.slim +0 -2
- data/test/rails/app/views/parents/new.html.slim +0 -2
- data/test/rails/app/views/parents/show.html.slim +0 -5
- data/test/rails/config/database.yml +0 -4
- data/test/rails/db/migrate/20101220223037_parents_and_children.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4a9425fd0b4b76c20a920f76d2d5de37e0f411c
|
4
|
+
data.tar.gz: 627435a655daa4b54f1ed18baf5a58302f1d5fc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 522bfc01a26bc8ce325599b25cd85de310c97d5d40b3cc5fb84b8b1f3fae592bb1ea0ed2a6738156082d65e77ee1afec9ce5d08ab34fb9d5d27fe86290b36160
|
7
|
+
data.tar.gz: 2e784025e8bc003385e120990660e449d0950acee036219ca73dc289c932b39876d782cd13f8972a91f85ed41439ed99ca3b8222f2eff7cde8fe65a128485202
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -9,12 +9,14 @@ rvm:
|
|
9
9
|
- rbx-18mode
|
10
10
|
- rbx-19mode
|
11
11
|
env:
|
12
|
-
- "TASK=test:core_and_plugins"
|
12
|
+
- "TASK=test:core_and_plugins TILT=master"
|
13
|
+
- "TASK=test:core_and_plugins TILT=1.3.4"
|
14
|
+
- "TASK=test:core_and_plugins TILT=1.4.1"
|
13
15
|
- "TASK=test:rails RAILS=master"
|
14
16
|
- "TASK=test:rails RAILS=3.0.20"
|
15
17
|
- "TASK=test:rails RAILS=3.1.12"
|
16
18
|
- "TASK=test:rails RAILS=3.2.13"
|
17
|
-
- "TASK=test:rails RAILS=4.0.0.
|
19
|
+
- "TASK=test:rails RAILS=4.0.0.rc1"
|
18
20
|
- "TASK=test:sinatra SINATRA=master"
|
19
21
|
- "TASK=test:sinatra SINATRA=1.3.6"
|
20
22
|
- "TASK=test:sinatra SINATRA=1.4.2"
|
@@ -30,16 +32,15 @@ matrix:
|
|
30
32
|
- rvm: rbx-18mode
|
31
33
|
env: "TASK=test:rails RAILS=master"
|
32
34
|
- rvm: 1.8.7
|
33
|
-
env: "TASK=test:rails RAILS=4.0.0.
|
35
|
+
env: "TASK=test:rails RAILS=4.0.0.rc1"
|
34
36
|
- rvm: jruby-18mode
|
35
|
-
env: "TASK=test:rails RAILS=4.0.0.
|
37
|
+
env: "TASK=test:rails RAILS=4.0.0.rc1"
|
36
38
|
- rvm: rbx-18mode
|
37
|
-
env: "TASK=test:rails RAILS=4.0.0.
|
39
|
+
env: "TASK=test:rails RAILS=4.0.0.rc1"
|
38
40
|
allow_failures:
|
41
|
+
- env: "TASK=test:core_and_plugins TILT=master"
|
39
42
|
- env: "TASK=test:rails RAILS=master"
|
40
|
-
- env: "TASK=test:rails RAILS=4.0.0.beta1"
|
41
43
|
- env: "TASK=test:sinatra SINATRA=master"
|
42
|
-
- env: "TASK=test:rails RAILS=3.0.20"
|
43
44
|
rvm: 2.0.0
|
44
45
|
- rvm: ruby-head
|
45
46
|
# Rails master needs newest bundler
|
data/CHANGES
CHANGED
@@ -1,3 +1,38 @@
|
|
1
|
+
2.0.0
|
2
|
+
|
3
|
+
* IMPORTANT: Backward incompatible syntax change: '{...}' and '[...]' are not
|
4
|
+
allowed as ruby attribute wrappers anymore. Use parentheses '(...)'
|
5
|
+
if you want to wrap code with spaces. This allows to write arrays and hashes directly.
|
6
|
+
Old:
|
7
|
+
div id={'obj' + name} data=({:a => 1, :b => 2}) class=['alpha', 'beta']
|
8
|
+
New:
|
9
|
+
div id=('obj' + name) data={:a => 1, :b => 2} class=['alpha', 'beta']
|
10
|
+
* Quoted attributes are escaped by default
|
11
|
+
Old:
|
12
|
+
a href='http://slim-lang.com/?a=1&b=2'
|
13
|
+
New:
|
14
|
+
a href='http://slim-lang.com/?a=1&b=2'
|
15
|
+
a href=='http://slim-lang.com/?a=1&b=2'
|
16
|
+
You can always disable escaping completly by using :disable_escape if you don't want to write '=='.
|
17
|
+
* Added hyphenation support for data attributes (Option :hyphen_attrs)
|
18
|
+
Example: div data={key1_key2: 2, key1: {key3: 3}} will render as '<div data-key1-key2="2" data-key1-key3="3"></div>'
|
19
|
+
* Removed deprecated options:
|
20
|
+
- :escape_quoted_attrs
|
21
|
+
- :remove_empty_attrs
|
22
|
+
- :chain
|
23
|
+
- :attr_wrapper (renamed to :attr_quote)
|
24
|
+
- :attr_delimiter (renamed to :merge_attrs)
|
25
|
+
- Slim::LogicLess :wrapped dictionary
|
26
|
+
- Slim::Parser :shortcut string option
|
27
|
+
* Allow spaces around attributes, e.g 'a [ href = url ] text' and 'a href = url text'
|
28
|
+
* Add unicode support for tags and attributes (Issue #212)
|
29
|
+
* Generate missing `do` keywords for code blocks (see #342)
|
30
|
+
* Logic-less: Add keyword `self` for string access
|
31
|
+
* Added Slim::ERBConverter, require 'slim/erb_converter'
|
32
|
+
* Added option '-e' for ERB conversion to slimrb
|
33
|
+
* Add syntax for trailing or leading whitespace after tag, e.g. input>, input<
|
34
|
+
* Add syntax for trailing or leading whitespace after output, e.g. =>, =<
|
35
|
+
|
1
36
|
1.3.8
|
2
37
|
|
3
38
|
* Disable some superflous deprecation warnings
|
data/Gemfile
CHANGED
@@ -8,20 +8,20 @@ elsif ENV['TEMPLE_PATH']
|
|
8
8
|
gem 'temple', :path => ENV['TEMPLE_PATH']
|
9
9
|
end
|
10
10
|
|
11
|
+
if ENV['TILT']
|
12
|
+
if ENV['TILT'] == 'master'
|
13
|
+
gem 'tilt', :github => 'rtomayko/tilt'
|
14
|
+
else
|
15
|
+
gem 'tilt', "= #{ENV['TILT']}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
11
19
|
if ENV['RAILS']
|
12
20
|
if ENV['RAILS'] == 'master'
|
13
21
|
gem 'rails', :github => 'rails/rails'
|
14
22
|
else
|
15
23
|
gem 'rails', "= #{ENV['RAILS']}"
|
16
24
|
end
|
17
|
-
|
18
|
-
if defined?(JRUBY_VERSION)
|
19
|
-
gem 'jdbc-sqlite3'
|
20
|
-
gem 'activerecord-jdbc-adapter'
|
21
|
-
gem 'activerecord-jdbcsqlite3-adapter'
|
22
|
-
else
|
23
|
-
gem 'sqlite3'
|
24
|
-
end
|
25
25
|
end
|
26
26
|
|
27
27
|
if ENV['SINATRA']
|
@@ -35,11 +35,11 @@ end
|
|
35
35
|
|
36
36
|
gem 'rake', '>= 0.8.7'
|
37
37
|
gem 'sass', '>= 3.1.0'
|
38
|
-
gem 'minitest'
|
39
38
|
gem 'kramdown'
|
40
39
|
gem 'creole'
|
41
40
|
gem 'builder'
|
42
41
|
gem 'asciidoctor'
|
42
|
+
gem 'minitest', '~> 4.7.4'
|
43
43
|
|
44
44
|
if ENV['TASK'] == 'bench'
|
45
45
|
gem 'erubis'
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Slim
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/slim.png)](http://rubygems.org/gems/slim) [![Build Status](https://secure.travis-ci.org/slim-template/slim.png?branch=master)](http://travis-ci.org/slim-template/slim) [![Dependency Status](https://gemnasium.com/slim-template/slim.png?travis)](https://gemnasium.com/slim-template/slim) [![Code Climate](https://codeclimate.com/
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/slim.png)](http://rubygems.org/gems/slim) [![Build Status](https://secure.travis-ci.org/slim-template/slim.png?branch=master)](http://travis-ci.org/slim-template/slim) [![Dependency Status](https://gemnasium.com/slim-template/slim.png?travis)](https://gemnasium.com/slim-template/slim) [![Code Climate](https://codeclimate.com/github/slim-template/slim.png)](https://codeclimate.com/github/slim-template/slim)
|
4
4
|
|
5
5
|
Slim is a template language whose goal is to reduce the view syntax to the essential parts without becoming cryptic. It started as an exercise to see how much could be removed from a standard html template (<, >, closing tags, etc...). As more people took an interest in Slim, the functionality grew and so did the flexibility of the syntax.
|
6
6
|
|
@@ -20,14 +20,22 @@ A short list of the features...
|
|
20
20
|
* Comparable speed to ERB/Erubis
|
21
21
|
* Streaming support in Rails
|
22
22
|
* Supported by all major frameworks (Rails, Sinatra, ...)
|
23
|
+
* Full Unicode support for tags and attributes on Ruby 1.9
|
23
24
|
* Embedded engines like Markdown and Textile
|
24
25
|
|
25
|
-
##
|
26
|
+
## Links
|
27
|
+
|
28
|
+
* Source: <http://github.com/slim-template/slim>
|
29
|
+
* Bugs: <http://github.com/slim-template/slim/issues>
|
30
|
+
* List: <http://groups.google.com/group/slim-template>
|
31
|
+
* API documentation:
|
32
|
+
* Latest Gem: <http://rubydoc.info/gems/slim/frames>
|
33
|
+
* GitHub master: <http://rubydoc.info/github/slim-template/slim/master/frames>
|
26
34
|
|
27
|
-
|
35
|
+
## Upgrade to version 2.0
|
28
36
|
|
29
|
-
If you are already using Slim 1.
|
30
|
-
upgrade to Slim 1.3.
|
37
|
+
If you are already using Slim 1.x and want to upgrade to the newest version 2.0, you should at first
|
38
|
+
upgrade to at least Slim 1.3.8 which will emit warnings for deprecated features. This way you can easily
|
31
39
|
see if your application is already Slim 2.0 compliant!
|
32
40
|
|
33
41
|
Slim 2.0 removes deprecated features from the 1.3 series and cleans up some minor
|
@@ -61,7 +69,7 @@ There is also some development in logic-less engines (e.g. [Mustache](https://gi
|
|
61
69
|
|
62
70
|
Slim was born to bring a minimalist syntax approach with speed. If people chose not to use Slim, it would not be because of speed.
|
63
71
|
|
64
|
-
___Yes, Slim is speedy!___ Benchmarks are done for every commit at
|
72
|
+
___Yes, Slim is speedy!___ Benchmarks are done for every commit at <http://travis-ci.org/#!/slim-template/slim>.
|
65
73
|
Don't trust the numbers? That's as it should be. Please try the benchmark rake task yourself!
|
66
74
|
|
67
75
|
### How to start?
|
@@ -92,11 +100,11 @@ Here's a quick example to demonstrate what a Slim template looks like:
|
|
92
100
|
#content
|
93
101
|
p This example shows you how a basic Slim file looks like.
|
94
102
|
|
95
|
-
|
103
|
+
== yield
|
96
104
|
|
97
105
|
- if items.any?
|
98
106
|
table#items
|
99
|
-
- for item in items
|
107
|
+
- for item in items
|
100
108
|
tr
|
101
109
|
td.name = item.name
|
102
110
|
td.price = item.price
|
@@ -105,7 +113,7 @@ Here's a quick example to demonstrate what a Slim template looks like:
|
|
105
113
|
Thank you!
|
106
114
|
|
107
115
|
div id="footer"
|
108
|
-
|
116
|
+
== render 'footer'
|
109
117
|
| Copyright © #{@year} #{@author}
|
110
118
|
|
111
119
|
Indentation matters, but the indentation depth can be chosen as you like. 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.
|
@@ -131,10 +139,10 @@ Each following line that is indented greater than the pipe is copied over.
|
|
131
139
|
|
132
140
|
body
|
133
141
|
p
|
134
|
-
|
|
135
|
-
|
136
|
-
|
137
|
-
|
142
|
+
| This line is on the left margin.
|
143
|
+
This line will have one space in front of it.
|
144
|
+
This line will have two spaces in front of it.
|
145
|
+
And so on...
|
138
146
|
|
139
147
|
You can also embed html in the text line
|
140
148
|
|
@@ -175,22 +183,20 @@ If your ruby code needs to use multiple lines, append a backslash `\` at the end
|
|
175
183
|
The equal sign tells Slim it's a Ruby call that produces output to add to the buffer. If your ruby code needs to use multiple lines, append a backslash `\` at the end of the lines, for example:
|
176
184
|
|
177
185
|
= javascript_include_tag \
|
178
|
-
"jquery",
|
186
|
+
"jquery",
|
179
187
|
"application"
|
180
188
|
|
181
|
-
If your line ends with comma `,` (e.g because of a method call) you don't need the additional backslash before the linebreak.
|
189
|
+
If your line ends with comma `,` (e.g because of a method call) you don't need the additional backslash before the linebreak. For trailing or leading whitespace the modifiers `>` and `<` are supported.
|
182
190
|
|
183
|
-
|
184
|
-
|
185
|
-
Same as the single equal sign (`=`), except that it adds a trailing white space.
|
191
|
+
* Output with trailing white space `=>`. Same as the single equal sign (`=`), except that it adds a trailing white space. The legacy syntax `='` is also supported.
|
192
|
+
* Output with leading white space `=<`. Same as the single equal sign (`=`), except that it adds a leading white space.
|
186
193
|
|
187
194
|
### Output without HTML escaping `==`
|
188
195
|
|
189
|
-
Same as the single equal sign (`=`), but does not go through the `escape_html` method.
|
190
|
-
|
191
|
-
### Output without HTML escaping and trailing ws `=='`
|
196
|
+
Same as the single equal sign (`=`), but does not go through the `escape_html` method. For trailing or leading whitespace the modifiers `>` and `<` are supported.
|
192
197
|
|
193
|
-
Same as the double equal sign (`==`), except that it adds a trailing white space.
|
198
|
+
* Output without HTML escaping and trailing white space `==>`. Same as the double equal sign (`==`), except that it adds a trailing white space. The legacy syntax `=='` is also supported.
|
199
|
+
* Output without HTML escaping and leading white space `==<`. Same as the double equal sign (`==`), except that it adds a leading white space.
|
194
200
|
|
195
201
|
### Code comment `/`
|
196
202
|
|
@@ -288,6 +294,22 @@ You can close tags explicitly by appending a trailing `/`.
|
|
288
294
|
Note, that this is usually not necessary since the standard html
|
289
295
|
tags (img, br, ...) are closed automatically.
|
290
296
|
|
297
|
+
### Trailing and leading whitespace (`<`, `>`)
|
298
|
+
|
299
|
+
You can force Slim to add a trailing whitespace after a tag by adding a >.
|
300
|
+
|
301
|
+
a> href='url1' Link1
|
302
|
+
a> href='url2' Link2
|
303
|
+
|
304
|
+
You can add a leading whitespace by adding <.
|
305
|
+
|
306
|
+
a< href='url1' Link1
|
307
|
+
a< href='url2' Link2
|
308
|
+
|
309
|
+
You can also combine both.
|
310
|
+
|
311
|
+
a<> href='url1' Link1
|
312
|
+
|
291
313
|
### Inline tags
|
292
314
|
|
293
315
|
Sometimes you may want to be a little more compact and inline the tags.
|
@@ -309,7 +331,7 @@ Either start on the same line as the tag
|
|
309
331
|
body
|
310
332
|
h1 id="headline" Welcome to my site.
|
311
333
|
|
312
|
-
Or nest it. You must use a pipe or
|
334
|
+
Or nest it. You must use a pipe or an apostrophe to escape processing
|
313
335
|
|
314
336
|
body
|
315
337
|
h1 id="headline"
|
@@ -350,6 +372,11 @@ If you wrap the attributes, you can spread them across multiple lines:
|
|
350
372
|
h2[id="tagline"
|
351
373
|
class="small tagline"] = page_tagline
|
352
374
|
|
375
|
+
You may use spaces around the wrappers and assignments:
|
376
|
+
|
377
|
+
h1 id = "logo" = page_logo
|
378
|
+
h2 [ id = "tagline" ] = page_tagline
|
379
|
+
|
353
380
|
#### Quoted attributes
|
354
381
|
|
355
382
|
Example:
|
@@ -360,7 +387,7 @@ You can use text interpolation in the quoted attributes:
|
|
360
387
|
|
361
388
|
a href="http://#{url}" Goto the #{url}
|
362
389
|
|
363
|
-
The attribute value will be escaped
|
390
|
+
The attribute value will be escaped by default. Use == if you want to disable escaping in the attribute.
|
364
391
|
|
365
392
|
a href=="&"
|
366
393
|
|
@@ -372,14 +399,14 @@ You can break quoted attributes with backslash `\`
|
|
372
399
|
#### Ruby attributes
|
373
400
|
|
374
401
|
Write the ruby code directly after the `=`. If the code contains spaces you have to wrap
|
375
|
-
the code into parentheses `(...)
|
402
|
+
the code into parentheses `(...)`. You can also directly write hashes `{...}` and arrays `[...]`.
|
376
403
|
|
377
404
|
body
|
378
405
|
table
|
379
|
-
- for user in users
|
406
|
+
- for user in users
|
380
407
|
td id="user_#{user.id}" class=user.role
|
381
408
|
a href=user_action(user, :edit) Edit #{user.name}
|
382
|
-
a href=
|
409
|
+
a href=(path_to_user user) = user.name
|
383
410
|
|
384
411
|
The attribute value will be escaped by default. Use == if you want to disable escaping in the attribute.
|
385
412
|
|
@@ -527,6 +554,33 @@ This is the same as
|
|
527
554
|
div class="content"
|
528
555
|
= show_content
|
529
556
|
|
557
|
+
## Helpers and capturing
|
558
|
+
|
559
|
+
If you use Slim you might want to extend your template with some helpers. Assume that you have the following helper
|
560
|
+
|
561
|
+
~~~ruby
|
562
|
+
module Helpers
|
563
|
+
def headline
|
564
|
+
"<h1>#{yield}</h1>"
|
565
|
+
end
|
566
|
+
end
|
567
|
+
~~~
|
568
|
+
|
569
|
+
which can be used in Slim as follows
|
570
|
+
|
571
|
+
p
|
572
|
+
= headline do
|
573
|
+
' Hello
|
574
|
+
= user.name
|
575
|
+
|
576
|
+
The content in the `do` block is then captured automatically and passed to the helper via `yield`. As a syntactic
|
577
|
+
sugar you can omit the `do` keyword and write only
|
578
|
+
|
579
|
+
p
|
580
|
+
= headline
|
581
|
+
' Hello
|
582
|
+
= user.name
|
583
|
+
|
530
584
|
## Text interpolation
|
531
585
|
|
532
586
|
Use standard Ruby interpolation. The text will be html escaped by default.
|
@@ -644,14 +698,14 @@ There are a lot of them but the good thing is, that Slim checks the configuratio
|
|
644
698
|
<tr><td>Array<Symbol,String></td><td>:disable_engines</td><td>nil <i>(None disabled)</i></td><td>List of disabled embedded engines (blacklist)</td></tr>
|
645
699
|
<tr><td>Boolean</td><td>:disable_capture</td><td>false (true in Rails)</td><td>Disable capturing in blocks (blocks write to the default buffer </td></tr>
|
646
700
|
<tr><td>Boolean</td><td>:disable_escape</td><td>false</td><td>Disable automatic escaping of strings</td></tr>
|
647
|
-
<tr><td>Boolean</td><td>:escape_quoted_attrs</td><td>false</td><td>Escape quoted attributes. <b>Option is removed and activated per default in Slim 2.0!</b></td></tr>
|
648
701
|
<tr><td>Boolean</td><td>:use_html_safe</td><td>false (true in Rails)</td><td>Use String#html_safe? from ActiveSupport (Works together with :disable_escape)</td></tr>
|
649
702
|
<tr><td>Symbol</td><td>:format</td><td>:xhtml</td><td>HTML output format (Possible formats :xhtml, :html4, :html5, :html)</td></tr>
|
650
703
|
<tr><td>String</td><td>:attr_quote</td><td>'"'</td><td>Character to wrap attributes in html (can be ' or ")</td></tr>
|
651
704
|
<tr><td>Hash</td><td>:merge_attrs</td><td>\{'class' => ' '}</td><td>Joining character used if multiple html attributes are supplied (e.g. class="class1 class2")</td></tr>
|
705
|
+
<tr><td>Array<String></td><td>:hyphen_attrs</td><td>%w(data)</td><td>Attributes which will be hyphenated if a Hash is given (e.g. data={a:1,b:2} will render as data-a="1" data-b="2")</td></tr>
|
652
706
|
<tr><td>Boolean</td><td>:sort_attrs</td><td>true</td><td>Sort attributes by name</td></tr>
|
653
707
|
<tr><td>Symbol</td><td>:js_wrapper</td><td>nil</td><td>Wrap javascript by :comment, :cdata or :both. You can also :guess the wrapper based on :format.</td></tr>
|
654
|
-
<tr><td>Boolean</td><td>:pretty</td><td>false</td><td>Pretty
|
708
|
+
<tr><td>Boolean</td><td>:pretty</td><td>false</td><td>Pretty HTML indenting, only block level tags are indented <b>(This is slower!)</b></td></tr>
|
655
709
|
<tr><td>String</td><td>:indent</td><td>' '</td><td>Indentation string</td></tr>
|
656
710
|
<tr><td>Boolean</td><td>:streaming</td><td>false (true in Rails > 3.1)</td><td>Enable output streaming</td></tr>
|
657
711
|
<tr><td>Class</td><td>:generator</td><td>Temple::Generators::ArrayBuffer/RailsOutputBuffer</td><td>Temple code generator (default generator generates array buffer)</td></tr>
|
@@ -680,149 +734,10 @@ It is also possible to set options for superclasses like `Temple::Engine`. But t
|
|
680
734
|
|
681
735
|
## Plugins
|
682
736
|
|
683
|
-
|
684
|
-
|
685
|
-
<a name="logicless">Logic less mode</a> is inspired by [Mustache](https://github.com/defunkt/mustache). Logic less mode uses a dictionary object
|
686
|
-
e.g. a recursive hash tree which contains the dynamic content.
|
687
|
-
|
688
|
-
#### Conditional
|
689
|
-
|
690
|
-
If the object is not false or empty?, the content will show
|
691
|
-
|
692
|
-
- article
|
693
|
-
h1 = title
|
694
|
-
|
695
|
-
#### Inverted conditional
|
696
|
-
|
697
|
-
If the object is false or empty?, the content will show
|
698
|
-
|
699
|
-
-! article
|
700
|
-
p Sorry, article not found
|
701
|
-
|
702
|
-
#### Iteration
|
703
|
-
|
704
|
-
If the object is an array, the section will iterate
|
705
|
-
|
706
|
-
- articles
|
707
|
-
tr: td = title
|
708
|
-
|
709
|
-
#### Lambdas
|
710
|
-
|
711
|
-
Like mustache, Slim supports lambdas.
|
712
|
-
|
713
|
-
= person
|
714
|
-
= name
|
715
|
-
|
716
|
-
The lambda method could be defined like this
|
717
|
-
|
718
|
-
def lambda_method
|
719
|
-
"<div class='person'>#{yield(:name => 'Andrew')}</div>"
|
720
|
-
end
|
721
|
-
|
722
|
-
You can optionally pass one or more hashes to `yield`. If you pass multiple hashes, the block will be iterated as described above.
|
723
|
-
|
724
|
-
#### Dictionary access
|
725
|
-
|
726
|
-
Example code:
|
727
|
-
|
728
|
-
- article
|
729
|
-
h1 = title
|
730
|
-
|
731
|
-
The dictionary object is accessed in the order given by the `:dictionary_access`. Default order:
|
732
|
-
|
733
|
-
1. `:symbol` - If `article.respond_to?(:has_key?)` and `article.has_key?(:title)`, Slim will execute `article[:title]`
|
734
|
-
2. `:string` - If `article.respond_to?(:has_key?)` and `article.has_key?('title')`, Slim will execute `article['title']`
|
735
|
-
3. `:method` - If `article.respond_to?(:title)`, Slim will execute `article.send(:title)`
|
736
|
-
4. `:instance_variable` - If `article.instance_variable_defined?(@title)`, Slim will execute `article.instance_variable_get @title`
|
737
|
-
|
738
|
-
If all the above fails, Slim will try to resolve the title reference in the same order against the parent object. In this example, the parent would be the dictionary object you are rendering the template against.
|
737
|
+
Slim currently provides plugins for logic less mode and I18n. See the plugin documentation.
|
739
738
|
|
740
|
-
|
741
|
-
|
742
|
-
#### Logic less in Rails
|
743
|
-
|
744
|
-
Install:
|
745
|
-
|
746
|
-
$ gem install slim
|
747
|
-
|
748
|
-
Require:
|
749
|
-
|
750
|
-
gem 'slim', :require => 'slim/logic_less'
|
751
|
-
|
752
|
-
You might want to activate logic less mode only for a few actions, you should disable logic-less mode globally at first in the configuration
|
753
|
-
|
754
|
-
Slim::Engine.set_default_options :logic_less => false
|
755
|
-
|
756
|
-
and activate logic less mode per render call in your action
|
757
|
-
|
758
|
-
class Controller
|
759
|
-
def action
|
760
|
-
Slim::Engine.with_options(:logic_less => true) do
|
761
|
-
render
|
762
|
-
end
|
763
|
-
end
|
764
|
-
end
|
765
|
-
|
766
|
-
#### Logic less in Sinatra
|
767
|
-
|
768
|
-
Sinata has built-in support for Slim. All you have to do is require the logic less Slim plugin. This can be done in your config.ru:
|
769
|
-
|
770
|
-
require 'slim/logic_less'
|
771
|
-
|
772
|
-
You are then ready to rock!
|
773
|
-
|
774
|
-
You might want to activate logic less mode only for a few actions, you should disable logic-less mode globally at first in the configuration
|
775
|
-
|
776
|
-
Slim::Engine.set_default_options :logic_less => false
|
777
|
-
|
778
|
-
and activate logic less mode per render call in your application
|
779
|
-
|
780
|
-
get '/page'
|
781
|
-
slim :page, :logic_less => true
|
782
|
-
end
|
783
|
-
|
784
|
-
#### Options
|
785
|
-
|
786
|
-
<table>
|
787
|
-
<thead style="font-weight:bold"><tr><td>Type</td><td>Name</td><td>Default</td><td>Purpose</td></tr></thead>
|
788
|
-
<tbody>
|
789
|
-
<tr><td>Boolean</td><td>:logic_less</td><td>true</td><td>Enable logic less mode (Enabled if 'slim/logic_less' is required)</td></tr>
|
790
|
-
<tr><td>String</td><td>:dictionary</td><td>"self"</td><td>Dictionary where variables are looked up</td></tr>
|
791
|
-
<tr><td>Symbol/Array<Symbol></td><td>:dictionary_access</td><td>[:symbol, :string, :method, :instance_variable]</td><td>Dictionary access order (:symbol, :string, :method, :instance_variable)</td></tr>
|
792
|
-
</tbody>
|
793
|
-
</table>
|
794
|
-
|
795
|
-
### Translator/I18n
|
796
|
-
|
797
|
-
The translator plugin provides automatic translation of the templates using Gettext, Fast-Gettext or Rails I18n. Static text
|
798
|
-
in the template is replaced by the translated version.
|
799
|
-
|
800
|
-
Example:
|
801
|
-
|
802
|
-
h1 Welcome to #{url}!
|
803
|
-
|
804
|
-
Gettext translates the string from english to german where interpolations are replaced by %1, %2, ...
|
805
|
-
|
806
|
-
"Welcome to %1!" -> "Willkommen auf %1!"
|
807
|
-
|
808
|
-
and renders as
|
809
|
-
|
810
|
-
<h1>Willkommen auf slim-lang.com!</h1>
|
811
|
-
|
812
|
-
Enable the translator plugin with
|
813
|
-
|
814
|
-
require 'slim/translator'
|
815
|
-
|
816
|
-
#### Options
|
817
|
-
|
818
|
-
<table>
|
819
|
-
<thead style="font-weight:bold"><tr><td>Type</td><td>Name</td><td>Default</td><td>Purpose</td></tr></thead>
|
820
|
-
<tbody>
|
821
|
-
<tr><td>Boolean</td><td>:tr</td><td>true</td><td>Enable translator (Enabled if 'slim/translator' is required)</td></tr>
|
822
|
-
<tr><td>Symbol</td><td>:tr_mode</td><td>:dynamic</td><td>When to translate: :static = at compile time, :dynamic = at runtime</td></tr>
|
823
|
-
<tr><td>String</td><td>:tr_fn</td><td>Depending on installed translation library</td><td>Translation function, could be '_' for gettext</td></tr>
|
824
|
-
</tbody>
|
825
|
-
</table>
|
739
|
+
* [Logic less mode](doc/logic_less.md)
|
740
|
+
* [Translator/I18ne](doc/translator.md)
|
826
741
|
|
827
742
|
## Framework support
|
828
743
|
|
@@ -875,6 +790,7 @@ Usage: slimrb [options]
|
|
875
790
|
-s, --stdin Read input from standard input instead of an input file
|
876
791
|
--trace Show a full traceback on error
|
877
792
|
-c, --compile Compile only but do not run
|
793
|
+
-e, --erb Convert to ERB
|
878
794
|
-r, --rails Generate rails compatible code (Implies --compile)
|
879
795
|
-t, --translator Enable translator plugin
|
880
796
|
-l, --logic-less Enable logic less plugin
|
@@ -921,8 +837,9 @@ There are plugins for various text editors (including the most important ones -
|
|
921
837
|
|
922
838
|
### Template Converters (HAML, ERB, ...)
|
923
839
|
|
840
|
+
* Slim can be converted to ERB using `slimrb` or `Slim::ERBConverter' which are both included in the Slim gem
|
924
841
|
* [Haml2Slim converter](https://github.com/slim-template/haml2slim)
|
925
|
-
* [HTML2Slim converter](https://github.com/slim-template/html2slim)
|
842
|
+
* [ERB2Slim, HTML2Slim converter](https://github.com/slim-template/html2slim)
|
926
843
|
|
927
844
|
## Testing
|
928
845
|
|
@@ -938,16 +855,16 @@ run the slow parsing benchmark which needs more time. You can also increase the
|
|
938
855
|
|
939
856
|
rake bench slow=1 iterations=1000
|
940
857
|
|
941
|
-
We run the benchmarks for every commit on Travis-CI. Take a look at the newest benchmarking results:
|
858
|
+
We run the benchmarks for every commit on Travis-CI. Take a look at the newest benchmarking results: <http://travis-ci.org/#!/slim-template/slim>
|
942
859
|
|
943
860
|
### Test suite and continous integration
|
944
861
|
|
945
862
|
Slim provides an extensive test-suite based on minitest. You can run the tests
|
946
863
|
with 'rake test' and the rails integration tests with 'rake test:rails'.
|
947
864
|
|
948
|
-
We are currently experimenting with human-readable literate tests which are written as markdown files:
|
865
|
+
We are currently experimenting with human-readable literate tests which are written as markdown files: [TESTS.md](test/literate/TESTS.md)
|
949
866
|
|
950
|
-
Travis-CI is used for continous integration testing:
|
867
|
+
Travis-CI is used for continous integration testing: <http://travis-ci.org/#!/slim-template/slim>
|
951
868
|
|
952
869
|
Slim is working well on all major Ruby implementations:
|
953
870
|
|
@@ -1005,7 +922,7 @@ Syntax highlighting:
|
|
1005
922
|
Template Converters (HAML, ERB, ...):
|
1006
923
|
|
1007
924
|
* [Haml2Slim converter](https://github.com/slim-template/haml2slim)
|
1008
|
-
* [HTML2Slim converter](https://github.com/slim-template/html2slim)
|
925
|
+
* [ERB2Slim, HTML2Slim converter](https://github.com/slim-template/html2slim)
|
1009
926
|
|
1010
927
|
Language ports/Similar languages:
|
1011
928
|
|
@@ -1014,5 +931,6 @@ Language ports/Similar languages:
|
|
1014
931
|
* [Hamlet.rb (Similar template language)](https://github.com/gregwebs/hamlet.rb)
|
1015
932
|
* [Plim (Python port of Slim)](https://github.com/2nd/plim)
|
1016
933
|
* [Skim (Slim for Javascript)](https://github.com/jfirebaugh/skim)
|
934
|
+
* [Emblem.js (Javascript, similar to Slim)](https://github.com/machty/emblem.js)
|
1017
935
|
* [Haml (Older engine which inspired Slim)](https://github.com/haml/haml)
|
1018
936
|
* [Jade (Similar engine for javascript)](https://github.com/visionmedia/jade)
|