slim 5.1.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +28 -5
- data/CHANGES +12 -1
- data/Gemfile +6 -7
- data/README.jp.md +19 -29
- data/README.md +43 -28
- data/Rakefile +1 -1
- data/lib/slim/code_attributes.rb +2 -1
- data/lib/slim/command.rb +2 -8
- data/lib/slim/controls.rb +1 -0
- data/lib/slim/do_inserter.rb +3 -2
- data/lib/slim/embedded.rb +6 -7
- data/lib/slim/end_inserter.rb +1 -0
- data/lib/slim/engine.rb +1 -0
- data/lib/slim/erb_converter.rb +1 -0
- data/lib/slim/filter.rb +1 -0
- data/lib/slim/grammar.rb +1 -0
- data/lib/slim/include.rb +1 -0
- data/lib/slim/interpolation.rb +1 -0
- data/lib/slim/logic_less/context.rb +6 -7
- data/lib/slim/logic_less/filter.rb +1 -0
- data/lib/slim/logic_less.rb +1 -0
- data/lib/slim/parser.rb +17 -10
- data/lib/slim/railtie.rb +3 -1
- data/lib/slim/smart/escaper.rb +1 -1
- data/lib/slim/smart/filter.rb +3 -2
- data/lib/slim/smart/parser.rb +4 -3
- data/lib/slim/smart.rb +1 -0
- data/lib/slim/splat/builder.rb +10 -8
- data/lib/slim/splat/filter.rb +4 -3
- data/lib/slim/template.rb +1 -0
- data/lib/slim/translator.rb +4 -3
- data/lib/slim/version.rb +2 -1
- data/lib/slim.rb +1 -0
- data/slim.gemspec +1 -1
- data/test/core/helper.rb +3 -11
- data/test/core/test_commands.rb +11 -15
- data/test/core/test_encoding.rb +2 -2
- data/test/core/test_html_structure.rb +48 -0
- data/test/core/test_ruby_errors.rb +19 -0
- data/test/literate/helper.rb +1 -1
- data/test/literate/run.rb +1 -1
- data/test/logic_less/test_logic_less.rb +15 -0
- data/test/rails/app/controllers/slim_controller.rb +7 -1
- data/test/rails/app/views/layouts/application.html+testvariant.slim +10 -0
- data/test/rails/app/views/slim/attributes.html.slim +3 -0
- data/test/rails/app/views/slim/splat_with_delimiter.slim +1 -0
- data/test/rails/config/application.rb +1 -1
- data/test/rails/test/test_slim.rb +18 -0
- metadata +11 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9008a7eaa7a19ae0ada9b2a6789ff073a43fceaea9e24fe284ebf698fd5b02c
|
4
|
+
data.tar.gz: 2c79bf7dc50662e04fb711ba4a1c334265c3a5b2186a111b932a04f02ae16680
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c4aa87d3b5a20242328258c6cfe8b436af5f92b437076bb185926764e5168959087aca53e5c0face78bde9b6670b6c4023f4893f98f58c6db97d730961ed93a
|
7
|
+
data.tar.gz: 178427ae03b2c8e2918c4114376a5dd3955ac20ef393d5a355ca441617a39f3b66101ff00bbb7c0c6e8b12aee338db2914c37910712c1ada5aa5814f9e3cdd79
|
data/.github/workflows/test.yml
CHANGED
@@ -9,16 +9,16 @@ on:
|
|
9
9
|
- synchronize
|
10
10
|
- reopened
|
11
11
|
schedule:
|
12
|
-
- cron: "
|
12
|
+
- cron: "0 15 * * 0"
|
13
13
|
jobs:
|
14
14
|
basic:
|
15
15
|
runs-on: ubuntu-latest
|
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@
|
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.
|
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@
|
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,14 @@
|
|
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
|
+
|
7
|
+
5.1.1 (2023-05-16)
|
8
|
+
|
9
|
+
* Support lambda functions as shortcuts - #677 #813 #903
|
10
|
+
* Support --enable-frozen-string-literal - #851
|
11
|
+
|
1
12
|
5.1.0 (2023-03-06)
|
2
13
|
|
3
14
|
* Allow whitespace markers for verbatim text: `|<`, `|>`, and `|<>` - #912
|
@@ -238,7 +249,7 @@
|
|
238
249
|
* BACKWARD INCOMPATIBLE CHANGE - Dynamic attributes which return empty value "" are not removed anymore
|
239
250
|
(this means "" is now interpreted as true), whereas false and nil are still removed.
|
240
251
|
This corresponds to the definition of boolean attributes in XHTML and HTML5.
|
241
|
-
* Deprecated option :remove_empty_attrs
|
252
|
+
* Deprecated option :remove_empty_attrs
|
242
253
|
* Add option :escape_quoted_attrs to escape quoted attributes, use == if you don't want that.
|
243
254
|
The default is false to stay backward compatible.
|
244
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', :
|
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', :
|
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', :
|
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'] == '
|
40
|
-
gem 'sinatra', :
|
38
|
+
if ENV['SINATRA'] == 'main'
|
39
|
+
gem 'sinatra', github: 'sinatra/sinatra'
|
41
40
|
else
|
42
|
-
gem 'sinatra', :
|
41
|
+
gem 'sinatra', tag: "v#{ENV['SINATRA']}"
|
43
42
|
end
|
44
43
|
end
|
data/README.jp.md
CHANGED
@@ -29,26 +29,25 @@ Slim は 不可解にならない程度に view の構文を本質的な部品
|
|
29
29
|
|
30
30
|
## リンク
|
31
31
|
|
32
|
-
* ホームページ: <
|
33
|
-
* ソース: <
|
34
|
-
* バグ: <
|
35
|
-
* リスト: <http://groups.google.com/group/slim-template>
|
32
|
+
* ホームページ: <https://slim-template.github.io>
|
33
|
+
* ソース: <https://github.com/slim-template/slim>
|
34
|
+
* バグ: <https://github.com/slim-template/slim/issues>
|
36
35
|
* API ドキュメント:
|
37
|
-
* 最新の Gem: <
|
38
|
-
* GitHub
|
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
|
-
私たちは継続的インテグレーションを採用しています。(
|
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/
|
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 はあなたのアプリケーションのパフォーマンスに悪影響を与えないことを保証します。
|
@@ -409,7 +407,7 @@ body
|
|
409
407
|
タグの後に直接属性を書きます。通常の属性記述にはダブルクォート `"` か シングルクォート `'` を使わなければなりません (引用符で囲まれた属性)。
|
410
408
|
|
411
409
|
~~~ slim
|
412
|
-
a href="
|
410
|
+
a href="https://slim-template.github.io" title='Slim のホームページ' Slim のホームページへ
|
413
411
|
~~~
|
414
412
|
|
415
413
|
引用符で囲まれたテキストを属性として使えます。
|
@@ -445,7 +443,7 @@ h2 [ id = "tagline" ] = page_tagline
|
|
445
443
|
例:
|
446
444
|
|
447
445
|
~~~ slim
|
448
|
-
a href="
|
446
|
+
a href="https://slim-template.github.io" title='Slim のホームページ' Slim のホームページへ
|
449
447
|
~~~
|
450
448
|
|
451
449
|
引用符で囲まれたテキストを属性として使えます:
|
@@ -510,13 +508,13 @@ input type="text" disabled=nil
|
|
510
508
|
class 属性はスペース区切りで結合されます。
|
511
509
|
|
512
510
|
~~~ slim
|
513
|
-
a.menu class="highlight" href="
|
511
|
+
a.menu class="highlight" href="https://slim-template.github.io/" slim-template.github.io
|
514
512
|
~~~
|
515
513
|
|
516
514
|
レンダリング結果:
|
517
515
|
|
518
516
|
~~~ html
|
519
|
-
<a class="menu highlight" href="
|
517
|
+
<a class="menu highlight" href="https://slim-template.github.io/">slim-template.github.io</a>
|
520
518
|
~~~
|
521
519
|
|
522
520
|
また, `Array` を属性値として使うと、配列要素が区切り文字で結合されます。
|
@@ -569,7 +567,7 @@ div class="first second third"
|
|
569
567
|
~~~ slim
|
570
568
|
ruby:
|
571
569
|
def a_unless_current
|
572
|
-
@page_current ? {tag: 'span'} : {tag: 'a', href: '
|
570
|
+
@page_current ? {tag: 'span'} : {tag: 'a', href: 'https://slim-template.github.io/'}
|
573
571
|
end
|
574
572
|
- @page_current = true
|
575
573
|
*a_unless_current リンク
|
@@ -580,7 +578,7 @@ ruby:
|
|
580
578
|
レンダリング結果:
|
581
579
|
|
582
580
|
~~~ html
|
583
|
-
<span>リンク</span><a href="
|
581
|
+
<span>リンク</span><a href="https://slim-template.github.io/">リンク</a>
|
584
582
|
~~~
|
585
583
|
|
586
584
|
### ショートカット
|
@@ -794,7 +792,7 @@ end
|
|
794
792
|
そして, 次のように使用出来ます。
|
795
793
|
|
796
794
|
~~~ slim
|
797
|
-
- links = { '
|
795
|
+
- links = { 'https://slim-template.github.io' => 'The Slim Template Language' }
|
798
796
|
= capture link_list=:link_list, links do |url, text|
|
799
797
|
a href=url = text
|
800
798
|
~~~
|
@@ -843,7 +841,7 @@ body
|
|
843
841
|
|
844
842
|
## 埋め込みエンジン (Markdown, ...)
|
845
843
|
|
846
|
-
[Tilt](https://github.com/
|
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/
|
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/
|
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
|
[](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
@@ -29,26 +29,25 @@ A short list of the features...
|
|
29
29
|
|
30
30
|
## Links
|
31
31
|
|
32
|
-
* Homepage: <
|
33
|
-
* Source: <
|
34
|
-
* Bugs: <
|
35
|
-
* List: <http://groups.google.com/group/slim-template>
|
32
|
+
* Homepage: <https://slim-template.github.io>
|
33
|
+
* Source: <https://github.com/slim-template/slim>
|
34
|
+
* Bugs: <https://github.com/slim-template/slim/issues>
|
36
35
|
* API documentation:
|
37
|
-
* Latest Gem: <
|
38
|
-
* GitHub
|
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 (
|
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/
|
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.
|
@@ -153,7 +152,7 @@ You can also embed html in the text line
|
|
153
152
|
| <tr><td>#{a.name}</td><td>#{a.description}</td></tr>
|
154
153
|
~~~
|
155
154
|
|
156
|
-
#### Verbatim text with leading and/or
|
155
|
+
#### Verbatim text with leading and/or trailing white space `|<` `|>` `|<>`
|
157
156
|
|
158
157
|
You can add white space around verbatim text in the same way as for `=` output:
|
159
158
|
~~~ slim
|
@@ -420,7 +419,7 @@ body
|
|
420
419
|
You write attributes directly after the tag. For normal text attributes you must use double `"` or single quotes `'` (Quoted attributes).
|
421
420
|
|
422
421
|
~~~ slim
|
423
|
-
a href="
|
422
|
+
a href="https://slim-template.github.io" title='Slim Homepage' Goto the Slim homepage
|
424
423
|
~~~
|
425
424
|
|
426
425
|
You can use text interpolation in the quoted attributes.
|
@@ -456,7 +455,7 @@ h2 [ id = "tagline" ] = page_tagline
|
|
456
455
|
Example:
|
457
456
|
|
458
457
|
~~~ slim
|
459
|
-
a href="
|
458
|
+
a href="https://slim-template.github.io" title='Slim Homepage' Goto the Slim homepage
|
460
459
|
~~~
|
461
460
|
|
462
461
|
You can use text interpolation in the quoted attributes:
|
@@ -521,13 +520,13 @@ You can configure attributes to be merged if multiple are given (See option `:me
|
|
521
520
|
this is done for class attributes with the white space as delimiter.
|
522
521
|
|
523
522
|
~~~ slim
|
524
|
-
a.menu class="highlight" href="
|
523
|
+
a.menu class="highlight" href="https://slim-template.github.io/" slim-template.github.io
|
525
524
|
~~~
|
526
525
|
|
527
526
|
This renders as:
|
528
527
|
|
529
528
|
~~~ html
|
530
|
-
<a class="menu highlight" href="
|
529
|
+
<a class="menu highlight" href="https://slim-template.github.io/">slim-template.github.io</a>
|
531
530
|
~~~
|
532
531
|
|
533
532
|
You can also use an `Array` as attribute value and the array elements will be merged using the delimiter.
|
@@ -580,7 +579,7 @@ with the :tag key.
|
|
580
579
|
~~~ slim
|
581
580
|
ruby:
|
582
581
|
def a_unless_current
|
583
|
-
@page_current ? {tag: 'span'} : {tag: 'a', href: '
|
582
|
+
@page_current ? {tag: 'span'} : {tag: 'a', href: 'https://slim-template.github.io/'}
|
584
583
|
end
|
585
584
|
- @page_current = true
|
586
585
|
*a_unless_current Link
|
@@ -591,7 +590,7 @@ ruby:
|
|
591
590
|
This renders as:
|
592
591
|
|
593
592
|
~~~ html
|
594
|
-
<span>Link</span><a href="
|
593
|
+
<span>Link</span><a href="https://slim-template.github.io/">Link</a>
|
595
594
|
~~~
|
596
595
|
|
597
596
|
### Shortcuts
|
@@ -701,6 +700,30 @@ which renders to
|
|
701
700
|
</script>
|
702
701
|
~~~
|
703
702
|
|
703
|
+
#### Lambda shortcuts
|
704
|
+
|
705
|
+
You can define custom shortcuts using lambdas.
|
706
|
+
|
707
|
+
In this example we add `~` to create a shortcut with a special processing (adding a prefix) for the class attribute.
|
708
|
+
|
709
|
+
~~~ ruby
|
710
|
+
Slim::Engine.set_options shortcut: {'~' => {attr: ->(v) {{class: "styled-#{v}"}}}}
|
711
|
+
~~~
|
712
|
+
|
713
|
+
We can use it in Slim code like this
|
714
|
+
|
715
|
+
~~~ slim
|
716
|
+
h1~title Hello
|
717
|
+
~text~question.paragraph How are you?
|
718
|
+
~~~
|
719
|
+
|
720
|
+
which renders to
|
721
|
+
|
722
|
+
~~~ html
|
723
|
+
<h1 class="styled-title">Hello</h1>
|
724
|
+
<div class="styled-text styled-question paragraph">How are you?</div>
|
725
|
+
~~~
|
726
|
+
|
704
727
|
#### ID shortcut `#` and class shortcut `.`
|
705
728
|
|
706
729
|
You can specify the `id` and `class` attributes in the following shortcut form
|
@@ -805,7 +828,7 @@ end
|
|
805
828
|
and it would be used as follows
|
806
829
|
|
807
830
|
~~~ slim
|
808
|
-
- links = { '
|
831
|
+
- links = { 'https://slim-template.github.io' => 'The Slim Template Language' }
|
809
832
|
= capture link_list=:link_list, links do |url, text|
|
810
833
|
a href=url = text
|
811
834
|
~~~
|
@@ -854,7 +877,7 @@ body
|
|
854
877
|
|
855
878
|
## Embedded engines (Markdown, ...)
|
856
879
|
|
857
|
-
Thanks to [Tilt](https://github.com/
|
880
|
+
Thanks to [Tilt](https://github.com/jeremyevans/tilt), Slim has extensive support for embedding other template engines.
|
858
881
|
|
859
882
|
Examples:
|
860
883
|
|
@@ -877,8 +900,8 @@ Supported engines:
|
|
877
900
|
| ruby: | none | Shortcut | Shortcut to embed ruby code |
|
878
901
|
| javascript: | none | Shortcut | Shortcut to embed javascript code and wrap in script tag |
|
879
902
|
| css: | none | Shortcut | Shortcut to embed css code and wrap in style tag |
|
880
|
-
| sass: | sass | Compile time | Embed sass code and wrap in style tag |
|
881
|
-
| 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 |
|
882
905
|
| less: | less | Compile time | Embed less css code and wrap in style tag |
|
883
906
|
| coffee: | coffee-script | Compile time | Compile coffee script code and wrap in script tag |
|
884
907
|
| markdown: | redcarpet/rdiscount/kramdown | Compile time + Interpolation | Compile markdown code and interpolate #\{variables} in text |
|
@@ -1032,7 +1055,7 @@ Slim currently provides plugins for logic less mode, includes and I18n. See the
|
|
1032
1055
|
|
1033
1056
|
### Tilt
|
1034
1057
|
|
1035
|
-
Slim uses [Tilt](https://github.com/
|
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.
|
1036
1059
|
|
1037
1060
|
~~~ ruby
|
1038
1061
|
Tilt.new['template.slim'].render(scope)
|
@@ -1198,8 +1221,6 @@ run the slow parsing benchmark which needs more time. You can also increase the
|
|
1198
1221
|
$ rake bench slow=1 iterations=1000
|
1199
1222
|
~~~
|
1200
1223
|
|
1201
|
-
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>
|
1202
|
-
|
1203
1224
|
### Test suite and continuous integration
|
1204
1225
|
|
1205
1226
|
Slim provides an extensive test-suite based on minitest. You can run the tests
|
@@ -1207,8 +1228,6 @@ with 'rake test' and the rails integration tests with 'rake test:rails'.
|
|
1207
1228
|
|
1208
1229
|
We are currently experimenting with human-readable literate tests which are written as markdown files: [TESTS.md](test/literate/TESTS.md)
|
1209
1230
|
|
1210
|
-
Travis-CI is used for continuous integration testing: <http://travis-ci.org/slim-template/slim>
|
1211
|
-
|
1212
1231
|
Slim is working well on all major Ruby implementations:
|
1213
1232
|
|
1214
1233
|
* Ruby 2.5 and newer
|
@@ -1244,10 +1263,6 @@ If you want to support this project please visit the GitHub sponsors page.
|
|
1244
1263
|
|
1245
1264
|
[](https://github.com/sponsors/slim-template)
|
1246
1265
|
|
1247
|
-
## Discuss
|
1248
|
-
|
1249
|
-
* [Google Group](http://groups.google.com/group/slim-template)
|
1250
|
-
|
1251
1266
|
## Related projects
|
1252
1267
|
|
1253
1268
|
Template compilation framework:
|
data/Rakefile
CHANGED
data/lib/slim/code_attributes.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Slim
|
2
3
|
# @api private
|
3
4
|
class CodeAttributes < Filter
|
@@ -8,7 +9,7 @@ module Slim
|
|
8
9
|
# @param [Array] attrs Array of temple expressions
|
9
10
|
# @return [Array] Compiled temple expression
|
10
11
|
def on_html_attrs(*attrs)
|
11
|
-
[:multi, *attrs.map {|a| compile(a) }]
|
12
|
+
[:multi, *attrs.map { |a| compile(a) }]
|
12
13
|
end
|
13
14
|
|
14
15
|
# Handle attribute expression `[:html, :attr, name, value]`
|
data/lib/slim/command.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'slim'
|
2
3
|
require 'optparse'
|
3
4
|
|
@@ -44,7 +45,7 @@ module Slim
|
|
44
45
|
@options[:compile] = true
|
45
46
|
end
|
46
47
|
|
47
|
-
opts.on('-r', '--require library',
|
48
|
+
opts.on('-r', '--require library', 'Load library or plugin with -r slim/plugin') do |lib|
|
48
49
|
require lib.strip
|
49
50
|
end
|
50
51
|
|
@@ -63,13 +64,6 @@ module Slim
|
|
63
64
|
eval(locals)
|
64
65
|
else
|
65
66
|
require 'yaml'
|
66
|
-
if RUBY_ENGINE == 'rbx'
|
67
|
-
begin
|
68
|
-
require 'psych'
|
69
|
-
rescue LoadError
|
70
|
-
$stderr.puts 'Please install psych gem as Rubunius ships with an old YAML engine.'
|
71
|
-
end
|
72
|
-
end
|
73
67
|
YAML.load(locals)
|
74
68
|
end
|
75
69
|
end
|
data/lib/slim/controls.rb
CHANGED
data/lib/slim/do_inserter.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Slim
|
2
3
|
# In Slim you don't need the do keyword sometimes. This
|
3
4
|
# filter adds the missing keyword.
|
@@ -15,7 +16,7 @@ module Slim
|
|
15
16
|
# @param [Array] content Temple expression
|
16
17
|
# @return [Array] Compiled temple expression
|
17
18
|
def on_slim_control(code, content)
|
18
|
-
code
|
19
|
+
code += ' do' unless code =~ BLOCK_REGEX || empty_exp?(content)
|
19
20
|
[:slim, :control, code, compile(content)]
|
20
21
|
end
|
21
22
|
|
@@ -26,7 +27,7 @@ module Slim
|
|
26
27
|
# @param [Array] content Temple expression
|
27
28
|
# @return [Array] Compiled temple expression
|
28
29
|
def on_slim_output(escape, code, content)
|
29
|
-
code
|
30
|
+
code += ' do' unless code =~ BLOCK_REGEX || empty_exp?(content)
|
30
31
|
[:slim, :output, escape, code, compile(content)]
|
31
32
|
end
|
32
33
|
end
|
data/lib/slim/embedded.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Slim
|
2
3
|
# @api private
|
3
4
|
class TextCollector < Filter
|
4
5
|
def call(exp)
|
5
|
-
@collected = ''
|
6
|
+
@collected = ''.dup
|
6
7
|
super(exp)
|
7
8
|
@collected
|
8
9
|
end
|
@@ -30,7 +31,7 @@ module Slim
|
|
30
31
|
# @api private
|
31
32
|
class OutputProtector < Filter
|
32
33
|
def call(exp)
|
33
|
-
@protect, @collected, @tag = [], '', object_id.abs.to_s(36)
|
34
|
+
@protect, @collected, @tag = [], ''.dup, object_id.abs.to_s(36)
|
34
35
|
super(exp)
|
35
36
|
@collected
|
36
37
|
end
|
@@ -153,8 +154,8 @@ module Slim
|
|
153
154
|
|
154
155
|
def tilt_render(tilt_engine, tilt_options, text)
|
155
156
|
text = tilt_engine.new(tilt_options.merge(
|
156
|
-
style: options[:pretty] ? :expanded : :compressed
|
157
|
-
|
157
|
+
style: options[:pretty] ? :expanded : :compressed
|
158
|
+
)) { text }.render
|
158
159
|
text = text.chomp
|
159
160
|
[:static, text]
|
160
161
|
end
|
@@ -188,9 +189,8 @@ module Slim
|
|
188
189
|
set_options attributes: {}
|
189
190
|
|
190
191
|
def on_slim_embedded(engine, body, attrs)
|
191
|
-
|
192
192
|
unless options[:attributes].empty?
|
193
|
-
options[:attributes].map do|k, v|
|
193
|
+
options[:attributes].map do |k, v|
|
194
194
|
attrs << [:html, :attr, k, [:static, v]]
|
195
195
|
end
|
196
196
|
end
|
@@ -206,7 +206,6 @@ module Slim
|
|
206
206
|
|
207
207
|
[:html, :tag, options[:tag], attrs, body]
|
208
208
|
end
|
209
|
-
|
210
209
|
end
|
211
210
|
|
212
211
|
# Javascript wrapper engine.
|
data/lib/slim/end_inserter.rb
CHANGED
data/lib/slim/engine.rb
CHANGED
data/lib/slim/erb_converter.rb
CHANGED