slim 5.1.1 → 5.2.0

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
  SHA256:
3
- metadata.gz: 032ed4e8911b32aa669a7e0a6196a9955d2f2cdadbcc8432aa589039bc3a7b50
4
- data.tar.gz: 94ce4618acbca850dce85c0ce3379e77a8b03ca846b84edcb25a09dfa050e848
3
+ metadata.gz: d9008a7eaa7a19ae0ada9b2a6789ff073a43fceaea9e24fe284ebf698fd5b02c
4
+ data.tar.gz: 2c79bf7dc50662e04fb711ba4a1c334265c3a5b2186a111b932a04f02ae16680
5
5
  SHA512:
6
- metadata.gz: e25e4b9230e092183013063ece1dbb3233b267eb118f90e41dca7d4a2221fe4e00b1c572d6d1b5defac7b0912bba0b00ff442785c930f49f06849819d699ecb7
7
- data.tar.gz: 065b7317b43379f0c7ecf85a0ce4fd398b9ecac13e3b6793de9293711776468bd24c15b2a19f029dd04a16aaf724b1210e0fab600a06a23db57f172054d7f798
6
+ metadata.gz: 1c4aa87d3b5a20242328258c6cfe8b436af5f92b437076bb185926764e5168959087aca53e5c0face78bde9b6670b6c4023f4893f98f58c6db97d730961ed93a
7
+ data.tar.gz: 178427ae03b2c8e2918c4114376a5dd3955ac20ef393d5a355ca441617a39f3b66101ff00bbb7c0c6e8b12aee338db2914c37910712c1ada5aa5814f9e3cdd79
@@ -16,9 +16,9 @@ jobs:
16
16
  strategy:
17
17
  fail-fast: false
18
18
  matrix:
19
- ruby: ['2.5', '2.6', '2.7', '3.0', '3.1']
19
+ ruby: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2']
20
20
  steps:
21
- - uses: actions/checkout@v3
21
+ - uses: actions/checkout@v4
22
22
  - name: Set up Ruby
23
23
  uses: ruby/setup-ruby@v1
24
24
  with:
@@ -29,23 +29,46 @@ jobs:
29
29
  SINATRA: 2.2.4
30
30
  - run: bundle install && bundle exec rake test:sinatra
31
31
  env:
32
- SINATRA: 3.0.5
32
+ SINATRA: 3.0.6
33
+ - run: bundle install && bundle exec rake test:sinatra
34
+ if: ${{ matrix.ruby != '2.5' }}
35
+ env:
36
+ SINATRA: 3.1.0
37
+ - run: bundle install && bundle exec rake test:sinatra
38
+ if: ${{ matrix.ruby != '2.5' }}
39
+ env:
40
+ SINATRA: main
33
41
  rails:
34
42
  runs-on: ubuntu-latest
35
43
  strategy:
36
44
  fail-fast: false
37
45
  steps:
38
- - uses: actions/checkout@v3
46
+ - uses: actions/checkout@v4
39
47
  - name: Set up Ruby
40
48
  uses: ruby/setup-ruby@v1
41
49
  with:
42
50
  ruby-version: 2.7
43
51
  - run: bundle install && bundle exec rake test:rails
52
+ name: "rake test:rails RAILS=5.2.8"
44
53
  env:
45
54
  RAILS: 5.2.8
46
55
  - run: bundle install && bundle exec rake test:rails
56
+ name: "rake test:rails RAILS=6.0.6"
47
57
  env:
48
58
  RAILS: 6.0.6
49
59
  - run: bundle install && bundle exec rake test:rails
60
+ name: "rake test:rails RAILS=6.1.7"
50
61
  env:
51
62
  RAILS: 6.1.7
63
+ - run: bundle install && bundle exec rake test:rails
64
+ name: "rake test:rails RAILS=7.0.7"
65
+ env:
66
+ RAILS: 7.0.8
67
+ - run: bundle install && bundle exec rake test:rails
68
+ name: "rake test:rails RAILS=7.1.0"
69
+ env:
70
+ RAILS: 7.1.2
71
+ - run: bundle install && bundle exec rake test:rails
72
+ name: "rake test:rails RAILS=main"
73
+ env:
74
+ RAILS: main
data/CHANGES CHANGED
@@ -1,3 +1,9 @@
1
+ 5.2.0 (2023-11-11)
2
+
3
+ * Fix logic less bug - #783
4
+ * Support Rails 7.1 - #936
5
+ * Fix splat arguments on Rails 7.1 - #942
6
+
1
7
  5.1.1 (2023-05-16)
2
8
 
3
9
  * Support lambda functions as shortcuts - #677 #813 #903
@@ -243,7 +249,7 @@
243
249
  * BACKWARD INCOMPATIBLE CHANGE - Dynamic attributes which return empty value "" are not removed anymore
244
250
  (this means "" is now interpreted as true), whereas false and nil are still removed.
245
251
  This corresponds to the definition of boolean attributes in XHTML and HTML5.
246
- * Deprecated option :remove_empty_attrs (TODO: Remove in 1.4.0)
252
+ * Deprecated option :remove_empty_attrs
247
253
  * Add option :escape_quoted_attrs to escape quoted attributes, use == if you don't want that.
248
254
  The default is false to stay backward compatible.
249
255
  * Use Temple::FilterError exception
data/Gemfile CHANGED
@@ -2,7 +2,6 @@ source 'https://rubygems.org/'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'test-unit', '~> 3.5'
6
5
  gem 'minitest', '~> 5.15'
7
6
  gem 'rake', '~> 13.0'
8
7
  gem 'kramdown', '~> 2.4'
@@ -11,12 +10,12 @@ if ENV['TEMPLE'] && ENV['TEMPLE'] != 'master'
11
10
  gem 'temple', "= #{ENV['TEMPLE']}"
12
11
  else
13
12
  # Test against temple master by default
14
- gem 'temple', :github => 'judofyr/temple'
13
+ gem 'temple', github: 'judofyr/temple'
15
14
  end
16
15
 
17
16
  if ENV['TILT']
18
17
  if ENV['TILT'] == 'master'
19
- gem 'tilt', :github => 'rtomayko/tilt'
18
+ gem 'tilt', github: 'jeremyevans/tilt'
20
19
  else
21
20
  gem 'tilt', "= #{ENV['TILT']}"
22
21
  end
@@ -27,7 +26,7 @@ if ENV['RAILS']
27
26
 
28
27
  # we need some smarter test logic for the different Rails versions
29
28
  if ENV['RAILS'] == 'main'
30
- gem 'rails', :github => 'rails/rails', branch: 'main'
29
+ gem 'rails', github: 'rails/rails', branch: 'main'
31
30
  else
32
31
  gem 'rails', "= #{ENV['RAILS']}"
33
32
  end
@@ -36,9 +35,9 @@ end
36
35
  if ENV['SINATRA']
37
36
  gem 'rack-test'
38
37
 
39
- if ENV['SINATRA'] == 'master'
40
- gem 'sinatra', :github => 'sinatra/sinatra'
38
+ if ENV['SINATRA'] == 'main'
39
+ gem 'sinatra', github: 'sinatra/sinatra'
41
40
  else
42
- gem 'sinatra', :tag => "v#{ENV['SINATRA']}"
41
+ gem 'sinatra', tag: "v#{ENV['SINATRA']}"
43
42
  end
44
43
  end
data/README.jp.md CHANGED
@@ -32,23 +32,22 @@ Slim は 不可解にならない程度に view の構文を本質的な部品
32
32
  * ホームページ: <https://slim-template.github.io>
33
33
  * ソース: <https://github.com/slim-template/slim>
34
34
  * バグ: <https://github.com/slim-template/slim/issues>
35
- * リスト: <https://groups.google.com/group/slim-template>
36
35
  * API ドキュメント:
37
- * 最新の Gem: <https://rubydoc.info/gems/slim/frames> <https://www.omniref.com/ruby/gems/slim>
38
- * GitHub master: <https://rubydoc.info/github/slim-template/slim/master/frames> <https://www.omniref.com/github/slim-template/slim>
36
+ * 最新の Gem: <https://rubydoc.info/gems/slim/frames>
37
+ * GitHub main: <https://rubydoc.info/github/slim-template/slim/main/frames>
39
38
 
40
39
  ## イントロダクション
41
40
 
42
41
  ### Slim とは?
43
42
 
44
43
  Slim は __Rails5 以降__ に対応した高速, 軽量なテンプレートエンジンです。主要な Ruby の実装全てでしっかりテストされています。
45
- 私たちは継続的インテグレーションを採用しています。(travis-ci)
44
+ 私たちは継続的インテグレーションを採用しています。(github actions)
46
45
 
47
46
  Slim の核となる構文は1つの考えによって導かれています: "この動作を行うために最低限必要なものは何か。"
48
47
 
49
48
  多くの人々の Slim への貢献によって, 彼らが使う [Haml](https://github.com/haml/haml) や [Jade](https://github.com/visionmedia/jade) の影響を受け構文の追加が行われています。 Slim の開発チームは美は見る人の目の中にあることを分っているので、こういった追加にオープンです。
50
49
 
51
- Slim は 構文解析/コンパイルに [Temple](https://github.com/judofyr/temple) を使い [Tilt](https://github.com/rtomayko/tilt) に組み込まれます。これにより [Sinatra](https://github.com/sinatra/sinatra) やプレーンな [Rack](https://github.com/rack/rack) とも一緒に使えます。
50
+ Slim は 構文解析/コンパイルに [Temple](https://github.com/judofyr/temple) を使い [Tilt](https://github.com/jeremyevans/tilt) に組み込まれます。これにより [Sinatra](https://github.com/sinatra/sinatra) やプレーンな [Rack](https://github.com/rack/rack) とも一緒に使えます。
52
51
 
53
52
  Temple のアーキテクチャはとても柔軟で, モンキーパッチなしで構文解析とコンパイルのプロセスの拡張が可能です。これはロジックレスのプラグインや I18n が提供する翻訳プラグインに
54
53
  使用されます。ロジックレスモードでは HTML をビルドするために Slim の構文を使いたいが, テンプレートの中で Ruby を書きたくない場合にも Slim を使うことができます。
@@ -60,7 +59,6 @@ Temple のアーキテクチャはとても柔軟で, モンキーパッチな
60
59
  * Slim のアーキテクチャは非常に柔軟なので, 構文の拡張やプラグインを書くことができます。
61
60
 
62
61
  ___そう, Slim は速い!___ Slim は開発当初からパフォーマンスに注意して開発されてきました。
63
- ベンチマークはコミット毎に <http://travis-ci.org/slim-template/slim> で取られています。
64
62
  この数字が信じられませんか? それは仕方ないことです。是非 rake タスクを使って自分でベンチマークを取ってみてください!
65
63
 
66
64
  私たちの考えでは, あなたは Slim の機能と構文を使うべきです。Slim はあなたのアプリケーションのパフォーマンスに悪影響を与えないことを保証します。
@@ -843,7 +841,7 @@ body
843
841
 
844
842
  ## 埋め込みエンジン (Markdown, ...)
845
843
 
846
- [Tilt](https://github.com/rtomayko/tilt)のおかげで, Slim は他のテンプレートエンジンの埋め込みに見事に対応しています。
844
+ [Tilt](https://github.com/jeremyevans/tilt)のおかげで, Slim は他のテンプレートエンジンの埋め込みに見事に対応しています。
847
845
 
848
846
  例:
849
847
 
@@ -866,8 +864,8 @@ p: markdown: Tag with **inline** markdown!
866
864
  | ruby: | なし | ショートカット | Ruby コードを埋め込むショートカット |
867
865
  | javascript: | なし | ショートカット | javascript コードを埋め込み、script タグで囲む |
868
866
  | css: | なし | ショートカット | css コードを埋め込み、style タグで囲む |
869
- | sass: | sass | コンパイル時 | sass コードを埋め込み、style タグで囲む |
870
- | scss: | sass | コンパイル時 | scss コードを埋め込み、style タグで囲む |
867
+ | sass: | sass-embedded または sassc または sass | コンパイル時 | sass コードを埋め込み、style タグで囲む |
868
+ | scss: | sass-embedded または sassc または sass | コンパイル時 | scss コードを埋め込み、style タグで囲む |
871
869
  | less: | less | コンパイル時 | less コードを埋め込み、style タグで囲む |
872
870
  | coffee: | coffee-script | コンパイル時 | CoffeeScript をコンパイルし、 script タグで囲む |
873
871
  | markdown: | redcarpet/rdiscount/kramdown | コンパイル時 + 展開 | Markdown をコンパイルし、テキスト中の # \{variables} を展開 |
@@ -906,7 +904,7 @@ scss class="myClass":
906
904
  ## Slim の設定
907
905
 
908
906
  Slim とその基礎となる [Temple](https://github.com/judofyr/temple) は非常に柔軟に設定可能です。
909
- Slim を設定する方法はコンパイル機構に少し依存します。(Rails や [Tilt](https://github.com/rtomayko/tilt))。デフォルトオプションの設定は `Slim::Engine` クラスでいつでも可能です。Rails の 環境設定ファイルで設定可能です。例えば, config/environments/developers.rb で設定したいとします:
907
+ Slim を設定する方法はコンパイル機構に少し依存します。(Rails や [Tilt](https://github.com/jeremyevans/tilt))。デフォルトオプションの設定は `Slim::Engine` クラスでいつでも可能です。Rails の 環境設定ファイルで設定可能です。例えば, config/environments/developers.rb で設定したいとします:
910
908
 
911
909
  ### デフォルトオプション
912
910
 
@@ -1021,7 +1019,7 @@ Slim はロジックレスモードと I18n, インクルードプラグイン
1021
1019
 
1022
1020
  ### Tilt
1023
1021
 
1024
- Slim は生成されたコードをコンパイルするために [Tilt](https://github.com/rtomayko/tilt) を使用します。Slim テンプレートを直接使いたい場合, Tilt インターフェイスが使用できます。
1022
+ Slim は生成されたコードをコンパイルするために [Tilt](https://github.com/jeremyevans/tilt) を使用します。Slim テンプレートを直接使いたい場合, Tilt インターフェイスが使用できます。
1025
1023
 
1026
1024
  ~~~ ruby
1027
1025
  Tilt.new['template.slim'].render(scope)
@@ -1186,8 +1184,6 @@ markdown:
1186
1184
  rake bench slow=1 iterations=1000
1187
1185
  ~~~
1188
1186
 
1189
- 私たちはコミット毎に Travis-CI でベンチマークをとっています。最新のベンチマーク結果はこちらです: <http://travis-ci.org/slim-template/slim>
1190
-
1191
1187
  ### テストスイートと継続的インテグレーション
1192
1188
 
1193
1189
  Slim は minitest ベースの拡張性のあるテストスイートを提供します。テストは 'rake test' または
@@ -1195,8 +1191,6 @@ rails のインテグレーションテストの場合 'rake test:rails' で実
1195
1191
 
1196
1192
  私たちは現在 markdown ファイルで書かれ, 人間が読み書きしやすいテストを試しています: [TESTS.md](test/literate/TESTS.md)
1197
1193
 
1198
- Travis-CI は継続的インテグレーションテストに利用されています: <http://travis-ci.org/slim-template/slim>
1199
-
1200
1194
  Slim は主要な Ruby 実装全てで動作します:
1201
1195
 
1202
1196
  * Ruby 2.5
@@ -1232,10 +1226,6 @@ Slim は [MIT license](http://www.opensource.org/licenses/MIT) に基づいて
1232
1226
 
1233
1227
  [![GitHub Sponsors](https://img.shields.io/github/sponsors/slim-template)](https://github.com/sponsors/slim-template)
1234
1228
 
1235
- ## 議論
1236
-
1237
- * [Google Group](http://groups.google.com/group/slim-template)
1238
-
1239
1229
  ## 関連プロジェクト
1240
1230
 
1241
1231
  テンプレートのコンパイルフレームワーク:
data/README.md CHANGED
@@ -32,23 +32,22 @@ A short list of the features...
32
32
  * Homepage: <https://slim-template.github.io>
33
33
  * Source: <https://github.com/slim-template/slim>
34
34
  * Bugs: <https://github.com/slim-template/slim/issues>
35
- * List: <https://groups.google.com/group/slim-template>
36
35
  * API documentation:
37
- * Latest Gem: <https://rubydoc.info/gems/slim/frames> <https://www.omniref.com/ruby/gems/slim>
38
- * GitHub master: <https://rubydoc.info/github/slim-template/slim/master/frames> <https://www.omniref.com/github/slim-template/slim>
36
+ * Latest Gem: <https://rubydoc.info/gems/slim/frames>
37
+ * GitHub main: <https://rubydoc.info/github/slim-template/slim/main/frames>
39
38
 
40
39
  ## Introduction
41
40
 
42
41
  ### What is Slim?
43
42
 
44
43
  Slim is a fast, lightweight templating engine with support for __Rails 5 and later__. It has been heavily tested on all major ruby implementations. We use
45
- continuous integration (travis-ci).
44
+ continuous integration (github actions).
46
45
 
47
46
  Slim's core syntax is guided by one thought: "What's the minimum required to make this work".
48
47
 
49
48
  As more people have contributed to Slim, there have been syntax additions influenced from their use of [Haml](https://github.com/haml/haml) and [Jade](https://github.com/visionmedia/jade). The Slim team is open to these additions because we know beauty is in the eye of the beholder.
50
49
 
51
- Slim uses [Temple](https://github.com/judofyr/temple) for parsing/compilation and is also integrated into [Tilt](https://github.com/rtomayko/tilt), so it can be used together with [Sinatra](https://github.com/sinatra/sinatra) or plain [Rack](https://github.com/rack/rack).
50
+ Slim uses [Temple](https://github.com/judofyr/temple) for parsing/compilation and is also integrated into [Tilt](https://github.com/jeremyevans/tilt), so it can be used together with [Sinatra](https://github.com/sinatra/sinatra) or plain [Rack](https://github.com/rack/rack).
52
51
 
53
52
  The architecture of Temple is very flexible and allows the extension of the parsing and compilation process without monkey-patching. This is used
54
53
  by the logic less plugin and the translator plugin which provides I18n. In logic-less mode you can use Slim if you like the Slim syntax to build your HTML but don't want to write Ruby in your templates.
@@ -878,7 +877,7 @@ body
878
877
 
879
878
  ## Embedded engines (Markdown, ...)
880
879
 
881
- Thanks to [Tilt](https://github.com/rtomayko/tilt), Slim has extensive support for embedding other template engines.
880
+ Thanks to [Tilt](https://github.com/jeremyevans/tilt), Slim has extensive support for embedding other template engines.
882
881
 
883
882
  Examples:
884
883
 
@@ -901,8 +900,8 @@ Supported engines:
901
900
  | ruby: | none | Shortcut | Shortcut to embed ruby code |
902
901
  | javascript: | none | Shortcut | Shortcut to embed javascript code and wrap in script tag |
903
902
  | css: | none | Shortcut | Shortcut to embed css code and wrap in style tag |
904
- | sass: | sass | Compile time | Embed sass code and wrap in style tag |
905
- | scss: | sass | Compile time | Embed scss code and wrap in style tag |
903
+ | sass: | sass-embedded or sassc or sass | Compile time | Embed sass code and wrap in style tag |
904
+ | scss: | sass-embedded or sassc or sass | Compile time | Embed scss code and wrap in style tag |
906
905
  | less: | less | Compile time | Embed less css code and wrap in style tag |
907
906
  | coffee: | coffee-script | Compile time | Compile coffee script code and wrap in script tag |
908
907
  | markdown: | redcarpet/rdiscount/kramdown | Compile time + Interpolation | Compile markdown code and interpolate #\{variables} in text |
@@ -1056,7 +1055,7 @@ Slim currently provides plugins for logic less mode, includes and I18n. See the
1056
1055
 
1057
1056
  ### Tilt
1058
1057
 
1059
- Slim uses [Tilt](https://github.com/rtomayko/tilt) to compile the generated code. If you want to use the Slim template directly, you can use the Tilt interface.
1058
+ Slim uses [Tilt](https://github.com/jeremyevans/tilt) to compile the generated code. If you want to use the Slim template directly, you can use the Tilt interface.
1060
1059
 
1061
1060
  ~~~ ruby
1062
1061
  Tilt.new['template.slim'].render(scope)
@@ -1222,8 +1221,6 @@ run the slow parsing benchmark which needs more time. You can also increase the
1222
1221
  $ rake bench slow=1 iterations=1000
1223
1222
  ~~~
1224
1223
 
1225
- 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>
1226
-
1227
1224
  ### Test suite and continuous integration
1228
1225
 
1229
1226
  Slim provides an extensive test-suite based on minitest. You can run the tests
@@ -1231,8 +1228,6 @@ with 'rake test' and the rails integration tests with 'rake test:rails'.
1231
1228
 
1232
1229
  We are currently experimenting with human-readable literate tests which are written as markdown files: [TESTS.md](test/literate/TESTS.md)
1233
1230
 
1234
- Travis-CI is used for continuous integration testing: <http://travis-ci.org/slim-template/slim>
1235
-
1236
1231
  Slim is working well on all major Ruby implementations:
1237
1232
 
1238
1233
  * Ruby 2.5 and newer
@@ -1268,10 +1263,6 @@ If you want to support this project please visit the GitHub sponsors page.
1268
1263
 
1269
1264
  [![GitHub Sponsors](https://img.shields.io/github/sponsors/slim-template)](https://github.com/sponsors/slim-template)
1270
1265
 
1271
- ## Discuss
1272
-
1273
- * [Google Group](http://groups.google.com/group/slim-template)
1274
-
1275
1266
  ## Related projects
1276
1267
 
1277
1268
  Template compilation framework:
data/Rakefile CHANGED
@@ -74,7 +74,7 @@ rescue LoadError
74
74
  end
75
75
  end
76
76
 
77
- desc "Generate Documentation"
77
+ desc 'Generate Documentation'
78
78
  task doc: :yard
79
79
 
80
80
  task default: 'test'
@@ -9,7 +9,7 @@ module Slim
9
9
  # @param [Array] attrs Array of temple expressions
10
10
  # @return [Array] Compiled temple expression
11
11
  def on_html_attrs(*attrs)
12
- [:multi, *attrs.map {|a| compile(a) }]
12
+ [:multi, *attrs.map { |a| compile(a) }]
13
13
  end
14
14
 
15
15
  # Handle attribute expression `[:html, :attr, name, value]`
data/lib/slim/command.rb CHANGED
@@ -45,7 +45,7 @@ module Slim
45
45
  @options[:compile] = true
46
46
  end
47
47
 
48
- opts.on('-r', '--require library', "Load library or plugin with -r slim/plugin") do |lib|
48
+ opts.on('-r', '--require library', 'Load library or plugin with -r slim/plugin') do |lib|
49
49
  require lib.strip
50
50
  end
51
51
 
@@ -16,7 +16,7 @@ module Slim
16
16
  # @param [Array] content Temple expression
17
17
  # @return [Array] Compiled temple expression
18
18
  def on_slim_control(code, content)
19
- code = code + ' do' unless code =~ BLOCK_REGEX || empty_exp?(content)
19
+ code += ' do' unless code =~ BLOCK_REGEX || empty_exp?(content)
20
20
  [:slim, :control, code, compile(content)]
21
21
  end
22
22
 
@@ -27,7 +27,7 @@ module Slim
27
27
  # @param [Array] content Temple expression
28
28
  # @return [Array] Compiled temple expression
29
29
  def on_slim_output(escape, code, content)
30
- code = code + ' do' unless code =~ BLOCK_REGEX || empty_exp?(content)
30
+ code += ' do' unless code =~ BLOCK_REGEX || empty_exp?(content)
31
31
  [:slim, :output, escape, code, compile(content)]
32
32
  end
33
33
  end
data/lib/slim/embedded.rb CHANGED
@@ -154,8 +154,8 @@ module Slim
154
154
 
155
155
  def tilt_render(tilt_engine, tilt_options, text)
156
156
  text = tilt_engine.new(tilt_options.merge(
157
- style: options[:pretty] ? :expanded : :compressed,
158
- cache: false)) { text }.render
157
+ style: options[:pretty] ? :expanded : :compressed
158
+ )) { text }.render
159
159
  text = text.chomp
160
160
  [:static, text]
161
161
  end
@@ -189,9 +189,8 @@ module Slim
189
189
  set_options attributes: {}
190
190
 
191
191
  def on_slim_embedded(engine, body, attrs)
192
-
193
192
  unless options[:attributes].empty?
194
- options[:attributes].map do|k, v|
193
+ options[:attributes].map do |k, v|
195
194
  attrs << [:html, :attr, k, [:static, v]]
196
195
  end
197
196
  end
@@ -207,7 +206,6 @@ module Slim
207
206
 
208
207
  [:html, :tag, options[:tag], attrs, body]
209
208
  end
210
-
211
209
  end
212
210
 
213
211
  # Javascript wrapper engine.
@@ -74,7 +74,7 @@ module Slim
74
74
  return @dict.instance_variable_get(var_name).call(&block) if instance_variable?(var_name)
75
75
  end
76
76
  end
77
- @parent.lambda(name) if @parent
77
+ @parent.lambda(name, &block) if @parent
78
78
  end
79
79
 
80
80
  def [](name)
@@ -105,11 +105,9 @@ module Slim
105
105
  end
106
106
 
107
107
  def instance_variable?(name)
108
- begin
109
- @dict.instance_variable_defined?(name)
110
- rescue NameError
111
- false
112
- end
108
+ @dict.instance_variable_defined?(name)
109
+ rescue NameError
110
+ false
113
111
  end
114
112
  end
115
113
 
data/lib/slim/parser.rb CHANGED
@@ -50,7 +50,7 @@ module Slim
50
50
  @code_attr_delims = options[:code_attr_delims]
51
51
  tabsize = options[:tabsize]
52
52
  if tabsize > 1
53
- @tab_re = /\G((?: {#{tabsize}})*) {0,#{tabsize-1}}\t/
53
+ @tab_re = /\G((?: {#{tabsize}})*) {0,#{tabsize - 1}}\t/
54
54
  @tab = '\1' + ' ' * tabsize
55
55
  else
56
56
  @tab_re = "\t"
@@ -70,9 +70,9 @@ module Slim
70
70
  @additional_attrs[k] = v[:additional_attrs]
71
71
  end
72
72
  end
73
- keys = Regexp.union @attr_shortcut.keys.sort_by {|k| -k.size }
73
+ keys = Regexp.union @attr_shortcut.keys.sort_by { |k| -k.size }
74
74
  @attr_shortcut_re = /\A(#{keys}+)((?:\p{Word}|-|\/\d+|:(\w|-)+)*)/
75
- keys = Regexp.union @tag_shortcut.keys.sort_by {|k| -k.size }
75
+ keys = Regexp.union @tag_shortcut.keys.sort_by { |k| -k.size }
76
76
  @tag_re = /\A(?:#{keys}|\*(?=[^\s]+)|(\p{Word}(?:\p{Word}|:|-)*\p{Word}|\p{Word}+))/
77
77
  keys = Regexp.escape @code_attr_delims.keys.join
78
78
  @code_attr_delims_re = /\A[#{keys}]/
@@ -338,7 +338,7 @@ module Slim
338
338
  syntax_error!('Illegal shortcut') unless shortcut = @attr_shortcut[$1]
339
339
 
340
340
  if shortcut.is_a?(Proc)
341
- shortcut.call($2).each {|a, v| attributes << [:html, :attr, a, [:static, v]] }
341
+ shortcut.call($2).each { |a, v| attributes << [:html, :attr, a, [:static, v]] }
342
342
  else
343
343
  shortcut.each {|a| attributes << [:html, :attr, a, [:static, $2]] }
344
344
  end
@@ -503,9 +503,9 @@ module Slim
503
503
  value << ($1 ? ' ' : "\n")
504
504
  expect_next_line
505
505
  else
506
- if @line[0] == ?{
506
+ if @line[0] == '{'
507
507
  count += 1
508
- elsif @line[0] == ?}
508
+ elsif @line[0] == '}'
509
509
  count -= 1
510
510
  end
511
511
  value << @line.slice!(0)
data/lib/slim/railtie.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Slim
3
4
  class Railtie < ::Rails::Railtie
4
- initializer "initialize slim template handler" do
5
+ initializer 'initialize slim template handler' do
5
6
  ActiveSupport.on_load(:action_view) do
6
7
  Slim::RailsTemplate = Temple::Templates::Rails(Slim::Engine,
7
8
  register_as: :slim,
@@ -37,7 +37,6 @@ module Slim
37
37
  end
38
38
  block
39
39
  end
40
-
41
40
  end
42
41
  end
43
42
  end
@@ -51,13 +51,13 @@ module Slim
51
51
  # so we don't have to worry about that at all.
52
52
  block = [:multi]
53
53
  prev = nil
54
- last_exp = exps.reject{ |exp| exp.first == :newline }.last unless @active && @append
54
+ last_exp = exps.reject { |exp| exp.first == :newline }.last unless @active && @append
55
55
  exps.each do |exp|
56
56
  @append = exp.equal?(last_exp)
57
57
  if @active
58
58
  @prepend = false if prev
59
59
  else
60
- @prepend = prev && ( prev.first != :slim || prev[1] != :text )
60
+ @prepend = prev && (prev.first != :slim || prev[1] != :text)
61
61
  end
62
62
  block << compile(exp)
63
63
  prev = exp unless exp.first == :newline
@@ -8,9 +8,9 @@ module Slim
8
8
  def initialize(opts = {})
9
9
  super
10
10
  word_re = options[:implicit_text] ? '[_a-z0-9]' : '\p{Word}'
11
- attr_keys = Regexp.union(@attr_shortcut.keys.sort_by {|k| -k.size } )
11
+ attr_keys = Regexp.union(@attr_shortcut.keys.sort_by { |k| -k.size })
12
12
  @attr_shortcut_re = /\A(#{attr_keys}+)((?:\p{Word}|-)*)/
13
- tag_keys = Regexp.union((@tag_shortcut.keys - @attr_shortcut.keys).sort_by {|k| -k.size } )
13
+ tag_keys = Regexp.union((@tag_shortcut.keys - @attr_shortcut.keys).sort_by { |k| -k.size })
14
14
  @tag_re = /\A(?:#{attr_keys}(?=-*\p{Word})|#{tag_keys}|\*(?=[^\s]+)|(#{word_re}(?:#{word_re}|:|-)*#{word_re}|#{word_re}+))/
15
15
  end
16
16
 
@@ -25,7 +25,7 @@ module Slim
25
25
  end
26
26
  # Found implicit smart text block.
27
27
  if line = @lines.first
28
- indent = ( line =~ /\A\s*\Z/ ? @indents.last + 1 : get_indent(line) )
28
+ indent = (line =~ /\A\s*\Z/ ? @indents.last + 1 : get_indent(line))
29
29
  end
30
30
  @stacks.last << [:slim, :text, :implicit, parse_text_block(@line, indent)]
31
31
  end
@@ -4,8 +4,9 @@ module Slim
4
4
  module Splat
5
5
  # @api private
6
6
  class Builder
7
- # https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
8
- INVALID_ATTRIBUTE_NAME_REGEX = /[ \0"'>\/=]/
7
+ # https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
8
+ INVALID_ATTRIBUTE_NAME_REGEX = /[ \0"'>\/=]/
9
+
9
10
  def initialize(options)
10
11
  @options = options
11
12
  @attrs = {}
@@ -18,7 +19,7 @@ module Slim
18
19
  elsif @options[:hyphen_attrs].include?(name) && Hash === value
19
20
  hyphen_attr(name, escape, value)
20
21
  elsif value != false && value != nil
21
- attr(name, escape_html(value != true && escape, value))
22
+ attr(name, escape_html(escape, value))
22
23
  end
23
24
  end
24
25
 
@@ -34,7 +35,7 @@ module Slim
34
35
  end
35
36
  if @attrs[name]
36
37
  if delim = @options[:merge_attrs][name]
37
- @attrs[name] += delim + value.to_s
38
+ @attrs[name] = @attrs[name].to_s + delim + value.to_s
38
39
  else
39
40
  raise("Multiple #{name} attributes specified")
40
41
  end
@@ -93,7 +94,7 @@ module Slim
93
94
  if Hash === value
94
95
  if @options[:hyphen_underscore_attrs]
95
96
  value.each do |n, v|
96
- hyphen_attr("#{name}-#{n.to_s.gsub('_', '-')}", escape, v)
97
+ hyphen_attr("#{name}-#{n.to_s.tr('_', '-')}", escape, v)
97
98
  end
98
99
  else
99
100
  value.each do |n, v|
@@ -101,12 +102,12 @@ module Slim
101
102
  end
102
103
  end
103
104
  else
104
- attr(name, escape_html(value != true && escape, value))
105
+ attr(name, escape_html(escape, value))
105
106
  end
106
107
  end
107
108
 
108
109
  def escape_html(escape, value)
109
- return value unless escape
110
+ return value if !escape || value == true
110
111
  @options[:use_html_safe] ? Temple::Utils.escape_html_safe(value) : Temple::Utils.escape_html(value)
111
112
  end
112
113
  end
@@ -11,7 +11,7 @@ module Slim
11
11
  @splat_options = nil
12
12
  exp = compile(exp)
13
13
  if @splat_options
14
- opts = options.to_hash.reject {|k,v| !Filter.options.valid_key?(k) }.inspect
14
+ opts = options.to_hash.reject { |k, v| !Filter.options.valid_key?(k) }.inspect
15
15
  [:multi, [:code, "#{@splat_options} = #{opts}"], exp]
16
16
  else
17
17
  exp
@@ -45,7 +45,7 @@ module Slim
45
45
  # @param [Array] attrs Array of temple expressions
46
46
  # @return [Array] Compiled temple expression
47
47
  def on_html_attrs(*attrs)
48
- if attrs.any? {|attr| splat?(attr) }
48
+ if attrs.any? { |attr| splat?(attr) }
49
49
  builder, block = make_builder(attrs)
50
50
  [:multi,
51
51
  block,
@@ -86,7 +86,7 @@ module Slim
86
86
  attr
87
87
  end
88
88
  end
89
- return builder, result
89
+ [builder, result]
90
90
  end
91
91
  end
92
92
  end
@@ -110,7 +110,7 @@ module Slim
110
110
  def on_slim_output(escape, code, content)
111
111
  @captures_count += 1
112
112
  @text << "%#{@captures_count}"
113
- [:capture, "#{@captures_var}[#{@captures_count-1}]", [:slim, :output, escape, code, content]]
113
+ [:capture, "#{@captures_var}[#{@captures_count - 1}]", [:slim, :output, escape, code, content]]
114
114
  end
115
115
  end
116
116
  end
data/lib/slim/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  module Slim
3
3
  # Slim version string
4
4
  # @api public
5
- VERSION = '5.1.1'
5
+ VERSION = '5.2.0'
6
6
  end
data/test/core/helper.rb CHANGED
@@ -62,16 +62,8 @@ class TestSlim < Minitest::Test
62
62
  end
63
63
 
64
64
  def assert_backtrace(ex, from)
65
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
66
- # HACK: Rubinius stack trace sometimes has one entry more
67
- if ex.backtrace[0] !~ /^#{Regexp.escape from}/
68
- ex.backtrace[1] =~ /([^\s]+:\d+)/
69
- assert_equal from, $1
70
- end
71
- else
72
- ex.backtrace[0] =~ /([^\s]+:\d+)/
73
- assert_equal from, $1
74
- end
65
+ ex.backtrace[0] =~ /([^\s]+:\d+)/
66
+ assert_equal from, $1
75
67
  end
76
68
 
77
69
  def assert_ruby_syntax_error(from, source, options = {})
@@ -73,23 +73,19 @@ class TestSlimCommands < Minitest::Test
73
73
  end
74
74
  end
75
75
 
76
- # We cannot run these two on Travis, because we can't install libyaml.
77
- # See https://github.com/slim-template/slim/issues/576
78
- if ENV['TRAVIS'] && RUBY_ENGINE != 'rbx'
79
- def test_locals_json
80
- data = '{"name":"from slim"}'
81
- prepare_common_test DYNAMIC_TEMPLATE, '--locals', data do |out, err|
82
- assert err.empty?
83
- assert_equal "<p>Hello from slim!</p>\n", out
84
- end
76
+ def test_locals_json
77
+ data = '{"name":"from slim"}'
78
+ prepare_common_test DYNAMIC_TEMPLATE, '--locals', data do |out, err|
79
+ assert err.empty?
80
+ assert_equal "<p>Hello from slim!</p>\n", out
85
81
  end
82
+ end
86
83
 
87
- def test_locals_yaml
88
- data = "name: from slim"
89
- prepare_common_test DYNAMIC_TEMPLATE, '--locals', data do |out, err|
90
- assert err.empty?
91
- assert_equal "<p>Hello from slim!</p>\n", out
92
- end
84
+ def test_locals_yaml
85
+ data = "name: from slim"
86
+ prepare_common_test DYNAMIC_TEMPLATE, '--locals', data do |out, err|
87
+ assert err.empty?
88
+ assert_equal "<p>Hello from slim!</p>\n", out
93
89
  end
94
90
  end
95
91
 
@@ -106,6 +106,25 @@ ruby:
106
106
  assert_ruby_error NameError,"(__TEMPLATE__):4", source
107
107
  end
108
108
 
109
+ def test_embedded_ruby3
110
+ source = %q{
111
+ h1 before
112
+ ruby:
113
+ a = 1
114
+
115
+ h1 between
116
+ ruby:
117
+ b = a + 1
118
+
119
+ unknown_ruby_method
120
+
121
+ c = 3
122
+ h1 third
123
+ }
124
+
125
+ assert_ruby_error NameError,"(__TEMPLATE__):10", source
126
+ end
127
+
109
128
  def test_embedded_markdown
110
129
  source = %q{
111
130
  markdown:
@@ -8,7 +8,7 @@ Slim::Engine.after Slim::Parser, Temple::Filters::Validator, grammar: Slim::Gra
8
8
  Slim::Engine.before :Pretty, Temple::Filters::Validator
9
9
  Slim::Engine.set_options tr: false, logic_less: false
10
10
 
11
- class MiniTest::Spec
11
+ class Minitest::Spec
12
12
  def render(source, options = {}, &block)
13
13
  Slim::Template.new(options) { source }.render(self, &block)
14
14
  end
@@ -312,4 +312,19 @@ div
312
312
  'This is the menu'
313
313
  end
314
314
  end
315
+
316
+ def test_render_parent_lambda
317
+ source = %q{
318
+ - list
319
+ == fn
320
+ p = string
321
+ }
322
+
323
+ assert_html '<fn><p>str</p></fn><fn><p>str</p></fn><fn><p>str</p></fn>',
324
+ source, scope: {
325
+ fn: ->(&block) { "<fn>#{block.call}</fn>" },
326
+ list: [ "item1", "item2", "item3" ],
327
+ string: "str"
328
+ }
329
+ end
315
330
  end
@@ -32,6 +32,11 @@ class SlimController < ApplicationController
32
32
  end
33
33
  end
34
34
 
35
+ def variant
36
+ request.variant = :testvariant
37
+ render :normal
38
+ end
39
+
35
40
  def content_for
36
41
  @hello = "Hello Slim!"
37
42
  end
@@ -0,0 +1,10 @@
1
+ doctype html
2
+
3
+ html
4
+ head
5
+ title Variant
6
+ = csrf_meta_tag
7
+
8
+ body
9
+ = yield :page_heading
10
+ .content= yield
@@ -0,0 +1 @@
1
+ .cute *{class: "nice"} Hello
@@ -5,7 +5,7 @@ require 'action_controller/railtie'
5
5
  require 'action_view/railtie'
6
6
  #require 'active_record/railtie'
7
7
  #require 'action_mailer/railtie'
8
- require 'sprockets/railtie'
8
+ #require 'sprockets/railtie'
9
9
  require 'slim'
10
10
 
11
11
  module Dummy
@@ -9,6 +9,14 @@ class TestSlim < ActionDispatch::IntegrationTest
9
9
  assert_html "<h1>Hello Slim!</h1>"
10
10
  end
11
11
 
12
+ test "variant" do
13
+ get "/slim/variant"
14
+ assert_response :success
15
+ assert_template "slim/normal"
16
+ assert_template "layouts/application"
17
+ assert_equal @response.body, "<!DOCTYPE html><html><head><title>Variant</title></head><body><div class=\"content\"><h1>Hello Slim!</h1></div></body></html>"
18
+ end
19
+
12
20
  test "xml view" do
13
21
  get "/slim/xml"
14
22
  assert_response :success
@@ -86,4 +94,9 @@ class TestSlim < ActionDispatch::IntegrationTest
86
94
  get "/slim/splat"
87
95
  assert_html "<div id=\"splat\"><splat>Hello</splat></div>"
88
96
  end
97
+
98
+ test "splat with delimiter" do
99
+ get "/slim/splat_with_delimiter"
100
+ assert_html "<div class=\"cute nice\">Hello</div>"
101
+ end
89
102
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slim
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.1
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Mendler
8
8
  - Andrew Stone
9
9
  - Fred Wu
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-05-16 00:00:00.000000000 Z
13
+ date: 2023-11-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: temple
@@ -136,6 +136,7 @@ files:
136
136
  - test/rails/app/helpers/application_helper.rb
137
137
  - test/rails/app/models/entry.rb
138
138
  - test/rails/app/views/entries/edit.html.slim
139
+ - test/rails/app/views/layouts/application.html+testvariant.slim
139
140
  - test/rails/app/views/layouts/application.html.slim
140
141
  - test/rails/app/views/slim/_partial.html.slim
141
142
  - test/rails/app/views/slim/attributes.html.slim
@@ -148,6 +149,7 @@ files:
148
149
  - test/rails/app/views/slim/normal.html.slim
149
150
  - test/rails/app/views/slim/partial.html.slim
150
151
  - test/rails/app/views/slim/splat.html.slim
152
+ - test/rails/app/views/slim/splat_with_delimiter.slim
151
153
  - test/rails/app/views/slim/thread_options.html.slim
152
154
  - test/rails/app/views/slim/variables.html.slim
153
155
  - test/rails/app/views/slim/xml.slim
@@ -180,7 +182,7 @@ homepage: http://github.com/slim-template/slim/
180
182
  licenses:
181
183
  - MIT
182
184
  metadata: {}
183
- post_install_message:
185
+ post_install_message:
184
186
  rdoc_options: []
185
187
  require_paths:
186
188
  - lib
@@ -195,8 +197,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
197
  - !ruby/object:Gem::Version
196
198
  version: '0'
197
199
  requirements: []
198
- rubygems_version: 3.2.5
199
- signing_key:
200
+ rubygems_version: 3.4.20
201
+ signing_key:
200
202
  specification_version: 4
201
203
  summary: Slim is a template language.
202
204
  test_files: []