slim 2.0.0 → 2.0.1

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: e4a9425fd0b4b76c20a920f76d2d5de37e0f411c
4
- data.tar.gz: 627435a655daa4b54f1ed18baf5a58302f1d5fc1
3
+ metadata.gz: 89b79547893a3fcfe80dc8f1a77b5e7eb94fb69e
4
+ data.tar.gz: 68744041f28214f56c5c12559db00e9edb4cc3d0
5
5
  SHA512:
6
- metadata.gz: 522bfc01a26bc8ce325599b25cd85de310c97d5d40b3cc5fb84b8b1f3fae592bb1ea0ed2a6738156082d65e77ee1afec9ce5d08ab34fb9d5d27fe86290b36160
7
- data.tar.gz: 2e784025e8bc003385e120990660e449d0950acee036219ca73dc289c932b39876d782cd13f8972a91f85ed41439ed99ca3b8222f2eff7cde8fe65a128485202
6
+ metadata.gz: 124098d00c5f8aec79387b13ea46f04df1c7b158d2aa8d27d858e6e62ed9b7814bbfdf08fd474a8d7b62e61df5a23454e10ee188997506352dd6980fa6517954
7
+ data.tar.gz: 392e37c3702ba5b2c84a9c6b763be82083d06cabad6155da9bcc9e4a5b4cffa612ad76d91654cd4451b024d5842fd1b8066a077d70ea756eecd81f606dfce1c7
@@ -12,11 +12,12 @@ env:
12
12
  - "TASK=test:core_and_plugins TILT=master"
13
13
  - "TASK=test:core_and_plugins TILT=1.3.4"
14
14
  - "TASK=test:core_and_plugins TILT=1.4.1"
15
+ - "TASK=test:core_and_plugins TILT=2.0.0.beta1"
15
16
  - "TASK=test:rails RAILS=master"
16
17
  - "TASK=test:rails RAILS=3.0.20"
17
18
  - "TASK=test:rails RAILS=3.1.12"
18
19
  - "TASK=test:rails RAILS=3.2.13"
19
- - "TASK=test:rails RAILS=4.0.0.rc1"
20
+ - "TASK=test:rails RAILS=4.0.0"
20
21
  - "TASK=test:sinatra SINATRA=master"
21
22
  - "TASK=test:sinatra SINATRA=1.3.6"
22
23
  - "TASK=test:sinatra SINATRA=1.4.2"
@@ -32,11 +33,11 @@ matrix:
32
33
  - rvm: rbx-18mode
33
34
  env: "TASK=test:rails RAILS=master"
34
35
  - rvm: 1.8.7
35
- env: "TASK=test:rails RAILS=4.0.0.rc1"
36
+ env: "TASK=test:rails RAILS=4.0.0"
36
37
  - rvm: jruby-18mode
37
- env: "TASK=test:rails RAILS=4.0.0.rc1"
38
+ env: "TASK=test:rails RAILS=4.0.0"
38
39
  - rvm: rbx-18mode
39
- env: "TASK=test:rails RAILS=4.0.0.rc1"
40
+ env: "TASK=test:rails RAILS=4.0.0"
40
41
  allow_failures:
41
42
  - env: "TASK=test:core_and_plugins TILT=master"
42
43
  - env: "TASK=test:rails RAILS=master"
data/.yardopts CHANGED
@@ -1,3 +1,4 @@
1
1
  --markup-provider redcarpet
2
2
  --markup markdown
3
- - README.md CHANGES LICENSE test/literate/TESTS.md
3
+ - README.md CHANGES LICENSE test/literate/TESTS.md doc/logic_less.md doc/translator.md
4
+
data/CHANGES CHANGED
@@ -1,3 +1,12 @@
1
+ 2.0.1
2
+
3
+ * Support multiple attributes per shortcut (See issue #415)
4
+ * Add support for org-ruby embedded engine
5
+ * Render true boolean attributes with empty value
6
+ * Support case-when statements
7
+ * Fix issue #431
8
+ * Also escape ' to '
9
+
1
10
  2.0.0
2
11
 
3
12
  * IMPORTANT: Backward incompatible syntax change: '{...}' and '[...]' are not
data/Gemfile CHANGED
@@ -39,6 +39,7 @@ gem 'kramdown'
39
39
  gem 'creole'
40
40
  gem 'builder'
41
41
  gem 'asciidoctor'
42
+ gem 'org-ruby'
42
43
  gem 'minitest', '~> 4.7.4'
43
44
 
44
45
  if ENV['TASK'] == 'bench'
data/README.md CHANGED
@@ -50,7 +50,7 @@ as good as possible.
50
50
  ### What is Slim?
51
51
 
52
52
  Slim is a fast, lightweight templating engine with support for __Rails 3 and 4__. It has been heavily tested on all major ruby implementations. We use
53
- continous integration (travis-ci).
53
+ continuous integration (travis-ci).
54
54
 
55
55
  Slim's core syntax is guided by one thought: "What's the minimum required to make this work".
56
56
 
@@ -417,7 +417,7 @@ You can also break ruby attributes with backslash `\` or trailing `,` as describ
417
417
  #### Boolean attributes
418
418
 
419
419
  The attribute values `true`, `false` and `nil` are interpreted
420
- as booleans. If you use the attribut wrapper you can omit the attribute assigment
420
+ as booleans. If you use the attribute wrapper you can omit the attribute assigment.
421
421
 
422
422
  input type="text" disabled="disabled"
423
423
  input type="text" disabled=true
@@ -532,6 +532,18 @@ which renders to
532
532
 
533
533
  <div class="person" role="admin">Daniel</div>
534
534
 
535
+ You can also set multiple attributes at once using one shortcut.
536
+
537
+ Slim::Engine.set_default_options :shortcut => {'@' => {:attr => %w(data-role role)}}
538
+
539
+ We can use it in Slim code like this
540
+
541
+ .person@admin = person.name
542
+
543
+ which renders to
544
+
545
+ <div class="person" role="admin" data-role="admin">Daniel</div>
546
+
535
547
  #### ID shortcut `#` and class shortcut `.`
536
548
 
537
549
  Similarly to Haml, you can specify the `id` and `class` attributes in the following shortcut form
@@ -610,28 +622,25 @@ Examples:
610
622
 
611
623
  Supported engines:
612
624
 
613
- <table>
614
- <thead style="font-weight:bold"><tr><td>Filter</td><td>Required gems</td><td>Type</td><td>Description</td></tr></thead>
615
- <tbody>
616
- <tr><td>ruby:</td><td>none</td><td>Shortcut</td><td>Shortcut to embed ruby code</td></tr>
617
- <tr><td>javascript:</td><td>none</td><td>Shortcut</td><td>Shortcut to embed javascript code and wrap in script tag</td></tr>
618
- <tr><td>css:</td><td>none</td><td>Shortcut</td><td>Shortcut to embed css code and wrap in style tag</td></tr>
619
- <tr><td>sass:</td><td>sass</td><td>Compile time</td><td>Embed sass code and wrap in style tag</td></tr>
620
- <tr><td>scss:</td><td>sass</td><td>Compile time</td><td>Embedd scss code and wrap in style tag</td></tr>
621
- <tr><td>less:</td><td>less</td><td>Compile time</td><td>Embed less css code and wrap in style tag</td></tr>
622
- <tr><td>styl:</td><td>styl</td><td>Compile time</td><td>Embed stylus css code and wrap in style tag</td></tr>
623
- <tr><td>coffee:</td><td>coffee-script</td><td>Compile time</td><td>Compile coffee script code and wrap in script tag</td></tr>
624
- <tr><td>asciidoc:</td><td>asciidoctor</td><td>Compile time + Interpolation</td><td>Compile AsciiDoc code and interpolate #\{variables} in text</td></tr>
625
- <tr><td>markdown:</td><td>redcarpet/rdiscount/kramdown</td><td>Compile time + Interpolation</td><td>Compile markdown code and interpolate #\{variables} in text</td></tr>
626
- <tr><td>textile:</td><td>redcloth</td><td>Compile time + Interpolation</td><td>Compile textile code and interpolate #\{variables} in text</td></tr>
627
- <tr><td>creole:</td><td>creole</td><td>Compile time + Interpolation</td><td>Compile creole code and interpolate #\{variables} in text</td></tr>
628
- <tr><td>wiki:, mediawiki:</td><td>wikicloth</td><td>Compile time + Interpolation</td><td>Compile wiki code and interpolate #\{variables} in text</td></tr>
629
- <tr><td>rdoc:</td><td>rdoc</td><td>Compile time + Interpolation</td><td>Compile rdoc code and interpolate #\{variables} in text</td></tr>
630
- <tr><td>builder:</td><td>builder</td><td>Precompiled</td><td>Embed builder code</td></tr>
631
- <tr><td>nokogiri:</td><td>nokogiri</td><td>Precompiled</td><td>Embed nokogiri builder code</td></tr>
632
- <tr><td>erb:</td><td>none</td><td>Precompiled</td><td>Embed erb code</td></tr>
633
- </tbody>
634
- </table>
625
+ | Filter | Required gems | Type | Description |
626
+ | ------ | ------------- | ---- | ----------- |
627
+ | ruby: | none | Shortcut | Shortcut to embed ruby code |
628
+ | javascript: | none | Shortcut | Shortcut to embed javascript code and wrap in script tag |
629
+ | css: | none | Shortcut | Shortcut to embed css code and wrap in style tag |
630
+ | sass: | sass | Compile time | Embed sass code and wrap in style tag |
631
+ | scss: | sass | Compile time | Embedd scss code and wrap in style tag |
632
+ | less: | less | Compile time | Embed less css code and wrap in style tag |
633
+ | styl: | styl | Compile time | Embed stylus css code and wrap in style tag |
634
+ | coffee: | coffee-script | Compile time | Compile coffee script code and wrap in script tag |
635
+ | asciidoc: | asciidoctor | Compile time + Interpolation | Compile AsciiDoc code and interpolate #\{variables} in text |
636
+ | markdown: | redcarpet/rdiscount/kramdown | Compile time + Interpolation | Compile markdown code and interpolate #\{variables} in text |
637
+ | textile: | redcloth | Compile time + Interpolation | Compile textile code and interpolate #\{variables} in text |
638
+ | creole: | creole | Compile time + Interpolation | Compile creole code and interpolate #\{variables} in text |
639
+ | wiki:, mediawiki: | wikicloth | Compile time + Interpolation | Compile wiki code and interpolate #\{variables} in text |
640
+ | rdoc: | rdoc | Compile time + Interpolation | Compile rdoc code and interpolate #\{variables} in text |
641
+ | builder: | builder | Precompiled | Embed builder code |
642
+ | nokogiri: | nokogiri | Precompiled | Embed nokogiri builder code |
643
+ | erb: | none | Precompiled | Embed erb code |
635
644
 
636
645
  The embedded engines can be configured in Slim by setting the options directly on the `Slim::Embedded` filter. Example:
637
646
 
@@ -686,32 +695,31 @@ You have to be aware that the compiled engine code and the options are cached pe
686
695
  The following options are exposed by the `Slim::Engine` and can be set with `Slim::Engine.set_default_options`.
687
696
  There are a lot of them but the good thing is, that Slim checks the configuration keys and reports an error if you try to use an invalid configuration key.
688
697
 
689
- <table>
690
- <thead style="font-weight:bold"><tr><td>Type</td><td>Name</td><td>Default</td><td>Purpose</td></tr></thead>
691
- <tbody>
692
- <tr><td>String</td><td>:file</td><td>nil</td><td>Name of parsed file, set automatically by Slim::Template</td></tr>
693
- <tr><td>Integer</td><td>:tabsize</td><td>4</td><td>Number of white spaces per tab (used by the parser)</td></tr>
694
- <tr><td>String</td><td>:encoding</td><td>"utf-8"</td><td>Set encoding of template</td></tr>
695
- <tr><td>String</td><td>:default_tag</td><td>"div"</td><td>Default tag to be used if tag name is omitted</td></tr>
696
- <tr><td>Hash</td><td>:shortcut</td><td>\{'.' => {:attr => 'class'}, '#' => {:attr => 'id'}}</td><td>Attribute shortcuts</td></tr>
697
- <tr><td>Array&lt;Symbol,String&gt;</td><td>:enable_engines</td><td>nil <i>(All enabled)</i></td><td>List of enabled embedded engines (whitelist)</td></tr>
698
- <tr><td>Array&lt;Symbol,String&gt;</td><td>:disable_engines</td><td>nil <i>(None disabled)</i></td><td>List of disabled embedded engines (blacklist)</td></tr>
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>
700
- <tr><td>Boolean</td><td>:disable_escape</td><td>false</td><td>Disable automatic escaping of strings</td></tr>
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>
702
- <tr><td>Symbol</td><td>:format</td><td>:xhtml</td><td>HTML output format (Possible formats :xhtml, :html4, :html5, :html)</td></tr>
703
- <tr><td>String</td><td>:attr_quote</td><td>'"'</td><td>Character to wrap attributes in html (can be ' or ")</td></tr>
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&lt;String&gt;</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>
706
- <tr><td>Boolean</td><td>:sort_attrs</td><td>true</td><td>Sort attributes by name</td></tr>
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>
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>
709
- <tr><td>String</td><td>:indent</td><td>' '</td><td>Indentation string</td></tr>
710
- <tr><td>Boolean</td><td>:streaming</td><td>false (true in Rails > 3.1)</td><td>Enable output streaming</td></tr>
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>
712
- <tr><td>String</td><td>:buffer</td><td>'_buf' ('@output_buffer' in Rails)</td><td>Variable used for buffer</td></tr>
713
- </tbody>
714
- </table>
698
+
699
+ | Type | Name | Default | Purpose |
700
+ | ---- | ---- | ------- | ------- |
701
+ | String | :file | nil | Name of parsed file, set automatically by Slim::Template |
702
+ | Integer | :tabsize | 4 | Number of white spaces per tab (used by the parser) |
703
+ | String | :encoding | "utf-8" | Set encoding of template |
704
+ | String | :default_tag | "div" | Default tag to be used if tag name is omitted |
705
+ | Hash | :shortcut | \{'.' => {:attr => 'class'}, '#' => {:attr => 'id'}} | Attribute shortcuts |
706
+ | Array&lt;Symbol,String&gt; | :enable_engines | nil <i>(All enabled)</i> | List of enabled embedded engines (whitelist) |
707
+ | Array&lt;Symbol,String&gt; | :disable_engines | nil <i>(None disabled)</i> | List of disabled embedded engines (blacklist) |
708
+ | Boolean | :disable_capture | false (true in Rails) | Disable capturing in blocks (blocks write to the default buffer |
709
+ | Boolean | :disable_escape | false | Disable automatic escaping of strings |
710
+ | Boolean | :use_html_safe | false (true in Rails) | Use String#html_safe? from ActiveSupport (Works together with :disable_escape) |
711
+ | Symbol | :format | :xhtml | HTML output format (Possible formats :xhtml, :html4, :html5, :html) |
712
+ | String | :attr_quote | '"' | Character to wrap attributes in html (can be ' or ") |
713
+ | Hash | :merge_attrs | \{'class' => ' '} | Joining character used if multiple html attributes are supplied (e.g. class="class1 class2") |
714
+ | Array&lt;String&gt; | :hyphen_attrs | %w(data) | 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") |
715
+ | Boolean | :sort_attrs | true | Sort attributes by name |
716
+ | Symbol | :js_wrapper | nil | Wrap javascript by :comment, :cdata or :both. You can also :guess the wrapper based on :format. |
717
+ | Boolean | :pretty | false | Pretty HTML indenting, only block level tags are indented <b>(This is slower!)</b> |
718
+ | String | :indent | ' ' | Indentation string |
719
+ | Boolean | :streaming | false (true in Rails > 3.1) | Enable output streaming |
720
+ | Class | :generator | Temple::Generators::ArrayBuffer/ RailsOutputBuffer | Temple code generator (default generator generates array buffer) |
721
+ | String | :buffer | '_buf' ('@output_buffer' in Rails) | Variable used for buffer |
722
+
715
723
 
716
724
  There are more options which are supported by the Temple filters but which are not exposed and are not officially supported. You
717
725
  have to take a look at the Slim and Temple code for that.
@@ -857,17 +865,18 @@ run the slow parsing benchmark which needs more time. You can also increase the
857
865
 
858
866
  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>
859
867
 
860
- ### Test suite and continous integration
868
+ ### Test suite and continuous integration
861
869
 
862
870
  Slim provides an extensive test-suite based on minitest. You can run the tests
863
871
  with 'rake test' and the rails integration tests with 'rake test:rails'.
864
872
 
865
873
  We are currently experimenting with human-readable literate tests which are written as markdown files: [TESTS.md](test/literate/TESTS.md)
866
874
 
867
- Travis-CI is used for continous integration testing: <http://travis-ci.org/#!/slim-template/slim>
875
+ Travis-CI is used for continuous integration testing: <http://travis-ci.org/#!/slim-template/slim>
868
876
 
869
877
  Slim is working well on all major Ruby implementations:
870
878
 
879
+ * Ruby 2.0.0
871
880
  * Ruby 1.8.7
872
881
  * Ruby 1.9.2
873
882
  * Ruby 1.9.3
@@ -883,9 +892,9 @@ If you'd like to help improve Slim, clone the project with Git by running:
883
892
 
884
893
  Work your magic and then submit a pull request. We love pull requests!
885
894
 
886
- Please remember to test against Ruby versions 1.9.2 and 1.8.7.
895
+ Please remember to test against Ruby versions 2.0.0, 1.9.3 and 1.8.7.
887
896
 
888
- If you find the documentation lacking (and you probably will), help us out and update this README.md. If you don't have the time to work on Slim, but found something we should know about, please submit an issue.
897
+ If you find the documentation lacking, help us out and update this README.md. If you don't have the time to work on Slim, but found something we should know about, please submit an issue.
889
898
 
890
899
  ## License
891
900
 
@@ -934,3 +943,4 @@ Language ports/Similar languages:
934
943
  * [Emblem.js (Javascript, similar to Slim)](https://github.com/machty/emblem.js)
935
944
  * [Haml (Older engine which inspired Slim)](https://github.com/haml/haml)
936
945
  * [Jade (Similar engine for javascript)](https://github.com/visionmedia/jade)
946
+ * [Sweet (Similar engine which also allows to write classes and functions)](https://github.com/joaomdmoura/sweet)
data/Rakefile CHANGED
@@ -48,6 +48,7 @@ namespace 'test' do
48
48
  end
49
49
 
50
50
  begin
51
+ require 'rubygems'
51
52
  require 'sinatra'
52
53
  spec = Gem::Specification.find_by_name('sinatra')
53
54
  Rake::TestTask.new('sinatra') do |t|
@@ -130,11 +130,8 @@ and activate logic less mode per render call in your application
130
130
 
131
131
  ## Options
132
132
 
133
- <table>
134
- <thead style="font-weight:bold"><tr><td>Type</td><td>Name</td><td>Default</td><td>Purpose</td></tr></thead>
135
- <tbody>
136
- <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>
137
- <tr><td>String</td><td>:dictionary</td><td>"self"</td><td>Dictionary where variables are looked up</td></tr>
138
- <tr><td>Symbol/Array&lt;Symbol&gt;</td><td>:dictionary_access</td><td>[:symbol, :string, :method, :instance_variable]</td><td>Dictionary access order (:symbol, :string, :method, :instance_variable)</td></tr>
139
- </tbody>
140
- </table>
133
+ | Type | Name | Default | Purpose |
134
+ | ---- | ---- | ------- | ------- |
135
+ | Boolean | :logic_less | true | Enable logic less mode (Enabled if 'slim/logic_less' is required) |
136
+ | String | :dictionary | "self" | Dictionary where variables are looked up |
137
+ | Symbol/Array&lt;Symbol&gt; | :dictionary_access | [:symbol, :string, :method, :instance_variable] | Dictionary access order (:symbol, :string, :method, :instance_variable) |
@@ -21,11 +21,8 @@ Enable the translator plugin with
21
21
 
22
22
  # Options
23
23
 
24
- <table>
25
- <thead style="font-weight:bold"><tr><td>Type</td><td>Name</td><td>Default</td><td>Purpose</td></tr></thead>
26
- <tbody>
27
- <tr><td>Boolean</td><td>:tr</td><td>true</td><td>Enable translator (Enabled if 'slim/translator' is required)</td></tr>
28
- <tr><td>Symbol</td><td>:tr_mode</td><td>:dynamic</td><td>When to translate: :static = at compile time, :dynamic = at runtime</td></tr>
29
- <tr><td>String</td><td>:tr_fn</td><td>Depending on installed translation library</td><td>Translation function, could be '_' for gettext</td></tr>
30
- </tbody>
31
- </table>
24
+ | Type | Name | Default | Purpose |
25
+ | ---- | ---- | ------- | ------- |
26
+ | Boolean | :tr | true | Enable translator (Enabled if 'slim/translator' is required) |
27
+ | Symbol | :tr_mode | :dynamic | When to translate: :static = at compile time, :dynamic = at runtime |
28
+ | String | :tr_fn | Depending on installed translation library | Translation function, could be '_' for gettext |
@@ -11,7 +11,7 @@ module Slim
11
11
  [:multi, *attrs.map {|a| compile(a) }]
12
12
  end
13
13
 
14
- # Handle attribute expression `[:html, :attr, escape, code]`
14
+ # Handle attribute expression `[:html, :attr, name, value]`
15
15
  #
16
16
  # @param [String] name Attribute name
17
17
  # @param [Array] value Value expression
@@ -22,7 +22,7 @@ module Slim
22
22
  escape, code = value[2], value[3]
23
23
  case code
24
24
  when 'true'
25
- [:html, :attr, name, [:static, name]]
25
+ [:html, :attr, name, [:multi]]
26
26
  when 'false', 'nil'
27
27
  [:multi]
28
28
  else
@@ -30,7 +30,7 @@ module Slim
30
30
  [:multi,
31
31
  [:code, "#{tmp} = #{code}"],
32
32
  [:case, tmp,
33
- ['true', [:html, :attr, name, [:static, name]]],
33
+ ['true', [:html, :attr, name, [:multi]]],
34
34
  ['false, nil', [:multi]],
35
35
  [:else, [:html, :attr, name, [:escape, escape, [:dynamic, tmp]]]]]]
36
36
  end
@@ -65,7 +65,7 @@ module Slim
65
65
 
66
66
  opts.on('-o', '--option [NAME=CODE]', String, 'Set slim option') do |str|
67
67
  parts = str.split('=', 2)
68
- Engine.default_options[parts.first.to_sym] = eval(parts.last)
68
+ Engine.default_options[parts.first.gsub(/\A:/, '').to_sym] = eval(parts.last)
69
69
  end
70
70
 
71
71
  opts.on_tail('-h', '--help', 'Show this message') do
@@ -7,7 +7,7 @@ module Slim
7
7
  #
8
8
  # @api private
9
9
  class DoInserter < Filter
10
- BLOCK_REGEX = /(\A(if|unless|else|elsif|when|begin|rescue|ensure)\b)|do\s*(\|[^\|]*\|\s*)?\Z/
10
+ BLOCK_REGEX = /(\A(if|unless|else|elsif|when|begin|rescue|ensure|case)\b)|do\s*(\|[^\|]*\|\s*)?\Z/
11
11
 
12
12
  # Handle control expression `[:slim, :control, code, content]`
13
13
  #
@@ -248,6 +248,7 @@ module Slim
248
248
  register :creole, InterpolateTiltEngine
249
249
  register :wiki, InterpolateTiltEngine
250
250
  register :mediawiki, InterpolateTiltEngine
251
+ register :org, InterpolateTiltEngine
251
252
 
252
253
  # These engines are executed at compile time
253
254
  register :coffee, JavaScriptEngine, :engine => StaticTiltEngine
@@ -9,7 +9,6 @@ module Slim
9
9
  :sort_attrs => true,
10
10
  :attr_quote => '"',
11
11
  :merge_attrs => {'class' => ' '},
12
- :encoding => 'utf-8',
13
12
  :generator => Temple::Generators::ArrayBuffer,
14
13
  :default_tag => 'div'
15
14
 
@@ -48,12 +48,14 @@ module Slim
48
48
  raise ArgumentError, 'Shortcut requires :tag and/or :attr' unless (v[:attr] || v[:tag]) && (v.keys - [:attr, :tag]).empty?
49
49
  @tag_shortcut[k] = v[:tag] || options[:default_tag]
50
50
  if v.include?(:attr)
51
- @attr_shortcut[k] = v[:attr]
51
+ @attr_shortcut[k] = [v[:attr]].flatten
52
52
  raise ArgumentError, 'You can only use special characters for attribute shortcuts' if k =~ /(#{WORD_RE}|-)/
53
53
  end
54
54
  end
55
- @attr_shortcut_re = /\A(#{Regexp.union @attr_shortcut.keys})(#{WORD_RE}(?:#{WORD_RE}|-)*#{WORD_RE}|#{WORD_RE}+)/
56
- @tag_re = /\A(?:#{Regexp.union @tag_shortcut.keys}|\*(?=[^\s]+)|(#{WORD_RE}(?:#{WORD_RE}|:|-)*#{WORD_RE}|#{WORD_RE}+))/
55
+ keys = Regexp.union @attr_shortcut.keys.sort_by {|k| -k.size }
56
+ @attr_shortcut_re = /\A(#{keys}+)(#{WORD_RE}(?:#{WORD_RE}|-)*#{WORD_RE}|#{WORD_RE}+)/
57
+ keys = Regexp.union @tag_shortcut.keys.sort_by {|k| -k.size }
58
+ @tag_re = /\A(?:#{keys}|\*(?=[^\s]+)|(#{WORD_RE}(?:#{WORD_RE}|:|-)*#{WORD_RE}|#{WORD_RE}+))/
57
59
  end
58
60
 
59
61
  # Compile string to Temple expression
@@ -302,7 +304,8 @@ module Slim
302
304
  while @line =~ @attr_shortcut_re
303
305
  # The class/id attribute is :static instead of :slim :interpolate,
304
306
  # because we don't want text interpolation in .class or #id shortcut
305
- attributes << [:html, :attr, @attr_shortcut[$1], [:static, $2]]
307
+ syntax_error!('Illegal shortcut') unless shortcut = @attr_shortcut[$1]
308
+ shortcut.each {|a| attributes << [:html, :attr, a, [:static, $2]] }
306
309
  @line = $'
307
310
  end
308
311
 
@@ -20,7 +20,7 @@ module Slim
20
20
  return
21
21
  when true
22
22
  # Boolean true attribute
23
- value = name
23
+ value = ''
24
24
  else
25
25
  value = value.to_s
26
26
  end
@@ -24,16 +24,15 @@ module Slim
24
24
  # @param [Array] content Temple expression
25
25
  # @return [Array] Compiled temple expression
26
26
  def on_html_tag(name, attrs, content = nil)
27
- if name != '*'
28
- super
29
- elsif content
30
- builder, block = make_builder(attrs[2..-1])
27
+ return super if name != '*'
28
+ builder, block = make_builder(attrs[2..-1])
29
+ if content
31
30
  [:multi,
32
31
  block,
33
- [:slim, :output, false, "#{builder}.build_tag do",
32
+ [:slim, :output, false,
33
+ "#{builder}.build_tag #{empty_exp?(content) ? '{}' : 'do'}",
34
34
  compile(content)]]
35
35
  else
36
- builder, block = make_builder(attrs[2..-1])
37
36
  [:multi,
38
37
  block,
39
38
  [:dynamic, "#{builder}.build_tag"]]
@@ -1,5 +1,5 @@
1
1
  module Slim
2
2
  # Slim version string
3
3
  # @api public
4
- VERSION = '2.0.0'
4
+ VERSION = '2.0.1'
5
5
  end
@@ -12,11 +12,12 @@ Gem::Specification.new do |s|
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/'
14
14
  s.rubyforge_project = s.name
15
+ s.license = 'MIT'
15
16
 
16
- s.files = `git ls-files`.split("\n")
17
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
- s.require_paths = %w(lib)
17
+ s.files = `git ls-files`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = %w(lib)
19
20
 
20
- s.add_runtime_dependency('temple', ['~> 0.6.5'])
21
- s.add_runtime_dependency('tilt', ['~> 1.3', '>= 1.3.3'])
21
+ s.add_runtime_dependency('temple', ['~> 0.6.6'])
22
+ s.add_runtime_dependency('tilt', ['>= 1.3.3', '< 2.1'])
22
23
  end
@@ -59,11 +59,11 @@ class TestSlim < MiniTest::Unit::TestCase
59
59
  if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
60
60
  # HACK: Rubinius stack trace sometimes has one entry more
61
61
  if ex.backtrace[0] !~ /^#{Regexp.escape from}:/
62
- ex.backtrace[1] =~ /^(.*?:\d+):/
62
+ ex.backtrace[1] =~ /([^\s]+:\d+):/
63
63
  assert_equal from, $1
64
64
  end
65
65
  else
66
- ex.backtrace[0] =~ /^(.*?:\d+):/
66
+ ex.backtrace[0] =~ /([^\s]+:\d+):/
67
67
  assert_equal from, $1
68
68
  end
69
69
  end
@@ -72,7 +72,7 @@ class TestSlim < MiniTest::Unit::TestCase
72
72
  render(source, options)
73
73
  raise 'Ruby syntax error expected'
74
74
  rescue SyntaxError => ex
75
- ex.message =~ /^(.*?:\d+):/
75
+ ex.message =~ /([^\s]+:\d+):/
76
76
  assert_equal from, $1
77
77
  end
78
78
 
@@ -17,6 +17,14 @@ p = "<strong>Hello World\\n, meet \\"Slim\\"</strong>."
17
17
  assert_html "<p>&lt;strong&gt;Hello World\n, meet \&quot;Slim\&quot;&lt;/strong&gt;.</p>", source
18
18
  end
19
19
 
20
+ def test_render_without_html_safe2
21
+ source = %q{
22
+ p = "<strong>Hello World\\n, meet 'Slim'</strong>."
23
+ }
24
+
25
+ assert_html "<p>&lt;strong&gt;Hello World\n, meet &#39;Slim&#39;&lt;/strong&gt;.</p>", source
26
+ end
27
+
20
28
  def test_render_with_html_safe_false
21
29
  source = %q{
22
30
  p = "<strong>Hello World\\n, meet \\"Slim\\"</strong>."
@@ -37,6 +45,27 @@ p = "<strong>Hello World\\n, meet \\"Slim\\"</strong>.".html_safe
37
45
  end
38
46
  end
39
47
 
48
+ # splat ignores html_safe? for now
49
+ def test_render_splat_with_html_safe_true
50
+ source = %q{
51
+ p *{ :title => '&'.html_safe }
52
+ }
53
+
54
+ with_html_safe do
55
+ assert_html "<p title=\"&amp;\"></p>", source, :use_html_safe => true
56
+ end
57
+ end
58
+
59
+ def test_render_attribute_with_html_safe_true
60
+ source = %q{
61
+ p title=('&'.html_safe)
62
+ }
63
+
64
+ with_html_safe do
65
+ assert_html "<p title=\"&\"></p>", source, :use_html_safe => true
66
+ end
67
+ end
68
+
40
69
  def test_render_with_disable_escape_false
41
70
  source = %q{
42
71
  = "<p>Hello</p>"
@@ -74,13 +74,32 @@ p = hello_world if true
74
74
  p
75
75
  - case 42
76
76
  - when 41
77
- | 1
77
+ | 41
78
+ - when 42
79
+ | 42
80
+ | is the answer
81
+ p
82
+ - case 41
83
+ - when 41
84
+ | 41
85
+ - when 42
86
+ | 42
87
+ | is the answer
88
+ p
89
+ - case 42 when 41
90
+ | 41
91
+ - when 42
92
+ | 42
93
+ | is the answer
94
+ p
95
+ - case 41 when 41
96
+ | 41
78
97
  - when 42
79
98
  | 42
80
99
  | is the answer
81
100
  }
82
101
 
83
- assert_html '<p>42 is the answer</p>', source
102
+ assert_html '<p>42 is the answer</p><p>41 is the answer</p><p>42 is the answer</p><p>41 is the answer</p>', source
84
103
  end
85
104
 
86
105
  def test_render_with_slim_comments
@@ -68,6 +68,18 @@ creole:
68
68
  assert_html "<h1>head1</h1><h2>head2</h2>", source
69
69
  end
70
70
 
71
+ def test_render_with_org
72
+ # HACK: org-ruby registers itself in Tilt
73
+ require 'org-ruby'
74
+
75
+ source = %q{
76
+ org:
77
+ * point1
78
+ * point2
79
+ }
80
+ assert_html "<h1>point1</h1>\n<h1>point2</h1>\n", source
81
+ end
82
+
71
83
  def test_render_with_builder
72
84
  source = %q{
73
85
  builder:
@@ -112,7 +124,7 @@ p Hi
112
124
  javascript:
113
125
  $(function() { #{func} });
114
126
  }
115
- assert_html %q|<script type="text/javascript">$(function() { alert('hello'); });</script>|, source
127
+ assert_html %q|<script type="text/javascript">$(function() { alert(&#39;hello&#39;); });</script>|, source
116
128
  end
117
129
 
118
130
  def test_render_with_javascript_with_explicit_html_comment
@@ -69,7 +69,7 @@ option selected=true Text
69
69
  option selected=cond Text2
70
70
  }
71
71
 
72
- assert_html '<option selected="selected">Text</option><option selected="selected">Text2</option>', source
72
+ assert_html '<option selected="">Text</option><option selected="">Text2</option>', source
73
73
  end
74
74
 
75
75
  def test_boolean_attribute_nil
@@ -96,7 +96,7 @@ option(class="clazz" selected) Text
96
96
  option(selected class="clazz") Text
97
97
  }
98
98
 
99
- assert_html '<option class="clazz" selected="selected">Text</option><option class="clazz" selected="selected">Text</option>', source
99
+ assert_html '<option class="clazz" selected="">Text</option><option class="clazz" selected="">Text</option>', source
100
100
  end
101
101
 
102
102
  def test_array_attribute_merging
@@ -116,6 +116,15 @@ option(selected class="clazz") Text
116
116
  assert_html '<div class="alpha" data-a="alpha" data-b="beta" data-c-d="gamma" data-c-e="epsilon"></div>', source
117
117
  end
118
118
 
119
+ def test_splat_without_content
120
+ source = %q{
121
+ *hash
122
+ p*hash
123
+ }
124
+
125
+ assert_html '<div a="The letter a" b="The letter b"></div><p a="The letter a" b="The letter b"></p>', source
126
+ end
127
+
119
128
  def test_shortcut_splat
120
129
  source = %q{
121
130
  *hash This is my title
@@ -202,7 +211,7 @@ h1 *hash class=[] This is my title
202
211
  *{:disabled => true, :empty1 => false, :nonempty => '', :empty2 => nil} This is my title
203
212
  }
204
213
 
205
- assert_html '<div disabled="disabled" nonempty="">This is my title</div>', source
214
+ assert_html '<div disabled="" nonempty="">This is my title</div>', source
206
215
  end
207
216
 
208
217
  def test_splat_merging_with_arrays
@@ -157,4 +157,18 @@ img / text
157
157
 
158
158
  assert_syntax_error "Unexpected text after closed tag\n (__TEMPLATE__), Line 2, Column 6\n img / text\n ^\n", source
159
159
  end
160
+
161
+ def test_illegal_shortcuts
162
+ source = %{
163
+ .#test
164
+ }
165
+
166
+ assert_syntax_error "Illegal shortcut\n (__TEMPLATE__), Line 2, Column 0\n .#test\n ^\n", source
167
+
168
+ source = %{
169
+ div.#test
170
+ }
171
+
172
+ assert_syntax_error "Illegal shortcut\n (__TEMPLATE__), Line 2, Column 3\n div.#test\n ^\n", source
173
+ end
160
174
  end
@@ -861,7 +861,7 @@ dl(
861
861
  renders as
862
862
 
863
863
  ~~~ html
864
- <dl itemprop="address" itemscope="itemscope" itemtype="http://schema.org/PostalAddress"></dl>
864
+ <dl itemprop="address" itemscope="" itemtype="http://schema.org/PostalAddress"></dl>
865
865
  ~~~
866
866
 
867
867
  You may use spaces around the wrappers and assignments:
@@ -993,7 +993,7 @@ input(type="text" disabled)
993
993
  renders as
994
994
 
995
995
  ~~~ html
996
- <input disabled="" type="text" /><input disabled="disabled" type="text" /><input disabled="disabled" type="text" /><input disabled="disabled" type="text" /><input disabled="disabled" type="text" />
996
+ <input disabled="" type="text" /><input disabled="" type="text" /><input disabled="disabled" type="text" /><input disabled="" type="text" /><input disabled="" type="text" />
997
997
  ~~~
998
998
 
999
999
  ~~~ slim
@@ -1126,6 +1126,42 @@ renders to
1126
1126
  <input name="user" type="text" /><input name="pw" type="password" /><input class="CLASS" id="ID" type="submit" />
1127
1127
  ~~~
1128
1128
 
1129
+ You can also set multiple attributes per shortcut.
1130
+
1131
+ ~~~ options
1132
+ :shortcut => {'.' => {:attr => %w(id class)} }
1133
+ ~~~
1134
+
1135
+ ~~~ slim
1136
+ .test
1137
+ ~~~
1138
+
1139
+ renders to
1140
+
1141
+ ~~~ html
1142
+ <div class="test" id="test"></div>
1143
+ ~~~
1144
+
1145
+ Shortcuts can also have multiple characters.
1146
+
1147
+ ~~~ options
1148
+ :shortcut => {'.' => {:attr => 'class'}, '#' => {:attr => 'id'}, '.#' => {:attr => %w(class id)} }
1149
+ ~~~
1150
+
1151
+ ~~~ slim
1152
+ .#test
1153
+ .test
1154
+ #test
1155
+ ~~~
1156
+
1157
+ renders to
1158
+
1159
+ ~~~ html
1160
+ <div class="test" id="test"></div>
1161
+ <div class="test"></div>
1162
+ <div id="test"></div>
1163
+ ~~~
1164
+
1129
1165
  #### ID shortcut and class shortcut `.`
1130
1166
 
1131
1167
  ## Text interpolation
@@ -242,7 +242,7 @@ p
242
242
  input checked=selected = name
243
243
  }
244
244
 
245
- assert_html '<p><input checked="checked">Joe</input><input>Jack</input></p>', source, :scope => Scope.new, :dictionary => '@hash'
245
+ assert_html '<p><input checked="">Joe</input><input>Jack</input></p>', source, :scope => Scope.new, :dictionary => '@hash'
246
246
  end
247
247
 
248
248
  def test_sections
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: 2.0.0
4
+ version: 2.0.1
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: 2013-05-27 00:00:00.000000000 Z
13
+ date: 2013-07-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: temple
@@ -18,34 +18,34 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.6.5
21
+ version: 0.6.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.6.5
28
+ version: 0.6.6
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: tilt
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - ~>
34
- - !ruby/object:Gem::Version
35
- version: '1.3'
36
33
  - - '>='
37
34
  - !ruby/object:Gem::Version
38
35
  version: 1.3.3
36
+ - - <
37
+ - !ruby/object:Gem::Version
38
+ version: '2.1'
39
39
  type: :runtime
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
42
42
  requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: '1.3'
46
43
  - - '>='
47
44
  - !ruby/object:Gem::Version
48
45
  version: 1.3.3
46
+ - - <
47
+ - !ruby/object:Gem::Version
48
+ version: '2.1'
49
49
  description: Slim is a template language whose goal is reduce the syntax to the essential
50
50
  parts without becoming cryptic.
51
51
  email:
@@ -159,7 +159,8 @@ files:
159
159
  - test/rails/test/test_slim.rb
160
160
  - test/translator/test_translator.rb
161
161
  homepage: http://slim-lang.com/
162
- licenses: []
162
+ licenses:
163
+ - MIT
163
164
  metadata: {}
164
165
  post_install_message:
165
166
  rdoc_options: []