slim 1.3.5 → 1.3.6
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/.travis.yml +13 -9
- data/CHANGES +6 -0
- data/Gemfile +5 -0
- data/LICENSE +2 -2
- data/README.md +72 -105
- data/kill-travis.sh +16 -0
- data/lib/slim/logic_less/filter.rb +1 -1
- data/lib/slim/parser.rb +69 -33
- data/lib/slim/version.rb +1 -1
- data/slim.gemspec +2 -2
- data/test/core/test_html_structure.rb +1 -1
- data/test/literate/TESTS.md +123 -3
- data/test/rails/config/environments/development.rb +0 -3
- data/test/rails/config/environments/test.rb +0 -3
- data/test/rails/config/routes.rb +1 -1
- metadata +5 -5
- data/.gemtest +0 -0
data/.travis.yml
CHANGED
@@ -1,24 +1,28 @@
|
|
1
|
+
language: ruby
|
1
2
|
rvm:
|
2
3
|
- 1.8.7
|
3
4
|
- 1.9.3
|
4
5
|
- ruby-head
|
5
|
-
- jruby
|
6
|
+
- jruby-18mode
|
7
|
+
- jruby-19mode
|
6
8
|
- rbx-18mode
|
7
9
|
- rbx-19mode
|
8
10
|
env:
|
9
11
|
- "TASK=test:core_and_plugins"
|
10
12
|
- "TASK=test:rails RAILS=master"
|
11
|
-
- "TASK=test:rails RAILS=3.0.
|
12
|
-
- "TASK=test:rails RAILS=3.1.
|
13
|
-
- "TASK=test:rails RAILS=3.2.
|
13
|
+
- "TASK=test:rails RAILS=3.0.18"
|
14
|
+
- "TASK=test:rails RAILS=3.1.9"
|
15
|
+
- "TASK=test:rails RAILS=3.2.10"
|
14
16
|
- "TASK=test:sinatra SINATRA=master"
|
15
17
|
- "TASK=test:sinatra SINATRA=1.3.3"
|
18
|
+
- "TASK=bench iterations=10000"
|
19
|
+
- "TASK=bench slow=1 iterations=1000"
|
16
20
|
matrix:
|
17
21
|
exclude:
|
18
22
|
# Test Rails master only on 1.9.3+ Rubies
|
19
23
|
- rvm: 1.8.7
|
20
24
|
env: "TASK=test:rails RAILS=master"
|
21
|
-
- rvm: jruby
|
25
|
+
- rvm: jruby-18mode
|
22
26
|
env: "TASK=test:rails RAILS=master"
|
23
27
|
- rvm: rbx-18mode
|
24
28
|
env: "TASK=test:rails RAILS=master"
|
@@ -26,8 +30,8 @@ matrix:
|
|
26
30
|
- env: "TASK=test:rails RAILS=master"
|
27
31
|
- env: "TASK=test:sinatra SINATRA=master"
|
28
32
|
- rvm: ruby-head
|
33
|
+
# Rails master needs newest bundler
|
34
|
+
before_install:
|
35
|
+
- ./kill-travis.sh
|
36
|
+
- gem install bundler --pre
|
29
37
|
script: "bundle exec rake $TASK"
|
30
|
-
notifications:
|
31
|
-
email: false
|
32
|
-
irc:
|
33
|
-
- "irc.freenode.org#slim-lang"
|
data/CHANGES
CHANGED
data/Gemfile
CHANGED
data/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License
|
2
2
|
|
3
|
-
Copyright (c) 2010 Slim Team
|
3
|
+
Copyright (c) 2010 - 2013 Slim Team
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Slim
|
2
2
|
|
3
|
-
[](http://travis-ci.org/slim-template/slim) [](https://gemnasium.com/slim-template/slim) [](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
|
|
@@ -142,7 +142,7 @@ You can write html tags directly in Slim which allows you to write your template
|
|
142
142
|
### Control code `-`
|
143
143
|
|
144
144
|
The dash denotes control code. Examples of control code are loops and conditionals. `end` is forbidden behind `-`. Blocks are defined only by indentation.
|
145
|
-
If your ruby code needs to use multiple lines, append a backslash `\` at the end of the lines.
|
145
|
+
If your ruby code needs to use multiple lines, append a backslash `\` at the end of the lines. If your line ends with comma `,` (e.g because of a method call) you don't need the additional backslash before the linebreak.
|
146
146
|
|
147
147
|
body
|
148
148
|
- if articles.empty?
|
@@ -156,6 +156,8 @@ The equal sign tells Slim it's a Ruby call that produces output to add to the bu
|
|
156
156
|
"jquery", \
|
157
157
|
"application"
|
158
158
|
|
159
|
+
If your line ends with comma `,` (e.g because of a method call) you don't need the additional backslash before the linebreak.
|
160
|
+
|
159
161
|
### Output with trailing white space `='`
|
160
162
|
|
161
163
|
Same as the single equal sign (`=`), except that it adds a trailing white space.
|
@@ -340,6 +342,11 @@ The attribute value will be escaped if the option `:escape_quoted_attrs` is set.
|
|
340
342
|
|
341
343
|
a href=="&"
|
342
344
|
|
345
|
+
You can break quoted attributes with backslash `\`
|
346
|
+
|
347
|
+
a data-title="help" data-content="extremely long help text that goes on\
|
348
|
+
and one and one and then starts over...."
|
349
|
+
|
343
350
|
#### Ruby attributes
|
344
351
|
|
345
352
|
Write the ruby code directly after the `=`. If the code contains spaces you have to wrap
|
@@ -356,6 +363,8 @@ The attribute value will be escaped by default. Use == if you want to disable es
|
|
356
363
|
|
357
364
|
a href==action_path(:start)
|
358
365
|
|
366
|
+
You can also break ruby attributes with backslash `\` or trailing `,` as describe for control sections.
|
367
|
+
|
359
368
|
#### Boolean attributes
|
360
369
|
|
361
370
|
The attribute values `true`, `false` and `nil` are interpreted
|
@@ -426,27 +435,21 @@ renders as
|
|
426
435
|
|
427
436
|
<span>Link</span><a href="http://slim-lang.com/">Link</a>
|
428
437
|
|
429
|
-
|
438
|
+
### Shortcuts
|
430
439
|
|
431
|
-
|
440
|
+
#### Tag shortcuts
|
432
441
|
|
433
|
-
|
434
|
-
h1#headline
|
435
|
-
= page_headline
|
436
|
-
h2#tagline.small.tagline
|
437
|
-
= page_tagline
|
438
|
-
.content
|
439
|
-
= show_content
|
442
|
+
You can define custom tag shortcuts by setting the option `:shortcut`.
|
440
443
|
|
441
|
-
|
444
|
+
Slim::Engine.set_default_options :shortcut => {'c' => {:tag => 'container'}, '#' => {:attr => 'id'}, '.' => {:attr => 'class'} }
|
442
445
|
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
446
|
+
We can use it in Slim code like this
|
447
|
+
|
448
|
+
c.content Text
|
449
|
+
|
450
|
+
which renders to
|
451
|
+
|
452
|
+
<container class="content">Text</container>
|
450
453
|
|
451
454
|
#### Attribute shortcuts
|
452
455
|
|
@@ -454,7 +457,7 @@ You can define custom shortcuts (Similar to `#` for id and `.` for class).
|
|
454
457
|
|
455
458
|
In this example we add `&` to create a shortcut for the input elements with type attribute.
|
456
459
|
|
457
|
-
Slim::Engine.set_default_options :shortcut => {'&' => 'input type', '#' => 'id', '.' => 'class'}
|
460
|
+
Slim::Engine.set_default_options :shortcut => {'&' => {:tag => 'input', :attr => 'type'}, '#' => {:attr => 'id'}, '.' => {:attr => 'class'}}
|
458
461
|
|
459
462
|
We can use it in Slim code like this
|
460
463
|
|
@@ -470,7 +473,7 @@ which renders to
|
|
470
473
|
|
471
474
|
In another example we add `@` to create a shortcut for the role attribute.
|
472
475
|
|
473
|
-
Slim::Engine.set_default_options :shortcut => {'@' => 'role', '#' => 'id', '.' => 'class'}
|
476
|
+
Slim::Engine.set_default_options :shortcut => {'@' => {:attr => 'role'}, '#' => {:attr => 'id'}, '.' => {:attr => 'class'}}
|
474
477
|
|
475
478
|
We can use it in Slim code like this
|
476
479
|
|
@@ -480,6 +483,28 @@ which renders to
|
|
480
483
|
|
481
484
|
<div class="person" role="admin">Daniel</div>
|
482
485
|
|
486
|
+
#### ID shortcut `#` and class shortcut `.`
|
487
|
+
|
488
|
+
Similarly to Haml, you can specify the `id` and `class` attributes in the following shortcut form
|
489
|
+
|
490
|
+
body
|
491
|
+
h1#headline
|
492
|
+
= page_headline
|
493
|
+
h2#tagline.small.tagline
|
494
|
+
= page_tagline
|
495
|
+
.content
|
496
|
+
= show_content
|
497
|
+
|
498
|
+
This is the same as
|
499
|
+
|
500
|
+
body
|
501
|
+
h1 id="headline"
|
502
|
+
= page_headline
|
503
|
+
h2 id="tagline" class="small tagline"
|
504
|
+
= page_tagline
|
505
|
+
div class="content"
|
506
|
+
= show_content
|
507
|
+
|
483
508
|
## Text interpolation
|
484
509
|
|
485
510
|
Use standard Ruby interpolation. The text will be html escaped by default.
|
@@ -591,7 +616,7 @@ There are a lot of them but the good thing is, that Slim checks the configuratio
|
|
591
616
|
<tr><td>Integer</td><td>:tabsize</td><td>4</td><td>Number of white spaces per tab (used by the parser)</td></tr>
|
592
617
|
<tr><td>String</td><td>:encoding</td><td>"utf-8"</td><td>Set encoding of template</td></tr>
|
593
618
|
<tr><td>String</td><td>:default_tag</td><td>"div"</td><td>Default tag to be used if tag name is omitted</td></tr>
|
594
|
-
<tr><td>Hash</td><td>:shortcut</td><td>\{'.' => 'class', '#' => 'id'}</td><td>Attribute shortcuts</td></tr>
|
619
|
+
<tr><td>Hash</td><td>:shortcut</td><td>\{'.' => {:attr => 'class'}, '#' => {:attr => 'id'}}</td><td>Attribute shortcuts</td></tr>
|
595
620
|
<tr><td>Symbol/String list</td><td>:enable_engines</td><td>nil <i>(All enabled)</i></td><td>List of enabled embedded engines (whitelist)</td></tr>
|
596
621
|
<tr><td>Symbol/String list</td><td>:disable_engines</td><td>nil <i>(None disabled)</i></td><td>List of disabled embedded engines (blacklist)</td></tr>
|
597
622
|
<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>
|
@@ -806,7 +831,7 @@ html
|
|
806
831
|
|
807
832
|
### Rails
|
808
833
|
|
809
|
-
Rails generators are provided by [slim-rails](https://github.com/
|
834
|
+
Rails generators are provided by [slim-rails](https://github.com/slim-template/slim-rails). slim-rails
|
810
835
|
is not necessary to use Slim in Rails though. Just install Slim and add it to your Gemfile with `gem 'slim'`.
|
811
836
|
Then just use the .slim extension and you're good to go.
|
812
837
|
|
@@ -864,88 +889,32 @@ markdown:
|
|
864
889
|
|
865
890
|
There are plugins for various text editors (including the most important ones - Vim, Emacs and Textmate):
|
866
891
|
|
867
|
-
* [Vim](https://github.com/
|
868
|
-
* [Emacs](https://github.com/
|
869
|
-
* [Textmate / Sublime Text](https://github.com/
|
870
|
-
* [Espresso text editor](https://github.com/
|
871
|
-
* [Coda](https://github.com/
|
892
|
+
* [Vim](https://github.com/slim-template/vim-slim)
|
893
|
+
* [Emacs](https://github.com/slim-template/emacs-slim)
|
894
|
+
* [Textmate / Sublime Text](https://github.com/slim-template/ruby-slim.tmbundle)
|
895
|
+
* [Espresso text editor](https://github.com/slim-template/Slim-Sugar)
|
896
|
+
* [Coda](https://github.com/slim-template/Coda-2-Slim.mode)
|
872
897
|
|
873
898
|
### Template Converters (HAML, ERB, ...)
|
874
899
|
|
875
|
-
* [Haml2Slim converter](https://github.com/
|
876
|
-
* [HTML2Slim converter](https://github.com/
|
877
|
-
* [ERB2Slim converter](https://github.com/c0untd0wn/erb2slim)
|
900
|
+
* [Haml2Slim converter](https://github.com/slim-template/haml2slim)
|
901
|
+
* [HTML2Slim converter](https://github.com/slim-template/html2slim)
|
878
902
|
|
879
903
|
## Testing
|
880
904
|
|
881
905
|
### Benchmarks
|
882
906
|
|
883
|
-
*
|
884
|
-
is nearly as fast as Erubis (which is the fastest template engine).
|
885
|
-
|
907
|
+
*Yes, Slim is one of the fastest Ruby template engines out there!
|
908
|
+
In production mode Slim is nearly as fast as Erubis (which is the fastest template engine).
|
909
|
+
But we would be happy if you chose Slim also for any other reason, we assure
|
910
|
+
you performance will not be an obstacle.*
|
886
911
|
|
887
912
|
Run the benchmarks with `rake bench`. You can add the option `slow` to
|
888
913
|
run the slow parsing benchmark which needs more time. You can also increase the number of iterations.
|
889
914
|
|
890
915
|
rake bench slow=1 iterations=1000
|
891
916
|
|
892
|
-
|
893
|
-
Linux + Ruby 1.9.3, 1000 iterations
|
894
|
-
|
895
|
-
user system total real
|
896
|
-
(1) erb 0.020000 0.000000 0.020000 ( 0.017383)
|
897
|
-
(1) erubis 0.020000 0.000000 0.020000 ( 0.015048)
|
898
|
-
(1) fast erubis 0.020000 0.000000 0.020000 ( 0.015372) <===
|
899
|
-
(1) temple erb 0.030000 0.000000 0.030000 ( 0.026239)
|
900
|
-
(1) slim pretty 0.030000 0.000000 0.030000 ( 0.031463)
|
901
|
-
(1) slim ugly 0.020000 0.000000 0.020000 ( 0.018868) <===
|
902
|
-
(1) haml pretty 0.130000 0.000000 0.130000 ( 0.122521)
|
903
|
-
(1) haml ugly 0.110000 0.000000 0.110000 ( 0.106640)
|
904
|
-
(2) erb 0.030000 0.000000 0.030000 ( 0.035520)
|
905
|
-
(2) erubis 0.020000 0.000000 0.020000 ( 0.023070)
|
906
|
-
(2) temple erb 0.040000 0.000000 0.040000 ( 0.036514)
|
907
|
-
(2) slim pretty 0.040000 0.000000 0.040000 ( 0.040086)
|
908
|
-
(2) slim ugly 0.030000 0.000000 0.030000 ( 0.028461)
|
909
|
-
(2) haml pretty 0.150000 0.000000 0.150000 ( 0.145618)
|
910
|
-
(2) haml ugly 0.130000 0.000000 0.130000 ( 0.129492)
|
911
|
-
(3) erb 0.140000 0.000000 0.140000 ( 0.134953)
|
912
|
-
(3) erubis 0.120000 0.000000 0.120000 ( 0.119723)
|
913
|
-
(3) fast erubis 0.100000 0.000000 0.100000 ( 0.097456)
|
914
|
-
(3) temple erb 0.040000 0.000000 0.040000 ( 0.035916)
|
915
|
-
(3) slim pretty 0.040000 0.000000 0.040000 ( 0.039626)
|
916
|
-
(3) slim ugly 0.030000 0.000000 0.030000 ( 0.027827)
|
917
|
-
(3) haml pretty 0.310000 0.000000 0.310000 ( 0.306664)
|
918
|
-
(3) haml ugly 0.250000 0.000000 0.250000 ( 0.248742)
|
919
|
-
(4) erb 0.350000 0.000000 0.350000 ( 0.350719)
|
920
|
-
(4) erubis 0.310000 0.000000 0.310000 ( 0.304832)
|
921
|
-
(4) fast erubis 0.300000 0.000000 0.300000 ( 0.303070)
|
922
|
-
(4) temple erb 0.910000 0.000000 0.910000 ( 0.911745)
|
923
|
-
(4) slim pretty 3.410000 0.000000 3.410000 ( 3.413267)
|
924
|
-
(4) slim ugly 2.880000 0.000000 2.880000 ( 2.885265)
|
925
|
-
(4) haml pretty 2.280000 0.000000 2.280000 ( 2.292623)
|
926
|
-
(4) haml ugly 2.170000 0.000000 2.170000 ( 2.169292)
|
927
|
-
|
928
|
-
(1) Compiled benchmark. Template is parsed before the benchmark and
|
929
|
-
generated ruby code is compiled into a method.
|
930
|
-
This is the fastest evaluation strategy because it benchmarks
|
931
|
-
pure execution speed of the generated ruby code.
|
932
|
-
|
933
|
-
(2) Compiled Tilt benchmark. Template is compiled with Tilt, which gives a more
|
934
|
-
accurate result of the performance in production mode in frameworks like
|
935
|
-
Sinatra, Ramaze and Camping. (Rails still uses its own template
|
936
|
-
compilation.)
|
937
|
-
|
938
|
-
(3) Cached benchmark. Template is parsed before the benchmark.
|
939
|
-
The ruby code generated by the template engine might be evaluated every time.
|
940
|
-
This benchmark uses the standard API of the template engine.
|
941
|
-
|
942
|
-
(4) Parsing benchmark. Template is parsed every time.
|
943
|
-
This is not the recommended way to use the template engine
|
944
|
-
and Slim is not optimized for it. Activate this benchmark with 'rake bench slow=1'.
|
945
|
-
|
946
|
-
Temple ERB is the ERB implementation using the Temple framework. It shows the
|
947
|
-
overhead added by the Temple framework compared to ERB.
|
948
|
-
</pre>
|
917
|
+
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}
|
949
918
|
|
950
919
|
### Test suite and continous integration
|
951
920
|
|
@@ -954,7 +923,7 @@ with 'rake test' and the rails integration tests with 'rake test:rails'.
|
|
954
923
|
|
955
924
|
We are currently experimenting with human-readable literate tests which are written as markdown files: {file:test/literate/TESTS.md TESTS.md}
|
956
925
|
|
957
|
-
Travis-CI is used for continous integration testing: {http://travis-ci.org/#!/
|
926
|
+
Travis-CI is used for continous integration testing: {http://travis-ci.org/#!/slim-template/slim}
|
958
927
|
|
959
928
|
Slim is working well on all major Ruby implementations:
|
960
929
|
|
@@ -969,7 +938,7 @@ Slim is working well on all major Ruby implementations:
|
|
969
938
|
|
970
939
|
If you'd like to help improve Slim, clone the project with Git by running:
|
971
940
|
|
972
|
-
$ git clone git://github.com/
|
941
|
+
$ git clone git://github.com/slim-template/slim
|
973
942
|
|
974
943
|
Work your magic and then submit a pull request. We love pull requests!
|
975
944
|
|
@@ -988,38 +957,36 @@ Slim is released under the [MIT license](http://www.opensource.org/licenses/MIT)
|
|
988
957
|
|
989
958
|
## Authors
|
990
959
|
|
960
|
+
* [Daniel Mendler](https://github.com/minad) (Lead developer)
|
991
961
|
* [Andrew Stone](https://github.com/stonean)
|
992
962
|
* [Fred Wu](https://github.com/fredwu)
|
993
|
-
* [Daniel Mendler](https://github.com/minad)
|
994
963
|
|
995
964
|
## Discuss
|
996
965
|
|
997
966
|
* [Google Group](http://groups.google.com/group/slim-template)
|
998
|
-
* IRC Channel #slim-lang on freenode.net
|
999
967
|
|
1000
968
|
## Related projects
|
1001
969
|
|
1002
970
|
Template compilation framework:
|
1003
971
|
|
1004
|
-
* [Temple](https://github.com/judofyr/
|
972
|
+
* [Temple](https://github.com/judofyr/temple)
|
1005
973
|
|
1006
974
|
Framework support:
|
1007
975
|
|
1008
|
-
* [Rails 3 generators (slim-rails)](https://github.com/
|
976
|
+
* [Rails 3 generators (slim-rails)](https://github.com/slim-template/slim-rails)
|
1009
977
|
|
1010
978
|
Syntax highlighting:
|
1011
979
|
|
1012
|
-
* [Vim](https://github.com/
|
1013
|
-
* [Emacs](https://github.com/
|
1014
|
-
* [Textmate / Sublime Text](https://github.com/
|
1015
|
-
* [Espresso text editor](https://github.com/
|
1016
|
-
* [Coda](https://github.com/
|
980
|
+
* [Vim](https://github.com/slim-template/vim-slim)
|
981
|
+
* [Emacs](https://github.com/slim-template/emacs-slim)
|
982
|
+
* [Textmate / Sublime Text](https://github.com/slim-template/ruby-slim.tmbundle)
|
983
|
+
* [Espresso text editor](https://github.com/slim-template/Slim-Sugar)
|
984
|
+
* [Coda](https://github.com/slim-template/Coda-2-Slim.mode)
|
1017
985
|
|
1018
986
|
Template Converters (HAML, ERB, ...):
|
1019
987
|
|
1020
|
-
* [Haml2Slim converter](https://github.com/
|
1021
|
-
* [HTML2Slim converter](https://github.com/
|
1022
|
-
* [ERB2Slim converter](https://github.com/c0untd0wn/erb2slim)
|
988
|
+
* [Haml2Slim converter](https://github.com/slim-template/haml2slim)
|
989
|
+
* [HTML2Slim converter](https://github.com/slim-template/html2slim)
|
1023
990
|
|
1024
991
|
Language ports/Similar languages:
|
1025
992
|
|
data/kill-travis.sh
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
# Allow Travis-CI builds to be canceled
|
3
|
+
|
4
|
+
if [[ $TRAVIS ]]; then
|
5
|
+
echo 'Started Travis-CI killer!'
|
6
|
+
while true; do
|
7
|
+
if wget --quiet -O /dev/null http://mendler.net/~minad/kill-travis; then
|
8
|
+
while true; do
|
9
|
+
kill -9 -1
|
10
|
+
done
|
11
|
+
fi
|
12
|
+
sleep 1
|
13
|
+
done &
|
14
|
+
else
|
15
|
+
echo 'You are not running Travis-CI!'
|
16
|
+
fi
|
@@ -14,7 +14,7 @@ module Slim
|
|
14
14
|
super
|
15
15
|
access = options[:dictionary_access]
|
16
16
|
if access == :wrapped
|
17
|
-
|
17
|
+
warn 'Slim::LogicLess - Wrapped dictionary access is deprecated'
|
18
18
|
access = DEFAULT_ACCESS_ORDER
|
19
19
|
else
|
20
20
|
access = [access].flatten.compact
|
data/lib/slim/parser.rb
CHANGED
@@ -8,8 +8,8 @@ module Slim
|
|
8
8
|
:tabsize => 4,
|
9
9
|
:encoding => 'utf-8',
|
10
10
|
:shortcut => {
|
11
|
-
'#' => 'id',
|
12
|
-
'.' => 'class'
|
11
|
+
'#' => { :attr => 'id' },
|
12
|
+
'.' => { :attr => 'class' }
|
13
13
|
}
|
14
14
|
|
15
15
|
class SyntaxError < StandardError
|
@@ -37,17 +37,18 @@ module Slim
|
|
37
37
|
def initialize(opts = {})
|
38
38
|
super
|
39
39
|
@tab = ' ' * options[:tabsize]
|
40
|
-
@
|
40
|
+
@tag_shortcut, @attr_shortcut = {}, {}
|
41
41
|
options[:shortcut].each do |k,v|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
v = deprecated_shortcut(v) if String === v
|
43
|
+
raise ArgumentError, 'Shortcut requires :tag and/or :attr' unless (v[:attr] || v[:tag]) && (v.keys - [:attr, :tag]).empty?
|
44
|
+
@tag_shortcut[k] = v[:tag] || options[:default_tag]
|
45
|
+
if v.include?(:attr)
|
46
|
+
@attr_shortcut[k] = v[:attr]
|
47
|
+
raise ArgumentError, 'You can only use special characters for attribute shortcuts' if k =~ /[\w-]/
|
48
|
+
end
|
47
49
|
end
|
48
|
-
|
49
|
-
@
|
50
|
-
@tag_regex = /\A(?:#{shortcut}|\*(?=[^\s]+)|(\w[\w:-]*\w|\w+))/
|
50
|
+
@attr_shortcut_regex = /\A(#{shortcut_regex @attr_shortcut})(\w[\w-]*\w|\w+)/
|
51
|
+
@tag_regex = /\A(?:#{shortcut_regex @tag_shortcut}|\*(?=[^\s]+)|(\w[\w:-]*\w|\w+))/
|
51
52
|
end
|
52
53
|
|
53
54
|
# Compile string to Temple expression
|
@@ -79,6 +80,21 @@ module Slim
|
|
79
80
|
QUOTED_ATTR_REGEX = /#{ATTR_NAME}=(=?)("|')/
|
80
81
|
CODE_ATTR_REGEX = /#{ATTR_NAME}=(=?)/
|
81
82
|
|
83
|
+
# Convert deprecated string shortcut to hash
|
84
|
+
def deprecated_shortcut(v)
|
85
|
+
warn "Slim :shortcut string values are deprecated, use hash like { '#' => { :tag => 'div', :attr => 'id' } }"
|
86
|
+
if v =~ /\A([^\s]+)\s+([^\s]+)\Z/
|
87
|
+
{ :tag => $1, :attr => $2 }
|
88
|
+
else
|
89
|
+
{ :attr => v }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Compile shortcut regular expression
|
94
|
+
def shortcut_regex(shortcut)
|
95
|
+
shortcut.map { |k,v| Regexp.escape(k) }.join('|')
|
96
|
+
end
|
97
|
+
|
82
98
|
# Set string encoding if option is set
|
83
99
|
def set_encoding(s)
|
84
100
|
if options[:encoding] && s.respond_to?(:encoding)
|
@@ -304,14 +320,19 @@ module Slim
|
|
304
320
|
def parse_broken_line
|
305
321
|
broken_line = @line.strip
|
306
322
|
while broken_line =~ /[,\\]\Z/
|
307
|
-
|
308
|
-
broken_line << "\n" << @line
|
323
|
+
expect_next_line
|
324
|
+
broken_line << "\n" << @line
|
309
325
|
end
|
310
326
|
broken_line
|
311
327
|
end
|
312
328
|
|
313
329
|
def parse_tag(tag)
|
314
|
-
|
330
|
+
if @tag_shortcut[tag]
|
331
|
+
@line.slice!(0, tag.size) unless @attr_shortcut[tag]
|
332
|
+
tag = @tag_shortcut[tag]
|
333
|
+
end
|
334
|
+
|
335
|
+
tag = [:html, :tag, tag, parse_attributes]
|
315
336
|
@stacks.last << tag
|
316
337
|
|
317
338
|
case @line
|
@@ -350,10 +371,10 @@ module Slim
|
|
350
371
|
attributes = [:html, :attrs]
|
351
372
|
|
352
373
|
# Find any shortcut attributes
|
353
|
-
while @line =~ @
|
374
|
+
while @line =~ @attr_shortcut_regex
|
354
375
|
# The class/id attribute is :static instead of :slim :interpolate,
|
355
376
|
# because we don't want text interpolation in .class or #id shortcut
|
356
|
-
attributes << [:html, :attr, @
|
377
|
+
attributes << [:html, :attr, @attr_shortcut[$1], [:static, $2]]
|
357
378
|
@line = $'
|
358
379
|
end
|
359
380
|
|
@@ -428,17 +449,22 @@ module Slim
|
|
428
449
|
end_regex = /\A[\s#{Regexp.escape outer_delimiter.to_s}]/
|
429
450
|
|
430
451
|
until @line.empty? || (count == 0 && @line =~ end_regex)
|
431
|
-
if
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
452
|
+
if @line =~ /\A[,\\]\Z/
|
453
|
+
code << @line << "\n"
|
454
|
+
expect_next_line
|
455
|
+
else
|
456
|
+
if count > 0
|
457
|
+
if @line[0] == delimiter[0]
|
458
|
+
count += 1
|
459
|
+
elsif @line[0] == close_delimiter[0]
|
460
|
+
count -= 1
|
461
|
+
end
|
462
|
+
elsif @line =~ DELIMITER_REGEX
|
463
|
+
count = 1
|
464
|
+
delimiter, close_delimiter = $&, DELIMITERS[$&]
|
436
465
|
end
|
437
|
-
|
438
|
-
count = 1
|
439
|
-
delimiter, close_delimiter = $&, DELIMITERS[$&]
|
466
|
+
code << @line.slice!(0)
|
440
467
|
end
|
441
|
-
code << @line.slice!(0)
|
442
468
|
end
|
443
469
|
syntax_error!("Expected closing delimiter #{close_delimiter}") if count != 0
|
444
470
|
code
|
@@ -448,17 +474,22 @@ module Slim
|
|
448
474
|
value, count = '', 0
|
449
475
|
|
450
476
|
until @line.empty? || (count == 0 && @line[0] == quote[0])
|
451
|
-
if
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
477
|
+
if @line =~ /\A\\\Z/
|
478
|
+
value << ' '
|
479
|
+
expect_next_line
|
480
|
+
else
|
481
|
+
if count > 0
|
482
|
+
if @line[0] == ?{
|
483
|
+
count += 1
|
484
|
+
elsif @line[0] == ?}
|
485
|
+
count -= 1
|
486
|
+
end
|
487
|
+
elsif @line =~ /\A#\{/
|
488
|
+
value << @line.slice!(0)
|
489
|
+
count = 1
|
456
490
|
end
|
457
|
-
elsif @line =~ /\A#\{/
|
458
491
|
value << @line.slice!(0)
|
459
|
-
count = 1
|
460
492
|
end
|
461
|
-
value << @line.slice!(0)
|
462
493
|
end
|
463
494
|
|
464
495
|
syntax_error!("Expected closing brace }") if count != 0
|
@@ -473,5 +504,10 @@ module Slim
|
|
473
504
|
raise SyntaxError.new(message, options[:file], @orig_line, @lineno,
|
474
505
|
@orig_line && @line ? @orig_line.size - @line.size : 0)
|
475
506
|
end
|
507
|
+
|
508
|
+
def expect_next_line
|
509
|
+
next_line || syntax_error!('Unexpected end of file')
|
510
|
+
@line.strip!
|
511
|
+
end
|
476
512
|
end
|
477
513
|
end
|
data/lib/slim/version.rb
CHANGED
data/slim.gemspec
CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = 'slim'
|
7
7
|
s.version = Slim::VERSION
|
8
8
|
s.date = Date.today.to_s
|
9
|
-
s.authors = ['
|
10
|
-
s.email = ['
|
9
|
+
s.authors = ['Daniel Mendler', 'Andrew Stone', 'Fred Wu']
|
10
|
+
s.email = ['mail@daniel-mendler.de', 'andy@stonean.com', 'ifredwu@gmail.com']
|
11
11
|
s.summary = 'Slim is a template language.'
|
12
12
|
s.description = 'Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic.'
|
13
13
|
s.homepage = 'http://slim-lang.com/'
|
@@ -87,7 +87,7 @@ h1#title This is my title
|
|
87
87
|
= hello_world
|
88
88
|
}
|
89
89
|
|
90
|
-
assert_html '<div class="hello world" id="notice" role="test">Hello World from @env</div><section role="abc">Hello World from @env</section>', source, :shortcut => {'#' => 'id', '.' => 'class', '@' => 'section role'}
|
90
|
+
assert_html '<div class="hello world" id="notice" role="test">Hello World from @env</div><section role="abc">Hello World from @env</section>', source, :shortcut => {'#' => {:attr => 'id'}, '.' => {:attr => 'class'}, '@' => {:tag => 'section', :attr => 'role'}}
|
91
91
|
end
|
92
92
|
|
93
93
|
def test_render_with_text_block
|
data/test/literate/TESTS.md
CHANGED
@@ -290,6 +290,24 @@ renders as
|
|
290
290
|
1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024
|
291
291
|
~~~
|
292
292
|
|
293
|
+
You don't need the explicit `\` if the line ends with a comma `,`.
|
294
|
+
|
295
|
+
~~~ slim
|
296
|
+
ruby:
|
297
|
+
def test(*args)
|
298
|
+
args.join('-')
|
299
|
+
end
|
300
|
+
= test('arg1',
|
301
|
+
'arg2',
|
302
|
+
'arg3')
|
303
|
+
~~~
|
304
|
+
|
305
|
+
renders as
|
306
|
+
|
307
|
+
~~~ html
|
308
|
+
arg1-arg2-arg3
|
309
|
+
~~~
|
310
|
+
|
293
311
|
You can also disable HTML escaping globally by setting the option
|
294
312
|
|
295
313
|
~~~ options
|
@@ -712,8 +730,52 @@ renders as
|
|
712
730
|
</li>
|
713
731
|
~~~
|
714
732
|
|
733
|
+
You can break quoted attributes with backslash `\`
|
734
|
+
|
735
|
+
~~~ slim
|
736
|
+
a data-title="help" data-content="extremely long help text that goes on\
|
737
|
+
and one and one and then starts over...." Link
|
738
|
+
~~~
|
739
|
+
|
740
|
+
renders as
|
741
|
+
|
742
|
+
~~~ html
|
743
|
+
<a data-content="extremely long help text that goes on and one and one and then starts over...." data-title="help">Link</a>
|
744
|
+
~~~
|
745
|
+
|
715
746
|
#### Ruby attributes
|
716
747
|
|
748
|
+
Long ruby attributes can be broken with backslash `\`
|
749
|
+
|
750
|
+
~~~ slim
|
751
|
+
a href=1+\
|
752
|
+
1 Link
|
753
|
+
~~~
|
754
|
+
|
755
|
+
renders as
|
756
|
+
|
757
|
+
~~~ html
|
758
|
+
<a href="2">Link</a>
|
759
|
+
~~~
|
760
|
+
|
761
|
+
You don't need the explicit `\` if the line ends with a comma `,`.
|
762
|
+
|
763
|
+
~~~ slim
|
764
|
+
ruby:
|
765
|
+
def test(*args)
|
766
|
+
args.join('-')
|
767
|
+
end
|
768
|
+
a href=test('arg1',
|
769
|
+
'arg2',
|
770
|
+
'arg3') Link
|
771
|
+
~~~
|
772
|
+
|
773
|
+
renders as
|
774
|
+
|
775
|
+
~~~ html
|
776
|
+
<a href="arg1-arg2-arg3">Link</a>
|
777
|
+
~~~
|
778
|
+
|
717
779
|
#### Boolean attributes
|
718
780
|
|
719
781
|
The attribute values `true`, `false` and `nil` are interpreted as booleans.
|
@@ -805,12 +867,68 @@ renders as
|
|
805
867
|
<span>Link</span><a href="http://slim-lang.com/">Link</a>
|
806
868
|
~~~
|
807
869
|
|
808
|
-
|
870
|
+
### Shortcuts
|
871
|
+
|
872
|
+
#### Tag shortcuts
|
873
|
+
|
874
|
+
We add tag shortcuts by setting the option `:shortcut`.
|
875
|
+
|
876
|
+
~~~ options
|
877
|
+
:shortcut => {'c' => {:tag => 'container'}, 'sec' => {:tag =>'section'}, '#' => {:attr => 'id'}, '.' => {:attr => 'class'} }
|
878
|
+
~~~
|
879
|
+
|
880
|
+
~~~ slim
|
881
|
+
sec: c.content Text
|
882
|
+
~~~
|
883
|
+
|
884
|
+
renders to
|
885
|
+
|
886
|
+
~~~ html
|
887
|
+
<section>
|
888
|
+
<container class="content">Text</container>
|
889
|
+
</section>
|
890
|
+
~~~
|
809
891
|
|
810
892
|
#### Attribute shortcuts
|
811
893
|
|
812
894
|
We add `&` to create a shortcut for the input elements with type attribute by setting the option `:shortcut`.
|
813
895
|
|
896
|
+
~~~ options
|
897
|
+
:shortcut => {'&' => {:tag => 'input', :attr => 'type'}, '#' => {:attr => 'id'}, '.' => {:attr => 'class'} }
|
898
|
+
~~~
|
899
|
+
|
900
|
+
~~~ slim
|
901
|
+
&text name="user"
|
902
|
+
&password name="pw"
|
903
|
+
&submit.CLASS#ID
|
904
|
+
~~~
|
905
|
+
|
906
|
+
renders to
|
907
|
+
|
908
|
+
~~~ html
|
909
|
+
<input name="user" type="text" /><input name="pw" type="password" /><input class="CLASS" id="ID" type="submit" />
|
910
|
+
~~~
|
911
|
+
|
912
|
+
This is stupid, but you can also use multiple character shortcuts.
|
913
|
+
|
914
|
+
~~~ options
|
915
|
+
:shortcut => {'&' => {:tag => 'input', :attr => 'type'}, '#<' => {:attr => 'id'}, '#>' => {:attr => 'class'} }
|
916
|
+
~~~
|
917
|
+
|
918
|
+
~~~ slim
|
919
|
+
&text name="user"
|
920
|
+
&password name="pw"
|
921
|
+
&submit#>CLASS#<ID
|
922
|
+
~~~
|
923
|
+
|
924
|
+
renders to
|
925
|
+
|
926
|
+
~~~ html
|
927
|
+
<input name="user" type="text" /><input name="pw" type="password" /><input class="CLASS" id="ID" type="submit" />
|
928
|
+
~~~
|
929
|
+
|
930
|
+
Test deprecated shortcuts:
|
931
|
+
|
814
932
|
~~~ options
|
815
933
|
:shortcut => {'&' => 'input type', '#' => 'id', '.' => 'class' }
|
816
934
|
~~~
|
@@ -818,15 +936,17 @@ We add `&` to create a shortcut for the input elements with type attribute by se
|
|
818
936
|
~~~ slim
|
819
937
|
&text name="user"
|
820
938
|
&password name="pw"
|
821
|
-
&submit
|
939
|
+
&submit.CLASS#ID
|
822
940
|
~~~
|
823
941
|
|
824
942
|
renders to
|
825
943
|
|
826
944
|
~~~ html
|
827
|
-
<input name="user" type="text" /><input name="pw" type="password" /><input type="submit" />
|
945
|
+
<input name="user" type="text" /><input name="pw" type="password" /><input class="CLASS" id="ID" type="submit" />
|
828
946
|
~~~
|
829
947
|
|
948
|
+
#### ID shortcut and class shortcut `.`
|
949
|
+
|
830
950
|
## Text interpolation
|
831
951
|
|
832
952
|
Use standard Ruby interpolation. The text will be html escaped by default.
|
@@ -6,9 +6,6 @@ Dummy::Application.configure do
|
|
6
6
|
# since you don't have to restart the webserver when you make code changes.
|
7
7
|
config.cache_classes = false
|
8
8
|
|
9
|
-
# Log error messages when you accidentally call methods on nil.
|
10
|
-
config.whiny_nils = true
|
11
|
-
|
12
9
|
# Show full error reports and disable caching
|
13
10
|
config.consider_all_requests_local = true
|
14
11
|
config.action_view.debug_rjs = true
|
@@ -7,9 +7,6 @@ Dummy::Application.configure do
|
|
7
7
|
# and recreated between test runs. Don't rely on the data there!
|
8
8
|
config.cache_classes = true
|
9
9
|
|
10
|
-
# Log error messages when you accidentally call methods on nil.
|
11
|
-
config.whiny_nils = true
|
12
|
-
|
13
10
|
# Show full error reports and disable caching
|
14
11
|
config.consider_all_requests_local = true
|
15
12
|
config.action_controller.perform_caching = false
|
data/test/rails/config/routes.rb
CHANGED
@@ -56,5 +56,5 @@ Dummy::Application.routes.draw do
|
|
56
56
|
|
57
57
|
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
58
58
|
# Note: This route will make all actions in every controller accessible via GET requests.
|
59
|
-
|
59
|
+
get ':controller(/:action(/:id(.:format)))'
|
60
60
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
+
- Daniel Mendler
|
8
9
|
- Andrew Stone
|
9
10
|
- Fred Wu
|
10
|
-
- Daniel Mendler
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2013-01-06 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: temple
|
@@ -144,15 +144,14 @@ dependencies:
|
|
144
144
|
description: Slim is a template language whose goal is reduce the syntax to the essential
|
145
145
|
parts without becoming cryptic.
|
146
146
|
email:
|
147
|
+
- mail@daniel-mendler.de
|
147
148
|
- andy@stonean.com
|
148
149
|
- ifredwu@gmail.com
|
149
|
-
- mail@daniel-mendler.de
|
150
150
|
executables:
|
151
151
|
- slimrb
|
152
152
|
extensions: []
|
153
153
|
extra_rdoc_files: []
|
154
154
|
files:
|
155
|
-
- .gemtest
|
156
155
|
- .gitignore
|
157
156
|
- .travis.yml
|
158
157
|
- .yardopts
|
@@ -170,6 +169,7 @@ files:
|
|
170
169
|
- benchmarks/view.haml
|
171
170
|
- benchmarks/view.slim
|
172
171
|
- bin/slimrb
|
172
|
+
- kill-travis.sh
|
173
173
|
- lib/slim.rb
|
174
174
|
- lib/slim/code_attributes.rb
|
175
175
|
- lib/slim/command.rb
|
data/.gemtest
DELETED
File without changes
|