slim 3.0.6 → 3.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62d3292109076e4e06bc239e5f78b6d53b198a34
4
- data.tar.gz: 0c1e6219507af63490d7de910b2e7e4a478013a5
3
+ metadata.gz: fdd7e59579d815f6a4b7b73d8ca4c9718f3e4df5
4
+ data.tar.gz: 37b35843560936e0fdcef732edd623e34fd17039
5
5
  SHA512:
6
- metadata.gz: 711c54460e79e5191c8662e7c2764cf5b4a019cf65324c9e0ce59c547319903a04803b89ede833a354a80d87a6e2be50bc479a5689b1908acb4bf359b190e734
7
- data.tar.gz: 13357a0c0ca79b446e29f7f9096a6964a97c0422bdb62f8826ad63ff551dc315633c82dc769d6864c255ae0c41d76e17fc8391d0578dafba64de87f03aca3888
6
+ metadata.gz: 813412ac6507ed3ecc3b72c4b02be96e323fe7638afc642186155fd196e96f59ff5506c808f2ace1568ab333b5b452a5496699bdfa0a4f1b8415c0eb8c7bd725
7
+ data.tar.gz: 647d4ecb78fcd10d0af3ffbc713a89ce210bdfb1dc4d3dae08bfed8056f2491255cde02d559952b2472951b4eb1bf4ce69bba617e6c687e7c7690eaf4e46db9b
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ 3.0.7 (2016-05-22)
2
+
3
+ * Add additional attributes feature to shortcuts
4
+ * Freeze string literals
5
+
1
6
  3.0.6 (2015-06-05)
2
7
 
3
8
  * Fix warnings #625
@@ -1,6 +1,6 @@
1
1
  # Slim
2
2
 
3
- [![Gem Version](https://img.shields.io/gem/v/slim.svg)](http://rubygems.org/gems/slim) [![Build Status](https://img.shields.io/travis/slim-template/slim.svg?branch=master)](http://travis-ci.org/slim-template/slim) [![Dependency Status](https://img.shields.io/gemnasium/slim-template/slim.svg?travis)](https://gemnasium.com/slim-template/slim) [![Code Climate](https://img.shields.io/codeclimate/github/slim-template/slim.svg)](https://codeclimate.com/github/slim-template/slim) [![Gittip donate button](https://img.shields.io/gratipay/bevry.svg)](https://www.gittip.com/min4d/ "Donate weekly to this project using Gittip")
3
+ [![Gem Version](https://img.shields.io/gem/v/slim.svg)](http://rubygems.org/gems/slim) [![Build Status](https://img.shields.io/travis/slim-template/slim.svg?branch=master)](http://travis-ci.org/slim-template/slim) [![Dependency Status](https://img.shields.io/gemnasium/slim-template/slim.svg?travis)](https://gemnasium.com/slim-template/slim) [![Code Climate](https://codeclimate.com/github/slim-template/slim/badges/gpa.svg)](https://codeclimate.com/github/slim-template/slim) [![Test Coverage](https://codeclimate.com/github/slim-template/slim/badges/coverage.svg)](https://codeclimate.com/github/slim-template/slim/coverage) [![Gittip donate button](https://img.shields.io/gratipay/bevry.svg)](https://www.gittip.com/min4d/ "Donate weekly to this project using Gittip")
4
4
  [![Flattr donate button](https://raw.github.com/balupton/flattr-buttons/master/badge-89x18.gif)](https://flattr.com/submit/auto?user_id=min4d&url=http%3A%2F%2Fslim-lang.org%2F "Donate monthly to this project using Flattr")
5
5
 
6
6
  Slim は 不可解にならないように view の構文を本質的な部品まで減らすことを目指したテンプレート言語です。標準的な HTML テンプレートからどれだけのものが削除できるか確かめるところから始まりました。(<, >, 閉じタグなど) 多くの人が Slim に興味を持ったことで, 機能性は発展し, 柔軟な構文をもたらしました。
@@ -238,7 +238,7 @@ html コメントにはスラッシュの直後にエクスクラメーション
238
238
  p もっといいブラウザを使ってください。
239
239
  ~~~
240
240
 
241
- レンダリング結果
241
+ レンダリング結果:
242
242
 
243
243
  ~~~ html
244
244
  <!--[if IE]><p>もっといいブラウザを使ってください。</p><![endif]-->
@@ -246,9 +246,9 @@ html コメントにはスラッシュの直後にエクスクラメーション
246
246
 
247
247
  ## HTML タグ
248
248
 
249
- ### ドキュメントタイプタグ
249
+ # <!DOCTYPE> 宣言
250
250
 
251
- ドキュメントタイプタグはとても簡単な方法で複雑なドキュメントタイプを生成するために使われる特別なタグです。
251
+ doctype はとても簡単な方法で複雑なドキュメントタイプを生成するために使われる特別なキーワードです。
252
252
 
253
253
  XML 宣言
254
254
 
@@ -513,7 +513,7 @@ input type="text" disabled=nil
513
513
  a.menu class="highlight" href="http://slim-lang.com/" Slim-lang.com
514
514
  ~~~
515
515
 
516
- レンダリング結果
516
+ レンダリング結果:
517
517
 
518
518
  ~~~ html
519
519
  <a class="menu highlight" href="http://slim-lang.com/">Slim-lang.com</a>
@@ -534,7 +534,7 @@ a class=:menu,:highlight
534
534
  .card*{'data-url'=>place_path(place), 'data-id'=>place.id} = place.name
535
535
  ~~~
536
536
 
537
- レンダリング結果
537
+ レンダリング結果:
538
538
 
539
539
  ~~~ html
540
540
  <div class="card" data-id="1234" data-url="/place/1234">Slim の家</div>
@@ -575,7 +575,7 @@ ruby:
575
575
  *a_unless_current リンク
576
576
  ~~~
577
577
 
578
- レンダリング結果
578
+ レンダリング結果:
579
579
 
580
580
  ~~~ html
581
581
  <span>リンク</span><a href="http://slim-lang.com/">リンク</a>
@@ -585,7 +585,7 @@ ruby:
585
585
 
586
586
  #### タグショートカット
587
587
 
588
- `:shortcut` オプションを設定することで独自のタグショートカットを定義できます。
588
+ `:shortcut` オプションを設定することで独自のタグショートカットを定義できます。Rails アプリケーションでは, `config/initializers/slim.rb` のようにイニシャライザに定義します。Sinatra アプリでは, `require 'slim'` が書かれた下であればどこにでも設定を定義することができます。
589
589
 
590
590
  ~~~ ruby
591
591
  Slim::Engine.set_options shortcut: {'c' => {tag: 'container'}, '#' => {attr: 'id'}, '.' => {attr: 'class'} }
@@ -665,6 +665,29 @@ Slim の中で次のように使用し
665
665
  <div class="person" role="admin" data-role="admin">Daniel</div>
666
666
  ~~~
667
667
 
668
+ 次のように追加の属性固定値を設定することもできます。
669
+
670
+ ~~~ ruby
671
+ Slim::Engine.set_options shortcut: {'^' => {tag: 'script', attr: 'data-binding',
672
+ additional_attrs: { type: "text/javascript" }}}
673
+ ~~~
674
+
675
+ このように使用します。
676
+
677
+ ~~~ slim
678
+ ^products
679
+ == @products.to_json
680
+ ~~~
681
+
682
+ レンダリング結果です。
683
+
684
+ ~~~ html
685
+ <script data-binding="products" type="text/javascript">
686
+ [{"name": "product1", "price": "$100"},
687
+ {"name": "prodcut2", "price": "$200"}]
688
+ </script>
689
+ ~~~
690
+
668
691
  #### ID ショートカット `#` と class ショートカット `.`
669
692
 
670
693
  `id` と `class` の属性を次のショートカットで指定できます。
@@ -754,7 +777,7 @@ end
754
777
  = captured_content
755
778
  ~~~
756
779
 
757
- 別の興味深いユースケースは、enumerableを使いそれぞれの要素をキャプチャすることです。ヘルパは、このようになります。
780
+ 別の興味深いユースケースは, enumerableを使いそれぞれの要素をキャプチャすることです。ヘルパは, このようになります。
758
781
 
759
782
  ~~~ ruby
760
783
  module Capture
@@ -766,7 +789,7 @@ module Capture
766
789
  end
767
790
  ~~~
768
791
 
769
- そして、次のように使用出来ます。
792
+ そして, 次のように使用出来ます。
770
793
 
771
794
  ~~~ slim
772
795
  - links = { 'http://slim-lang.com' => 'The Slim Template Language' }
@@ -774,7 +797,7 @@ end
774
797
  a href=url = text
775
798
  ~~~
776
799
 
777
- その後は、`link_list`はキャプチャしたコンテンツを含みます。
800
+ その後は, `link_list`はキャプチャしたコンテンツを含みます。
778
801
 
779
802
  ### インクルードヘルパ
780
803
 
@@ -1080,6 +1103,7 @@ markdown:
1080
1103
  * [Textmate / Sublime Text](https://github.com/slim-template/ruby-slim.tmbundle)
1081
1104
  * [Espresso text editor](https://github.com/slim-template/Slim-Sugar)
1082
1105
  * [Coda](https://github.com/slim-template/Coda-2-Slim.mode)
1106
+ * [Atom](https://github.com/slim-template/language-slim)
1083
1107
 
1084
1108
  ### テンプレート変換 (HAML, ERB, ...)
1085
1109
 
@@ -1181,6 +1205,7 @@ Slim は [MIT license](http://www.opensource.org/licenses/MIT) に基づいて
1181
1205
  静的コード解析:
1182
1206
 
1183
1207
  * [Slim-Lint](https://github.com/sds/slim-lint)
1208
+ * [SublimeLinter-slim-lint](https://github.com/elstgav/SublimeLinter-slim-lint)
1184
1209
 
1185
1210
  テンプレート変換 (HAML, ERB, ...):
1186
1211
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Slim
2
2
 
3
- [![Gem Version](https://img.shields.io/gem/v/slim.svg)](http://rubygems.org/gems/slim) [![Build Status](https://img.shields.io/travis/slim-template/slim.svg?branch=master)](http://travis-ci.org/slim-template/slim) [![Dependency Status](https://img.shields.io/gemnasium/slim-template/slim.svg?travis)](https://gemnasium.com/slim-template/slim) [![Code Climate](https://img.shields.io/codeclimate/github/slim-template/slim.svg)](https://codeclimate.com/github/slim-template/slim) [![Gittip donate button](https://img.shields.io/gratipay/bevry.svg)](https://www.gittip.com/min4d/ "Donate weekly to this project using Gittip")
3
+ [![Gem Version](https://img.shields.io/gem/v/slim.svg)](http://rubygems.org/gems/slim) [![Build Status](https://img.shields.io/travis/slim-template/slim.svg?branch=master)](http://travis-ci.org/slim-template/slim) [![Dependency Status](https://img.shields.io/gemnasium/slim-template/slim.svg?travis)](https://gemnasium.com/slim-template/slim) [![Code Climate](https://codeclimate.com/github/slim-template/slim/badges/gpa.svg)](https://codeclimate.com/github/slim-template/slim) [![Test Coverage](https://codeclimate.com/github/slim-template/slim/badges/coverage.svg)](https://codeclimate.com/github/slim-template/slim/coverage) [![Gittip donate button](https://img.shields.io/gratipay/bevry.svg)](https://www.gittip.com/min4d/ "Donate weekly to this project using Gittip")
4
4
  [![Flattr donate button](https://raw.github.com/balupton/flattr-buttons/master/badge-89x18.gif)](https://flattr.com/submit/auto?user_id=min4d&url=http%3A%2F%2Fslim-lang.org%2F "Donate monthly to this project using Flattr")
5
5
 
6
6
  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.
@@ -189,7 +189,7 @@ body
189
189
 
190
190
  ### Output `=`
191
191
 
192
- 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:
192
+ The equals 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:
193
193
 
194
194
  ~~~ slim
195
195
  = javascript_include_tag \
@@ -199,15 +199,15 @@ The equal sign tells Slim it's a Ruby call that produces output to add to the bu
199
199
 
200
200
  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.
201
201
 
202
- * Output with trailing white space `=>`. Same as the single equal sign (`=`), except that it adds a trailing white space.
203
- * Output with leading white space `=<`. Same as the single equal sign (`=`), except that it adds a leading white space.
202
+ * Output with trailing white space `=>`. Same as the single equals sign (`=`), except that it adds a trailing white space.
203
+ * Output with leading white space `=<`. Same as the single equals sign (`=`), except that it adds a leading white space.
204
204
 
205
205
  ### Output without HTML escaping `==`
206
206
 
207
- 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.
207
+ Same as the single equals sign (`=`), but does not go through the `escape_html` method. For trailing or leading whitespace the modifiers `>` and `<` are supported.
208
208
 
209
- * Output without HTML escaping and trailing white space `==>`. Same as the double equal sign (`==`), except that it adds a trailing white space.
210
- * Output without HTML escaping and leading white space `==<`. Same as the double equal sign (`==`), except that it adds a leading white space.
209
+ * Output without HTML escaping and trailing white space `==>`. Same as the double equals sign (`==`), except that it adds a trailing white space.
210
+ * Output without HTML escaping and leading white space `==<`. Same as the double equals sign (`==`), except that it adds a leading white space.
211
211
 
212
212
  ### Code comment `/`
213
213
 
@@ -238,7 +238,7 @@ Use the forward slash immediately followed by an exclamation mark for html comme
238
238
  p Get a better browser.
239
239
  ~~~
240
240
 
241
- renders as
241
+ This renders as:
242
242
 
243
243
  ~~~ html
244
244
  <!--[if IE]><p>Get a better browser.</p><![endif]-->
@@ -246,9 +246,9 @@ renders as
246
246
 
247
247
  ## HTML tags
248
248
 
249
- ### Doctype tag
249
+ ### <!DOCTYPE> declaration
250
250
 
251
- The doctype tag is a special tag which can be used to generate the complex doctypes in a very simple way.
251
+ The doctype keyword can be used to generate the complex doctypes in a very simple manner.
252
252
 
253
253
  XML VERSION
254
254
 
@@ -513,7 +513,7 @@ this is done for class attributes with the white space as delimiter.
513
513
  a.menu class="highlight" href="http://slim-lang.com/" Slim-lang.com
514
514
  ~~~
515
515
 
516
- This renders as
516
+ This renders as:
517
517
 
518
518
  ~~~ html
519
519
  <a class="menu highlight" href="http://slim-lang.com/">Slim-lang.com</a>
@@ -528,13 +528,13 @@ a class=:menu,:highlight
528
528
 
529
529
  #### Splat attributes `*`
530
530
 
531
- The splat shortcut allows you turn a hash in to attribute/value pairs
531
+ The splat shortcut allows you to turn a hash into attribute/value pairs.
532
532
 
533
533
  ~~~ slim
534
534
  .card*{'data-url'=>place_path(place), 'data-id'=>place.id} = place.name
535
535
  ~~~
536
536
 
537
- renders as
537
+ This renders as:
538
538
 
539
539
  ~~~ html
540
540
  <div class="card" data-id="1234" data-url="/place/1234">Slim's house</div>
@@ -553,7 +553,7 @@ The hash attributes which support attribute merging (see Slim option `:merge_att
553
553
  .first *{class: [:second, :third]} Text
554
554
  ~~~
555
555
 
556
- renders as
556
+ This renders as:
557
557
 
558
558
  ~~~ html
559
559
  div class="first second third"
@@ -575,7 +575,7 @@ ruby:
575
575
  *a_unless_current Link
576
576
  ~~~
577
577
 
578
- renders as
578
+ This renders as:
579
579
 
580
580
  ~~~ html
581
581
  <span>Link</span><a href="http://slim-lang.com/">Link</a>
@@ -585,7 +585,7 @@ renders as
585
585
 
586
586
  #### Tag shortcuts
587
587
 
588
- You can define custom tag shortcuts by setting the option `:shortcut`.
588
+ You can define custom tag shortcuts by setting the option `:shortcut`. In Rails apps, you need to put this code for your shortcuts into an initializer like `config/initializers/slim.rb`. In Sinatra, you simply add the same configuration anywhere below the line where you `require 'slim'`.
589
589
 
590
590
  ~~~ ruby
591
591
  Slim::Engine.set_options shortcut: {'c' => {tag: 'container'}, '#' => {attr: 'id'}, '.' => {attr: 'class'} }
@@ -647,7 +647,7 @@ which renders to
647
647
  <div class="person" role="admin">Daniel</div>
648
648
  ~~~
649
649
 
650
- You can also set multiple attributes at once using one shortcut.
650
+ You can also set multiple attributes with same value at once using one shortcut.
651
651
 
652
652
  ~~~ ruby
653
653
  Slim::Engine.set_options shortcut: {'@' => {attr: %w(data-role role)}}
@@ -665,6 +665,29 @@ which renders to
665
665
  <div class="person" role="admin" data-role="admin">Daniel</div>
666
666
  ~~~
667
667
 
668
+ You can also set additional fixed value attributes to a shortcut.
669
+
670
+ ~~~ ruby
671
+ Slim::Engine.set_options shortcut: {'^' => {tag: 'script', attr: 'data-binding',
672
+ additional_attrs: { type: "text/javascript" }}}
673
+ ~~~
674
+
675
+ Then
676
+
677
+ ~~~ slim
678
+ ^products
679
+ == @products.to_json
680
+ ~~~
681
+
682
+ which renders to
683
+
684
+ ~~~ html
685
+ <script data-binding="products" type="text/javascript">
686
+ [{"name": "product1", "price": "$100"},
687
+ {"name": "prodcut2", "price": "$200"}]
688
+ </script>
689
+ ~~~
690
+
668
691
  #### ID shortcut `#` and class shortcut `.`
669
692
 
670
693
  You can specify the `id` and `class` attributes in the following shortcut form
@@ -818,7 +841,7 @@ body
818
841
 
819
842
  ## Embedded engines (Markdown, ...)
820
843
 
821
- Thanks to [Tilt](https://github.com/rtomayko/tilt), Slim has impressive support for embedding other template engines.
844
+ Thanks to [Tilt](https://github.com/rtomayko/tilt), Slim has extensive support for embedding other template engines.
822
845
 
823
846
  Examples:
824
847
 
@@ -842,7 +865,7 @@ Supported engines:
842
865
  | javascript: | none | Shortcut | Shortcut to embed javascript code and wrap in script tag |
843
866
  | css: | none | Shortcut | Shortcut to embed css code and wrap in style tag |
844
867
  | sass: | sass | Compile time | Embed sass code and wrap in style tag |
845
- | scss: | sass | Compile time | Embedd scss code and wrap in style tag |
868
+ | scss: | sass | Compile time | Embed scss code and wrap in style tag |
846
869
  | less: | less | Compile time | Embed less css code and wrap in style tag |
847
870
  | styl: | styl | Compile time | Embed stylus css code and wrap in style tag |
848
871
  | coffee: | coffee-script | Compile time | Compile coffee script code and wrap in script tag |
@@ -1080,6 +1103,7 @@ There are plugins for various text editors (including the most important ones -
1080
1103
  * [Textmate / Sublime Text](https://github.com/slim-template/ruby-slim.tmbundle)
1081
1104
  * [Espresso text editor](https://github.com/slim-template/Slim-Sugar)
1082
1105
  * [Coda](https://github.com/slim-template/Coda-2-Slim.mode)
1106
+ * [Atom](https://github.com/slim-template/language-slim)
1083
1107
 
1084
1108
  ### Template Converters (HAML, ERB, ...)
1085
1109
 
@@ -1181,6 +1205,7 @@ Syntax highlighting:
1181
1205
  Static code analysis:
1182
1206
 
1183
1207
  * [Slim-Lint](https://github.com/sds/slim-lint)
1208
+ * [SublimeLinter-slim-lint](https://github.com/elstgav/SublimeLinter-slim-lint)
1184
1209
 
1185
1210
  Template Converters (HAML, ERB, ...):
1186
1211
 
@@ -13,7 +13,7 @@ require 'haml'
13
13
 
14
14
  class SlimBenchmarks
15
15
  def initialize(slow)
16
- @benches = []
16
+ @benches = Hash.new { |h, k| h[k] = [] }
17
17
 
18
18
  @erb_code = File.read(File.dirname(__FILE__) + '/view.erb')
19
19
  @haml_code = File.read(File.dirname(__FILE__) + '/view.haml')
@@ -25,8 +25,8 @@ class SlimBenchmarks
25
25
  end
26
26
 
27
27
  def init_compiled_benches
28
- haml_pretty = Haml::Engine.new(@haml_code, format: :html5)
29
- haml_ugly = Haml::Engine.new(@haml_code, format: :html5, ugly: true)
28
+ haml_pretty = Haml::Engine.new(@haml_code, format: :html5, escape_attrs: false)
29
+ haml_ugly = Haml::Engine.new(@haml_code, format: :html5, ugly: true, escape_attrs: false)
30
30
 
31
31
  context = Context.new
32
32
 
@@ -41,14 +41,14 @@ class SlimBenchmarks
41
41
  def run_slim_ugly; #{Slim::Engine.new.call @slim_code}; end
42
42
  }
43
43
 
44
- bench('(1) erb') { context.run_erb }
45
- bench('(1) erubis') { context.run_erubis }
46
- bench('(1) fast erubis') { context.run_fast_erubis }
47
- bench('(1) temple erb') { context.run_temple_erb }
48
- bench('(1) slim pretty') { context.run_slim_pretty }
49
- bench('(1) slim ugly') { context.run_slim_ugly }
50
- bench('(1) haml pretty') { context.run_haml_pretty }
51
- bench('(1) haml ugly') { context.run_haml_ugly }
44
+ bench(:compiled, 'erb') { context.run_erb }
45
+ bench(:compiled, 'erubis') { context.run_erubis }
46
+ bench(:compiled, 'fast erubis') { context.run_fast_erubis }
47
+ bench(:compiled, 'temple erb') { context.run_temple_erb }
48
+ bench(:compiled, 'slim pretty') { context.run_slim_pretty }
49
+ bench(:compiled, 'slim ugly') { context.run_slim_ugly }
50
+ bench(:compiled, 'haml pretty') { context.run_haml_pretty }
51
+ bench(:compiled, 'haml ugly') { context.run_haml_ugly }
52
52
  end
53
53
 
54
54
  def init_tilt_benches
@@ -62,47 +62,54 @@ class SlimBenchmarks
62
62
 
63
63
  context = Context.new
64
64
 
65
- bench('(2) erb') { tilt_erb.render(context) }
66
- bench('(2) erubis') { tilt_erubis.render(context) }
67
- bench('(2) temple erb') { tilt_temple_erb.render(context) }
68
- bench('(2) slim pretty') { tilt_slim_pretty.render(context) }
69
- bench('(2) slim ugly') { tilt_slim_ugly.render(context) }
70
- bench('(2) haml pretty') { tilt_haml_pretty.render(context) }
71
- bench('(2) haml ugly') { tilt_haml_ugly.render(context) }
65
+ bench(:tilt, 'erb') { tilt_erb.render(context) }
66
+ bench(:tilt, 'erubis') { tilt_erubis.render(context) }
67
+ bench(:tilt, 'temple erb') { tilt_temple_erb.render(context) }
68
+ bench(:tilt, 'slim pretty') { tilt_slim_pretty.render(context) }
69
+ bench(:tilt, 'slim ugly') { tilt_slim_ugly.render(context) }
70
+ bench(:tilt, 'haml pretty') { tilt_haml_pretty.render(context) }
71
+ bench(:tilt, 'haml ugly') { tilt_haml_ugly.render(context) }
72
72
  end
73
73
 
74
74
  def init_parsing_benches
75
75
  context = Context.new
76
76
  context_binding = context.instance_eval { binding }
77
77
 
78
- bench('(3) erb') { ERB.new(@erb_code).result(context_binding) }
79
- bench('(3) erubis') { Erubis::Eruby.new(@erb_code).result(context_binding) }
80
- bench('(3) fast erubis') { Erubis::FastEruby.new(@erb_code).result(context_binding) }
81
- bench('(3) temple erb') { Temple::ERB::Template.new { @erb_code }.render(context) }
82
- bench('(3) slim pretty') { Slim::Template.new(pretty: true) { @slim_code }.render(context) }
83
- bench('(3) slim ugly') { Slim::Template.new { @slim_code }.render(context) }
84
- bench('(3) haml pretty') { Haml::Engine.new(@haml_code, format: :html5).render(context) }
85
- bench('(3) haml ugly') { Haml::Engine.new(@haml_code, format: :html5, ugly: true).render(context) }
78
+ bench(:parsing, 'erb') { ERB.new(@erb_code).result(context_binding) }
79
+ bench(:parsing, 'erubis') { Erubis::Eruby.new(@erb_code).result(context_binding) }
80
+ bench(:parsing, 'fast erubis') { Erubis::FastEruby.new(@erb_code).result(context_binding) }
81
+ bench(:parsing, 'temple erb') { Temple::ERB::Template.new { @erb_code }.render(context) }
82
+ bench(:parsing, 'slim pretty') { Slim::Template.new(pretty: true) { @slim_code }.render(context) }
83
+ bench(:parsing, 'slim ugly') { Slim::Template.new { @slim_code }.render(context) }
84
+ bench(:parsing, 'haml pretty') { Haml::Engine.new(@haml_code, format: :html5).render(context) }
85
+ bench(:parsing, 'haml ugly') { Haml::Engine.new(@haml_code, format: :html5, ugly: true).render(context) }
86
86
  end
87
87
 
88
88
  def run
89
- Benchmark.ips do |x|
90
- @benches.each do |name, block|
91
- x.report(name.to_s, &block)
89
+ @benches.each do |group_name, group_benches|
90
+ puts "Running #{group_name} benchmarks:"
91
+
92
+ Benchmark.ips do |x|
93
+ group_benches.each do |name, block|
94
+ x.report("#{group_name} #{name}", &block)
95
+ end
96
+
97
+ x.compare!
92
98
  end
93
99
  end
100
+
94
101
  puts "
95
- (1) Compiled benchmark. Template is parsed before the benchmark and
102
+ Compiled benchmark: Template is parsed before the benchmark and
96
103
  generated ruby code is compiled into a method.
97
104
  This is the fastest evaluation strategy because it benchmarks
98
105
  pure execution speed of the generated ruby code.
99
106
 
100
- (2) Compiled Tilt benchmark. Template is compiled with Tilt, which gives a more
107
+ Compiled Tilt benchmark: Template is compiled with Tilt, which gives a more
101
108
  accurate result of the performance in production mode in frameworks like
102
109
  Sinatra, Ramaze and Camping. (Rails still uses its own template
103
110
  compilation.)
104
111
 
105
- (3) Parsing benchmark. Template is parsed every time.
112
+ Parsing benchmark: Template is parsed every time.
106
113
  This is not the recommended way to use the template engine
107
114
  and Slim is not optimized for it. Activate this benchmark with 'rake bench slow=1'.
108
115
 
@@ -111,8 +118,8 @@ overhead added by the Temple framework compared to ERB.
111
118
  "
112
119
  end
113
120
 
114
- def bench(name, &block)
115
- @benches.push([name, block])
121
+ def bench(group, name, &block)
122
+ @benches[group].push([name, block])
116
123
  end
117
124
  end
118
125
 
@@ -55,7 +55,7 @@ The dictionary object is accessed in the order given by the `:dictionary_access`
55
55
 
56
56
  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.
57
57
 
58
- As you might have guessed, the article reference goes through the same steps against the dictionary. Instance variables are not allowed in the view code, but Slim will find and use them. Essentially, you're just using dropping the @ prefix in your template. Parameterized method calls are not allowed.
58
+ As you might have guessed, the article reference goes through the same steps against the dictionary. Instance variables are not allowed in the view code, but Slim will find and use them. Essentially, you're just dropping the @ prefix in your template. Parameterized method calls are not allowed.
59
59
 
60
60
 
61
61
  ## Strings
@@ -10,7 +10,7 @@ module Slim
10
10
  #
11
11
  # @api private
12
12
  class EndInserter < Filter
13
- IF_RE = /\A(if|unless|else|elsif|when|rescue|ensure)\b|\bdo\s*(\|[^\|]*\|)?\s*$/
13
+ IF_RE = /\A(if|begin|unless|else|elsif|when|rescue|ensure)\b|\bdo\s*(\|[^\|]*\|)?\s*$/
14
14
  ELSE_RE = /\A(else|elsif|when|rescue|ensure)\b/
15
15
  END_RE = /\Aend\b/
16
16
 
@@ -34,8 +34,6 @@ module Slim
34
34
  filter :ControlFlow
35
35
  filter :MultiFlattener
36
36
  filter :StaticMerger
37
- use :Generator do
38
- options[:generator].new(options.to_hash.reject {|k,v| !options[:generator].options.valid_key?(k) })
39
- end
37
+ use(:Generator) { options[:generator] }
40
38
  end
41
39
  end
@@ -55,13 +55,18 @@ module Slim
55
55
  @tab_re = "\t"
56
56
  @tab = ' '
57
57
  end
58
- @tag_shortcut, @attr_shortcut = {}, {}
58
+ @tag_shortcut, @attr_shortcut, @additional_attrs = {}, {}, {}
59
59
  options[:shortcut].each do |k,v|
60
- raise ArgumentError, 'Shortcut requires :tag and/or :attr' unless (v[:attr] || v[:tag]) && (v.keys - [:attr, :tag]).empty?
60
+ raise ArgumentError, 'Shortcut requires :tag and/or :attr' unless (v[:attr] || v[:tag]) && (v.keys - [:attr, :tag, :additional_attrs]).empty?
61
61
  @tag_shortcut[k] = v[:tag] || options[:default_tag]
62
+ if v.include?(:attr) || v.include?(:additional_attrs)
63
+ raise ArgumentError, 'You can only use special characters for attribute shortcuts' if k =~ /(\p{Word}|-)/
64
+ end
62
65
  if v.include?(:attr)
63
66
  @attr_shortcut[k] = [v[:attr]].flatten
64
- raise ArgumentError, 'You can only use special characters for attribute shortcuts' if k =~ /(\p{Word}|-)/
67
+ end
68
+ if v.include?(:additional_attrs)
69
+ @additional_attrs[k] = v[:additional_attrs]
65
70
  end
66
71
  end
67
72
  keys = Regexp.union @attr_shortcut.keys.sort_by {|k| -k.size }
@@ -221,13 +226,13 @@ module Slim
221
226
  # Found an output block.
222
227
  # We expect the line to be broken or the next line to be indented.
223
228
  @line = $'
224
- trailing_ws = $2.include?('>')
225
- if $2.include?('\'')
229
+ trailing_ws = $2.include?('>'.freeze)
230
+ if $2.include?('\''.freeze)
226
231
  deprecated_syntax '=\' for trailing whitespace is deprecated in favor of =>'
227
232
  trailing_ws = true
228
233
  end
229
234
  block = [:multi]
230
- @stacks.last << [:static, ' '] if $2.include?('<')
235
+ @stacks.last << [:static, ' '] if $2.include?('<'.freeze)
231
236
  @stacks.last << [:slim, :output, $1.empty?, parse_broken_line, block]
232
237
  @stacks.last << [:static, ' '] if trailing_ws
233
238
  @stacks << block
@@ -326,18 +331,23 @@ module Slim
326
331
  # because we don't want text interpolation in .class or #id shortcut
327
332
  syntax_error!('Illegal shortcut') unless shortcut = @attr_shortcut[$1]
328
333
  shortcut.each {|a| attributes << [:html, :attr, a, [:static, $2]] }
334
+ if additional_attr_pairs = @additional_attrs[$1]
335
+ additional_attr_pairs.each do |k,v|
336
+ attributes << [:html, :attr, k.to_s, [:static, v]]
337
+ end
338
+ end
329
339
  @line = $'
330
340
  end
331
341
 
332
342
  @line =~ /\A[<>']*/
333
343
  @line = $'
334
- trailing_ws = $&.include?('>')
335
- if $&.include?('\'')
344
+ trailing_ws = $&.include?('>'.freeze)
345
+ if $&.include?('\''.freeze)
336
346
  deprecated_syntax 'tag\' for trailing whitespace is deprecated in favor of tag>'
337
347
  trailing_ws = true
338
348
  end
339
349
 
340
- leading_ws = $&.include?('<')
350
+ leading_ws = $&.include?('<'.freeze)
341
351
 
342
352
  parse_attributes(attributes)
343
353
 
@@ -366,13 +376,13 @@ module Slim
366
376
  when /\A\s*=(=?)(['<>]*)/
367
377
  # Handle output code
368
378
  @line = $'
369
- trailing_ws2 = $2.include?('>')
370
- if $2.include?('\'')
379
+ trailing_ws2 = $2.include?('>'.freeze)
380
+ if $2.include?('\''.freeze)
371
381
  deprecated_syntax '=\' for trailing whitespace is deprecated in favor of =>'
372
382
  trailing_ws2 = true
373
383
  end
374
384
  block = [:multi]
375
- @stacks.last.insert(-2, [:static, ' ']) if !leading_ws && $2.include?('<')
385
+ @stacks.last.insert(-2, [:static, ' ']) if !leading_ws && $2.include?('<'.freeze)
376
386
  tag << [:slim, :output, $1 != '=', parse_broken_line, block]
377
387
  @stacks.last << [:static, ' '] if !trailing_ws && trailing_ws2
378
388
  @stacks << block
@@ -24,7 +24,7 @@ module Slim
24
24
  block = [:multi]
25
25
  until string.empty?
26
26
  case string
27
- when /\A&(\w+|#x[0-9a-f]+|#\d+);/i
27
+ when /\A&([a-z][a-z0-9]*|#x[0-9a-f]+|#\d+);/i
28
28
  # Entity.
29
29
  block << [:escape, false, [:static, $&]]
30
30
  string = $'
@@ -1,5 +1,5 @@
1
1
  module Slim
2
2
  # Slim version string
3
3
  # @api public
4
- VERSION = '3.0.6'
4
+ VERSION = '3.0.7'
5
5
  end
@@ -19,6 +19,6 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.required_ruby_version = '>=1.9.2'
21
21
 
22
- s.add_runtime_dependency('temple', ['~> 0.7.3'])
22
+ s.add_runtime_dependency('temple', ['~> 0.7.6'])
23
23
  s.add_runtime_dependency('tilt', ['>= 1.3.3', '< 2.1'])
24
24
  end
@@ -13,6 +13,24 @@ div
13
13
  assert_html '<div><p>The second paragraph</p></div>', source
14
14
  end
15
15
 
16
+ def test_render_with_begin
17
+ source = %q{
18
+ - if true
19
+ - begin
20
+ p A
21
+ - if true
22
+ - begin
23
+ p B
24
+ - if true
25
+ - begin
26
+ p C
27
+ - rescue
28
+ p D
29
+ }
30
+
31
+ assert_html '<p>A</p><p>B</p><p>C</p>', source
32
+ end
33
+
16
34
  def test_render_with_consecutive_conditionals
17
35
  source = %q{
18
36
  div
@@ -99,6 +99,22 @@ h1#title This is my title
99
99
  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'}}
100
100
  end
101
101
 
102
+ def test_render_with_custom_array_shortcut
103
+ source = %q{
104
+ #user@.admin Daniel
105
+ }
106
+ assert_html '<div class="admin" id="user" role="admin">Daniel</div>', source, shortcut: {'#' => {attr: 'id'}, '.' => {attr: 'class'}, '@' => {attr: 'role'}, '@.' => {attr: ['class', 'role']}}
107
+ end
108
+
109
+ def test_render_with_custom_shortcut_and_additional_attrs
110
+ source = %q{
111
+ ^items
112
+ == "[{'title':'item0'},{'title':'item1'},{'title':'item2'},{'title':'item3'},{'title':'item4'}]"
113
+ }
114
+ assert_html '<script data-binding="items" type="application/json">[{\'title\':\'item0\'},{\'title\':\'item1\'},{\'title\':\'item2\'},{\'title\':\'item3\'},{\'title\':\'item4\'}]</script>',
115
+ source, shortcut: {'^' => {tag: 'script', attr: 'data-binding', additional_attrs: { type: "application/json" }}}
116
+ end
117
+
102
118
  def test_render_with_text_block
103
119
  source = %q{
104
120
  p
@@ -99,14 +99,14 @@ p
99
99
  > Escaped <&>.
100
100
  Protected &amp; &lt; &gt; &copy; &Aacute;.
101
101
  Protected &#0129; &#x00ff;.
102
- Escaped &#xx; &#1f; &;.
102
+ Escaped &#xx; &#1f; &9; &_; &;.
103
103
  }
104
104
 
105
105
  result = %q{Not escaped <&>.<p>Escaped &lt;&amp;&gt;.</p><p>Escaped &lt;&amp;&gt;.
106
106
  Escaped &lt;&amp;&gt;.
107
107
  Protected &amp; &lt; &gt; &copy; &Aacute;.
108
108
  Protected &#0129; &#x00ff;.
109
- Escaped &amp;#xx; &amp;#1f; &amp;;.</p>}
109
+ Escaped &amp;#xx; &amp;#1f; &amp;9; &amp;_; &amp;;.</p>}
110
110
 
111
111
  assert_html result, source
112
112
  end
@@ -121,14 +121,14 @@ p
121
121
  > Not escaped <&>.
122
122
  Not escaped &amp; &lt; &gt; &copy; &Aacute;.
123
123
  Not escaped &#0129; &#x00ff;.
124
- Not escaped &#xx; &#1f; &;.
124
+ Not escaped &#xx; &#1f; &9; &_; &;.
125
125
  }
126
126
 
127
127
  result = %q{<p>Not escaped <&>.</p>Not escaped <&>.<p>Not escaped <&>.
128
128
  Not escaped <&>.
129
129
  Not escaped &amp; &lt; &gt; &copy; &Aacute;.
130
130
  Not escaped &#0129; &#x00ff;.
131
- Not escaped &#xx; &#1f; &;.</p>}
131
+ Not escaped &#xx; &#1f; &9; &_; &;.</p>}
132
132
 
133
133
  assert_html result, source
134
134
  end
@@ -139,13 +139,13 @@ Not escaped &#xx; &#1f; &;.</p>}
139
139
  p Escaped <&>.
140
140
  Protected &amp; &lt; &gt; &copy; &Aacute;.
141
141
  Protected &#0129; &#x00ff;.
142
- Escaped &#xx; &#1f; &;.
142
+ Escaped &#xx; &#1f; &9; &_; &;.
143
143
  }
144
144
 
145
145
  result = %q{<p>Escaped &lt;&amp;&gt;.
146
146
  Protected &amp; &lt; &gt; &copy; &Aacute;.
147
147
  Protected &#0129; &#x00ff;.
148
- Escaped &amp;#xx; &amp;#1f; &amp;;.</p>}
148
+ Escaped &amp;#xx; &amp;#1f; &amp;9; &amp;_; &amp;;.</p>}
149
149
 
150
150
  assert_html result, source
151
151
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slim
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.6
4
+ version: 3.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Mendler
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-06-05 00:00:00.000000000 Z
13
+ date: 2016-05-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: temple
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: 0.7.3
21
+ version: 0.7.6
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: 0.7.3
28
+ version: 0.7.6
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: tilt
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -203,4 +203,3 @@ signing_key:
203
203
  specification_version: 4
204
204
  summary: Slim is a template language.
205
205
  test_files: []
206
- has_rdoc: