slim 2.0.1 → 2.0.2

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: 89b79547893a3fcfe80dc8f1a77b5e7eb94fb69e
4
- data.tar.gz: 68744041f28214f56c5c12559db00e9edb4cc3d0
3
+ metadata.gz: e8b90e64b7eb12f2d3c66b7f1141a757d7314df8
4
+ data.tar.gz: e695b95196c24065d593af6dbc2da8d122b6b0e1
5
5
  SHA512:
6
- metadata.gz: 124098d00c5f8aec79387b13ea46f04df1c7b158d2aa8d27d858e6e62ed9b7814bbfdf08fd474a8d7b62e61df5a23454e10ee188997506352dd6980fa6517954
7
- data.tar.gz: 392e37c3702ba5b2c84a9c6b763be82083d06cabad6155da9bcc9e4a5b4cffa612ad76d91654cd4451b024d5842fd1b8066a077d70ea756eecd81f606dfce1c7
6
+ metadata.gz: 43864aaeb0b17561f3a742be6a2324213be8aefa19ee751f7ded2fef9018effb46bc095a8f756af696eb2c835fb3035df33bbb254781e1ebcd52ac36aef20df4
7
+ data.tar.gz: 5e9ca23904c3c810069605133d41e3770ab6b4349e926328b219c7b3ecf5da99b4a850a38064913082e8d2d4df2bf59e7016c790ae91f717b59e3af3f7a45a25
@@ -46,6 +46,5 @@ matrix:
46
46
  - rvm: ruby-head
47
47
  # Rails master needs newest bundler
48
48
  before_install:
49
- - ./kill-travis.sh
50
49
  - gem update bundler
51
50
  script: "bundle exec rake $TASK"
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ 2.0.2
2
+
3
+ * Add option :attr_delims
4
+
1
5
  2.0.1
2
6
 
3
7
  * Support multiple attributes per shortcut (See issue #415)
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Slim
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/slim.png)](http://rubygems.org/gems/slim) [![Build Status](https://secure.travis-ci.org/slim-template/slim.png?branch=master)](http://travis-ci.org/slim-template/slim) [![Dependency Status](https://gemnasium.com/slim-template/slim.png?travis)](https://gemnasium.com/slim-template/slim) [![Code Climate](https://codeclimate.com/github/slim-template/slim.png)](https://codeclimate.com/github/slim-template/slim)
3
+ [![Gem Version](https://badge.fury.io/rb/slim.png)](http://rubygems.org/gems/slim) [![Build Status](https://secure.travis-ci.org/slim-template/slim.png?branch=master)](http://travis-ci.org/slim-template/slim) [![Dependency Status](https://gemnasium.com/slim-template/slim.png?travis)](https://gemnasium.com/slim-template/slim) [![Code Climate](https://codeclimate.com/github/slim-template/slim.png)](https://codeclimate.com/github/slim-template/slim) [![Gittip donate button](http://img.shields.io/gittip/bevry.png)](https://www.gittip.com/min4d/ "Donate weekly to this project using Gittip")
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")
4
5
 
5
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.
6
7
 
@@ -32,19 +33,6 @@ A short list of the features...
32
33
  * Latest Gem: <http://rubydoc.info/gems/slim/frames>
33
34
  * GitHub master: <http://rubydoc.info/github/slim-template/slim/master/frames>
34
35
 
35
- ## Upgrade to version 2.0
36
-
37
- If you are already using Slim 1.x and want to upgrade to the newest version 2.0, you should at first
38
- upgrade to at least Slim 1.3.8 which will emit warnings for deprecated features. This way you can easily
39
- see if your application is already Slim 2.0 compliant!
40
-
41
- Slim 2.0 removes deprecated features from the 1.3 series and cleans up some minor
42
- inconsistencies in the syntax (Attribute wrapper and quoted attribute escaping).
43
- Of course it also includes new features and bugfixes. See the CHANGES for details.
44
-
45
- In general don't be afraid of upgrading! We try to be backward compatible and follow [semantic versions](http://semver.org/)
46
- as good as possible.
47
-
48
36
  ## Introduction
49
37
 
50
38
  ### What is Slim?
@@ -69,7 +57,7 @@ There is also some development in logic-less engines (e.g. [Mustache](https://gi
69
57
 
70
58
  Slim was born to bring a minimalist syntax approach with speed. If people chose not to use Slim, it would not be because of speed.
71
59
 
72
- ___Yes, Slim is speedy!___ Benchmarks are done for every commit at <http://travis-ci.org/#!/slim-template/slim>.
60
+ ___Yes, Slim is speedy!___ Benchmarks are done for every commit at <http://travis-ci.org/slim-template/slim>.
73
61
  Don't trust the numbers? That's as it should be. Please try the benchmark rake task yourself!
74
62
 
75
63
  ### How to start?
@@ -98,7 +86,7 @@ Here's a quick example to demonstrate what a Slim template looks like:
98
86
  h1 Markup examples
99
87
 
100
88
  #content
101
- p This example shows you how a basic Slim file looks like.
89
+ p This example shows you how a basic Slim file looks.
102
90
 
103
91
  == yield
104
92
 
@@ -362,6 +350,7 @@ You can use text interpolation in the quoted attributes.
362
350
 
363
351
  If a delimiter makes the syntax more readable for you,
364
352
  you can use the characters `{...}`, `(...)`, `[...]` to wrap the attributes.
353
+ You can configure these symbols (See option `:attr_delims`).
365
354
 
366
355
  body
367
356
  h1(id="logo") = page_logo
@@ -572,8 +561,15 @@ If you use Slim you might want to extend your template with some helpers. Assume
572
561
 
573
562
  ~~~ruby
574
563
  module Helpers
575
- def headline
576
- "<h1>#{yield}</h1>"
564
+ def headline(&block)
565
+ if defined?(::Rails)
566
+ # In Rails we have to use capture!
567
+ "<h1>#{capture(&block)}</h1>"
568
+ else
569
+ # If we are using Slim without a framework (Plain Tilt),
570
+ # this works directly.
571
+ "<h1>#{yield}</h1>"
572
+ end
577
573
  end
578
574
  end
579
575
  ~~~
@@ -703,6 +699,7 @@ There are a lot of them but the good thing is, that Slim checks the configuratio
703
699
  | String | :encoding | "utf-8" | Set encoding of template |
704
700
  | String | :default_tag | "div" | Default tag to be used if tag name is omitted |
705
701
  | Hash | :shortcut | \{'.' => {:attr => 'class'}, '#' => {:attr => 'id'}} | Attribute shortcuts |
702
+ | Hash | :attr_delims | \{'(' => ')', '[' => ']', '{' => '}'} | Attribute delimiters |
706
703
  | Array&lt;Symbol,String&gt; | :enable_engines | nil <i>(All enabled)</i> | List of enabled embedded engines (whitelist) |
707
704
  | Array&lt;Symbol,String&gt; | :disable_engines | nil <i>(None disabled)</i> | List of disabled embedded engines (blacklist) |
708
705
  | Boolean | :disable_capture | false (true in Rails) | Disable capturing in blocks (blocks write to the default buffer |
@@ -745,7 +742,7 @@ It is also possible to set options for superclasses like `Temple::Engine`. But t
745
742
  Slim currently provides plugins for logic less mode and I18n. See the plugin documentation.
746
743
 
747
744
  * [Logic less mode](doc/logic_less.md)
748
- * [Translator/I18ne](doc/translator.md)
745
+ * [Translator/I18n](doc/translator.md)
749
746
 
750
747
  ## Framework support
751
748
 
@@ -863,7 +860,7 @@ run the slow parsing benchmark which needs more time. You can also increase the
863
860
 
864
861
  rake bench slow=1 iterations=1000
865
862
 
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>
863
+ 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>
867
864
 
868
865
  ### Test suite and continuous integration
869
866
 
@@ -872,14 +869,11 @@ with 'rake test' and the rails integration tests with 'rake test:rails'.
872
869
 
873
870
  We are currently experimenting with human-readable literate tests which are written as markdown files: [TESTS.md](test/literate/TESTS.md)
874
871
 
875
- Travis-CI is used for continuous integration testing: <http://travis-ci.org/#!/slim-template/slim>
872
+ Travis-CI is used for continuous integration testing: <http://travis-ci.org/slim-template/slim>
876
873
 
877
874
  Slim is working well on all major Ruby implementations:
878
875
 
879
- * Ruby 2.0.0
880
- * Ruby 1.8.7
881
- * Ruby 1.9.2
882
- * Ruby 1.9.3
876
+ * Ruby 1.8.7, 1.9.3 and 2.0.0
883
877
  * Ruby EE
884
878
  * JRuby
885
879
  * Rubinius 2.0
@@ -892,7 +886,7 @@ If you'd like to help improve Slim, clone the project with Git by running:
892
886
 
893
887
  Work your magic and then submit a pull request. We love pull requests!
894
888
 
895
- Please remember to test against Ruby versions 2.0.0, 1.9.3 and 1.8.7.
889
+ Please remember to keep the compatibility with Ruby versions 1.8.7, 1.9.3 and 2.0.0.
896
890
 
897
891
  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.
898
892
 
@@ -906,6 +900,15 @@ Slim is released under the [MIT license](http://www.opensource.org/licenses/MIT)
906
900
  * [Andrew Stone](https://github.com/stonean)
907
901
  * [Fred Wu](https://github.com/fredwu)
908
902
 
903
+ ## Donations and sponsoring
904
+
905
+ If you want to support this project please visit the Gittip and Flattr pages.
906
+
907
+ [![Gittip donate button](http://img.shields.io/gittip/bevry.png)](https://www.gittip.com/min4d/ "Donate weekly to this project using Gittip")
908
+ [![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")
909
+
910
+ Currently the donations will be used to cover the hosting costs (domain name etc).
911
+
909
912
  ## Discuss
910
913
 
911
914
  * [Google Group](http://groups.google.com/group/slim-template)
@@ -14,7 +14,7 @@ module Slim
14
14
 
15
15
  filter :Encoding, :encoding
16
16
  filter :RemoveBOM
17
- use Slim::Parser, :file, :tabsize, :shortcut, :default_tag
17
+ use Slim::Parser, :file, :tabsize, :shortcut, :default_tag, :attr_delims
18
18
  use Slim::Embedded, :enable_engines, :disable_engines, :pretty
19
19
  use Slim::Interpolation
20
20
  use Slim::Splat::Filter, :merge_attrs, :attr_quote, :sort_attrs, :default_tag, :hyphen_attrs
@@ -9,6 +9,11 @@ module Slim
9
9
  :shortcut => {
10
10
  '#' => { :attr => 'id' },
11
11
  '.' => { :attr => 'class' }
12
+ },
13
+ :attr_delims => {
14
+ '(' => ')',
15
+ '[' => ']',
16
+ '{' => '}',
12
17
  }
13
18
 
14
19
  class SyntaxError < StandardError
@@ -56,6 +61,9 @@ module Slim
56
61
  @attr_shortcut_re = /\A(#{keys}+)(#{WORD_RE}(?:#{WORD_RE}|-)*#{WORD_RE}|#{WORD_RE}+)/
57
62
  keys = Regexp.union @tag_shortcut.keys.sort_by {|k| -k.size }
58
63
  @tag_re = /\A(?:#{keys}|\*(?=[^\s]+)|(#{WORD_RE}(?:#{WORD_RE}|:|-)*#{WORD_RE}|#{WORD_RE}+))/
64
+ keys = Regexp.escape options[:attr_delims].keys.join
65
+ @delim_re = /\A[#{keys}]/
66
+ @attr_delim_re = /\A\s*([#{keys}])/
59
67
  end
60
68
 
61
69
  # Compile string to Temple expression
@@ -74,15 +82,7 @@ module Slim
74
82
 
75
83
  protected
76
84
 
77
- DELIMS = {
78
- '(' => ')',
79
- '[' => ']',
80
- '{' => '}',
81
- }.freeze
82
-
83
85
  WORD_RE = ''.respond_to?(:encoding) ? '\p{Word}' : '\w'
84
- DELIM_RE = /\A[#{Regexp.escape DELIMS.keys.join}]/
85
- ATTR_DELIM_RE = /\A\s*([#{Regexp.escape DELIMS.keys.join}])/
86
86
  ATTR_NAME = "\\A\\s*(#{WORD_RE}(?:#{WORD_RE}|:|-)*)"
87
87
  QUOTED_ATTR_RE = /#{ATTR_NAME}\s*=(=?)\s*("|')/
88
88
  CODE_ATTR_RE = /#{ATTR_NAME}\s*=(=?)\s*/
@@ -361,8 +361,8 @@ module Slim
361
361
  def parse_attributes(attributes)
362
362
  # Check to see if there is a delimiter right after the tag name
363
363
  delimiter = nil
364
- if @line =~ ATTR_DELIM_RE
365
- delimiter = DELIMS[$1]
364
+ if @line =~ @attr_delim_re
365
+ delimiter = options[:attr_delims][$1]
366
366
  @line = $'
367
367
  end
368
368
 
@@ -433,9 +433,9 @@ module Slim
433
433
  elsif @line[0] == close_delimiter[0]
434
434
  count -= 1
435
435
  end
436
- elsif @line =~ DELIM_RE
436
+ elsif @line =~ @delim_re
437
437
  count = 1
438
- delimiter, close_delimiter = $&, DELIMS[$&]
438
+ delimiter, close_delimiter = $&, options[:attr_delims][$&]
439
439
  end
440
440
  code << @line.slice!(0)
441
441
  end
@@ -1,5 +1,5 @@
1
1
  module Slim
2
2
  # Slim version string
3
3
  # @api public
4
- VERSION = '2.0.1'
4
+ VERSION = '2.0.2'
5
5
  end
@@ -283,6 +283,26 @@ p(id="marvin" class="martian" data-info="Illudium Q-36")= output_number
283
283
  assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', source
284
284
  end
285
285
 
286
+ def test_default_attr_delims_option
287
+ source = %q{
288
+ p<id="marvin" class="martian" data-info="Illudium Q-36">= output_number
289
+ }
290
+ Slim::Parser.default_options[:attr_delims].each do |k,v|
291
+ str = source.sub('<',k).sub('>',v)
292
+ assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', str
293
+ end
294
+ end
295
+
296
+ def test_custom_attr_delims_option
297
+ source = %q{
298
+ p { foo="bar" }
299
+ }
300
+
301
+ assert_html '<p foo="bar"></p>', source
302
+ assert_html '<p foo="bar"></p>', source, :attr_delims => {'{' => '}'}
303
+ assert_html '<p>{ foo="bar" }</p>', source, :attr_delims => {'(' => ')', '[' => ']'}
304
+ end
305
+
286
306
  def test_closed_tag
287
307
  source = %q{
288
308
  closed/
@@ -358,7 +378,7 @@ p<id="marvin"
358
378
  class="martian"
359
379
  data-info="Illudium Q-36"> = output_number
360
380
  }
361
- Slim::Parser::DELIMS.each do |k,v|
381
+ Slim::Parser.default_options[:attr_delims].each do |k,v|
362
382
  str = source.sub('<',k).sub('>',v)
363
383
  assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', str
364
384
  end
@@ -370,7 +390,7 @@ p<id="marvin"
370
390
  class="martian"
371
391
  data-info="Illudium Q-36"> THE space modulator
372
392
  }
373
- Slim::Parser::DELIMS.each do |k,v|
393
+ Slim::Parser.default_options[:attr_delims].each do |k,v|
374
394
  str = source.sub('<',k).sub('>',v)
375
395
  assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">THE space modulator</p>', str
376
396
  end
@@ -383,7 +403,7 @@ p<id="marvin"
383
403
  data-info="Illudium Q-36">
384
404
  | THE space modulator
385
405
  }
386
- Slim::Parser::DELIMS.each do |k,v|
406
+ Slim::Parser.default_options[:attr_delims].each do |k,v|
387
407
  str = source.sub('<',k).sub('>',v)
388
408
  assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">THE space modulator</p>', str
389
409
  end
@@ -396,7 +416,7 @@ p<id=id_helper
396
416
  data-info="Illudium Q-36">
397
417
  | THE space modulator
398
418
  }
399
- Slim::Parser::DELIMS.each do |k,v|
419
+ Slim::Parser.default_options[:attr_delims].each do |k,v|
400
420
  str = source.sub('<',k).sub('>',v)
401
421
  assert_html '<p class="martian" data-info="Illudium Q-36" id="notice">THE space modulator</p>', str
402
422
  end
@@ -410,7 +430,7 @@ p<id=id_helper
410
430
  span.emphasis THE
411
431
  | space modulator
412
432
  }
413
- Slim::Parser::DELIMS.each do |k,v|
433
+ Slim::Parser.default_options[:attr_delims].each do |k,v|
414
434
  str = source.sub('<',k).sub('>',v)
415
435
  assert_html '<p class="martian" data-info="Illudium Q-36" id="notice"><span class="emphasis">THE</span> space modulator</p>', str
416
436
  end
@@ -423,7 +443,7 @@ li< id="myid"
423
443
  data-info="myinfo">
424
444
  a href="link" My Link
425
445
  }
426
- Slim::Parser::DELIMS.each do |k,v|
446
+ Slim::Parser.default_options[:attr_delims].each do |k,v|
427
447
  str = source.sub('<',k).sub('>',v)
428
448
  assert_html '<li class="myclass" data-info="myinfo" id="myid"><a href="link">My Link</a></li>', str
429
449
  end
@@ -41,10 +41,7 @@ html
41
41
  result = %q{<!DOCTYPE html>
42
42
  <html>
43
43
  <head>
44
- <title>
45
- Hello World!
46
- </title>
47
- <!--Meta tags
44
+ <title>Hello World!</title><!--Meta tags
48
45
  with long explanatory
49
46
  multiline comment-->
50
47
  <meta content="template language" name="description" />
@@ -213,11 +213,7 @@ HTML tags allow nested blocks inside.
213
213
  renders as
214
214
 
215
215
  ~~~ html
216
- <html><head>
217
- <title>
218
- Example
219
- </title>
220
- </head>
216
+ <html><head><title>Example</title></head>
221
217
  <body>
222
218
  yes
223
219
  </body>
@@ -34,4 +34,7 @@ class SlimController < ApplicationController
34
34
  def content_for
35
35
  @hello = "Hello Slim!"
36
36
  end
37
+
38
+ def helper
39
+ end
37
40
  end
@@ -1,2 +1,5 @@
1
1
  module ApplicationHelper
2
+ def headline(&block)
3
+ "<h1>#{capture(&block)}</h1>".html_safe
4
+ end
2
5
  end
@@ -0,0 +1,4 @@
1
+ p
2
+ = headline do
3
+ ' Hello
4
+ = 'User'
@@ -17,6 +17,14 @@ class TestSlim < ActionDispatch::IntegrationTest
17
17
  assert_html "<h1>Hello Slim!</h1>"
18
18
  end
19
19
 
20
+ test "helper" do
21
+ get "slim/helper"
22
+ assert_response :success
23
+ assert_template "slim/helper"
24
+ assert_template "layouts/application"
25
+ assert_html "<p><h1>Hello User</h1></p>"
26
+ end
27
+
20
28
  test "normal erb view" do
21
29
  get "slim/erb"
22
30
  assert_html "<h1>Hello Erb!</h1>"
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.1
4
+ version: 2.0.2
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-07-31 00:00:00.000000000 Z
13
+ date: 2013-10-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: temple
@@ -76,7 +76,6 @@ files:
76
76
  - bin/slimrb
77
77
  - doc/logic_less.md
78
78
  - doc/translator.md
79
- - kill-travis.sh
80
79
  - lib/slim.rb
81
80
  - lib/slim/code_attributes.rb
82
81
  - lib/slim/command.rb
@@ -135,6 +134,7 @@ files:
135
134
  - test/rails/app/views/slim/content_for.html.slim
136
135
  - test/rails/app/views/slim/erb.html.erb
137
136
  - test/rails/app/views/slim/form_for.html.slim
137
+ - test/rails/app/views/slim/helper.html.slim
138
138
  - test/rails/app/views/slim/integers.html.slim
139
139
  - test/rails/app/views/slim/no_layout.html.slim
140
140
  - test/rails/app/views/slim/normal.html.slim
@@ -178,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
178
  version: '0'
179
179
  requirements: []
180
180
  rubyforge_project: slim
181
- rubygems_version: 2.0.0
181
+ rubygems_version: 2.0.3
182
182
  signing_key:
183
183
  specification_version: 4
184
184
  summary: Slim is a template language.
@@ -1,16 +0,0 @@
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