slim 3.0.7 → 3.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +14 -8
- data/CHANGES +6 -0
- data/Gemfile +5 -1
- data/LICENSE +1 -1
- data/README.jp.md +52 -9
- data/README.md +53 -10
- data/benchmarks/profile-parser.rb +0 -0
- data/benchmarks/profile-render.rb +0 -0
- data/doc/include.md +1 -1
- data/doc/jp/include.md +1 -1
- data/doc/smart.md +58 -41
- data/lib/slim/engine.rb +1 -1
- data/lib/slim/parser.rb +9 -5
- data/lib/slim/smart/parser.rb +0 -2
- data/lib/slim/version.rb +1 -1
- data/slim.gemspec +2 -2
- data/test/core/helper.rb +2 -4
- data/test/core/test_commands.rb +5 -6
- data/test/core/test_html_structure.rb +0 -8
- data/test/core/test_parser_errors.rb +1 -1
- data/test/core/test_slim_template.rb +2 -1
- data/test/core/test_splat_prefix_option.rb +155 -0
- data/test/core/test_unicode.rb +0 -1
- data/test/smart/test_smart_text.rb +0 -2
- metadata +12 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6015955337b548a4b9a2771f13ef80790288d6bc
|
4
|
+
data.tar.gz: 83b36da94f2c3a12b2c34f30f59a104268d7fe03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fad25f84c11a4fce52b703b6466be67e2baa5ba62d692bc515f3981078df227edc188a2f14f49eb27e969352dfcbb7ae9f08f1f9ff7f2aa65544070eff6bbe54
|
7
|
+
data.tar.gz: 822391dff4d3328eeab7df526a476492d8ba7713f112a7623c4aa86d9283ae107b83573c27a8e50ecc4e8c736140d31733d9c4610324dd50dbfa8c0b9ed26103
|
data/.travis.yml
CHANGED
@@ -2,18 +2,22 @@ language: ruby
|
|
2
2
|
|
3
3
|
rvm:
|
4
4
|
- ruby-head
|
5
|
-
- 2.
|
6
|
-
- 2.
|
5
|
+
- 2.3.3
|
6
|
+
- 2.2.6
|
7
|
+
- 2.1.10
|
7
8
|
- 2.0.0
|
8
|
-
- rbx-
|
9
|
-
- 1.9.3
|
9
|
+
- rbx-3
|
10
10
|
- jruby-head
|
11
11
|
- jruby-19mode
|
12
12
|
|
13
13
|
sudo: false
|
14
|
+
dist: trusty
|
14
15
|
|
15
16
|
script: "bundle exec rake $TASK"
|
16
17
|
|
18
|
+
after_success:
|
19
|
+
- bundle exec codeclimate-test-reporter
|
20
|
+
|
17
21
|
env:
|
18
22
|
global:
|
19
23
|
# travis encrypt CODECLIMATE_REPO_TOKEN=???
|
@@ -37,12 +41,14 @@ env:
|
|
37
41
|
|
38
42
|
matrix:
|
39
43
|
exclude:
|
40
|
-
- rvm: rbx-
|
41
|
-
env: "TASK=test:rails RAILS=master"
|
42
|
-
- rvm: 1.9.3
|
44
|
+
- rvm: rbx-3
|
43
45
|
env: "TASK=test:rails RAILS=master"
|
44
46
|
- rvm: 2.0.0
|
45
47
|
env: "TASK=test:rails RAILS=master"
|
48
|
+
- rvm: 2.3.3
|
49
|
+
env: "TASK=test:rails RAILS=3.1.12 TILT=1.3.4"
|
50
|
+
- rvm: 2.3.3
|
51
|
+
env: "TASK=test:rails RAILS=3.2.21 TILT=1.3.4"
|
46
52
|
allow_failures:
|
47
53
|
- env: "TASK=test:core_and_plugins TILT=master"
|
48
54
|
- env: "TASK=test:rails RAILS=master"
|
@@ -52,4 +58,4 @@ matrix:
|
|
52
58
|
- rvm: jruby-head
|
53
59
|
|
54
60
|
notifications:
|
55
|
-
irc: "chat.freenode.net#slim-lang"
|
61
|
+
irc: "chat.freenode.net#slim-lang"
|
data/CHANGES
CHANGED
data/Gemfile
CHANGED
@@ -16,7 +16,11 @@ end
|
|
16
16
|
|
17
17
|
if ENV['RAILS']
|
18
18
|
# we need some smarter test logic for the different Rails versions
|
19
|
-
|
19
|
+
if RUBY_VERSION >= '2.1.0'
|
20
|
+
gem 'nokogiri'
|
21
|
+
else
|
22
|
+
gem 'nokogiri', '~> 1.6.8'
|
23
|
+
end
|
20
24
|
|
21
25
|
if ENV['RAILS'] == 'master'
|
22
26
|
gem 'rails', github: 'rails/rails'
|
data/LICENSE
CHANGED
data/README.jp.md
CHANGED
@@ -153,9 +153,9 @@ body
|
|
153
153
|
| <tr><td>#{a.name}</td><td>#{a.description}</td></tr>
|
154
154
|
~~~
|
155
155
|
|
156
|
-
###
|
156
|
+
### スペース付きテキスト `'`
|
157
157
|
|
158
|
-
シングルクォートは Slim に行をコピーしろと命じます (`|` と同様に) が,
|
158
|
+
シングルクォートは Slim に行をコピーしろと命じます (`|` と同様に) が, 末尾にスペースが追加されます。
|
159
159
|
|
160
160
|
### インライン html `<` (HTML 形式)
|
161
161
|
|
@@ -464,7 +464,7 @@ a href=="&"
|
|
464
464
|
|
465
465
|
~~~ slim
|
466
466
|
a data-title="help" data-content="極めて長い長い長いヘルプテキストで\
|
467
|
-
|
467
|
+
続けてその後はまたやり直して繰り返し...."
|
468
468
|
~~~
|
469
469
|
|
470
470
|
#### Ruby コードを用いた属性
|
@@ -559,6 +559,8 @@ a class=:menu,:highlight
|
|
559
559
|
div class="first second third"
|
560
560
|
~~~
|
561
561
|
|
562
|
+
スプラット(アスタリスク)属性のプレフィックスは `splat_prefix` オプションで設定できます。デフォルト値は `'*'` です。
|
563
|
+
|
562
564
|
#### 動的タグ `*`
|
563
565
|
|
564
566
|
アスタリスク属性を使用することで完全に動的なタグを作ることができます。:tag をキーにもつハッシュを返すメソッドを
|
@@ -965,9 +967,9 @@ end
|
|
965
967
|
| 真偽値 | :pretty | false | 綺麗な html インデント <b>(遅くなります!)</b> |
|
966
968
|
| 文字列 | :indent | ' ' | インデントに使用される文字列 |
|
967
969
|
| 真偽値 | :streaming | false (Rails では true, 無効化するにはストリーミングを参照) | ストリーミング出力の有効化, 体感的なパフォーマンスの向上 |
|
968
|
-
| Class | :generator | Temple::Generators::
|
970
|
+
| Class | :generator | Temple::Generators::StringBuffer/ RailsOutputBuffer | Temple コードジェネレータ (デフォルトのジェネレータは文字列バッファを生成します) |
|
969
971
|
| 文字列 | :buffer | '_buf' (Rails では '@output_buffer') | バッファに使用される変数 |
|
970
|
-
|
972
|
+
| 文字列 | :splat_prefix | '*' | スプラット(アスタリスク)属性のプレフィックス |
|
971
973
|
|
972
974
|
Temple フィルタによってもっと多くのオプションがサポートされていますが一覧には載せず公式にはサポートしません。
|
973
975
|
Slim と Temple のコードを確認しなければなりません。
|
@@ -1035,7 +1037,7 @@ html
|
|
1035
1037
|
### Rails
|
1036
1038
|
|
1037
1039
|
Rails のジェネレータは [slim-rails](https://github.com/slim-template/slim-rails) によって提供されます。
|
1038
|
-
slim-rails は Rails で Slim を使用する場合に必須ではありません。Slim をインストールし Gemfile に `gem 'slim
|
1040
|
+
slim-rails は Rails で Slim を使用する場合に必須ではありません。Slim をインストールし Gemfile に `gem 'slim'` を追加するだけです。
|
1039
1041
|
後は .slim 拡張子を使えば Rails で使用できます。
|
1040
1042
|
|
1041
1043
|
#### ストリーミング
|
@@ -1047,6 +1049,47 @@ HTTP ストリーミングは Rails がそれをサポートしているバー
|
|
1047
1049
|
Slim::RailsTemplate.set_options streaming: false
|
1048
1050
|
~~~
|
1049
1051
|
|
1052
|
+
### Angular2
|
1053
|
+
|
1054
|
+
Slim は Angular2 の構文に対応しています。ただし, いくつかのオプションを設定する必要があります:
|
1055
|
+
|
1056
|
+
#### `splat_prefix` オプション
|
1057
|
+
|
1058
|
+
このオプションはパーサにスプラット(アスタリスク)属性に使用する構文を知らせます。
|
1059
|
+
デフォルト値はアスタリスクです: `splat_prefix: '*'`
|
1060
|
+
アスタリスクは Angular2 でも構造ディレクティブとして `*ngIf` などで使われます。デフォルトの設定値は Slim と Angular2 の構文衝突の原因になります。
|
1061
|
+
|
1062
|
+
解決方法は 2 つあります:
|
1063
|
+
|
1064
|
+
* `splat_prefix` に 2 重アスタリスクのようなカスタム値(`splat_prefix: '**'`)を設定します。これで構造ディレクティブは期待通りに機能するはずです。スプラット(アスタリスク)属性は設定したカスタム値のプレフィックスで書かなければならないので注意してください。
|
1065
|
+
* アスタリスクではない代わりのディレクティブ構文を使う
|
1066
|
+
|
1067
|
+
#### 属性区切り文字
|
1068
|
+
|
1069
|
+
Angular と Slim はそれぞれの構文で括弧を使います。この場合も解決方法は 2 つ:
|
1070
|
+
* バインディングに代わりの構文を使う (`bind-...` など)
|
1071
|
+
* 属性区切り文字を波括弧に限定する
|
1072
|
+
```
|
1073
|
+
code_attr_delims: {
|
1074
|
+
'{' => '}',
|
1075
|
+
},
|
1076
|
+
attr_list_delims: {
|
1077
|
+
'{' => '}',
|
1078
|
+
},
|
1079
|
+
```
|
1080
|
+
|
1081
|
+
これで次のよう書けます:
|
1082
|
+
```
|
1083
|
+
h1{ #var (bind1)="test" [bind2]="ok" [(bind3)]="works?" *ngIf="expr" *ngFor="expression" } {{it works}}
|
1084
|
+
```
|
1085
|
+
|
1086
|
+
コンパイル結果:
|
1087
|
+
```
|
1088
|
+
<h1 #var="" (bind1)="test" [bind2]="ok" [(bind3)]="works?" *ngIf="expr" *ngFor="expression">
|
1089
|
+
{{it works}}
|
1090
|
+
</h1>
|
1091
|
+
```
|
1092
|
+
|
1050
1093
|
## ツール
|
1051
1094
|
|
1052
1095
|
### Slim コマンド 'slimrb'
|
@@ -1140,8 +1183,7 @@ Travis-CI は継続的インテグレーションテストに利用されてい
|
|
1140
1183
|
|
1141
1184
|
Slim はすべての主要な Ruby 実装で動作します:
|
1142
1185
|
|
1143
|
-
* Ruby
|
1144
|
-
* Ruby EE
|
1186
|
+
* Ruby 2.0, 2.1, 2.2 および 2.3
|
1145
1187
|
* JRuby 1.9 mode
|
1146
1188
|
* Rubinius 2.0
|
1147
1189
|
|
@@ -1155,7 +1197,7 @@ $ git clone git://github.com/slim-template/slim
|
|
1155
1197
|
|
1156
1198
|
魔法をかけた後 pull request を送ってください。私たちは pull request が大好きです!
|
1157
1199
|
|
1158
|
-
Ruby の 2.
|
1200
|
+
Ruby の 2.3.0, 2.2.0, 2.1.0 と 2.0.0 でテストをすることを覚えておいてください。
|
1159
1201
|
|
1160
1202
|
もしドキュメントの不足を見つけたら, README.md をアップデートして私たちを助けて下さい。Slim に割く時間がないが, 私たちが知るべきものを何か見つけた場合には issue を送ってください。
|
1161
1203
|
|
@@ -1226,5 +1268,6 @@ Slim は [MIT license](http://www.opensource.org/licenses/MIT) に基づいて
|
|
1226
1268
|
* [Faml (Faster Haml implementation, also using Temple like Slim)](https://github.com/eagletmt/faml)
|
1227
1269
|
* [Haml (Older engine which inspired Slim)](https://github.com/haml/haml)
|
1228
1270
|
* [Jade (Similar engine for javascript)](https://github.com/visionmedia/jade)
|
1271
|
+
* [Pug (Successor of Jade, Similar engine for javascript)](https://github.com/pugjs/pug)
|
1229
1272
|
* [Sweet (Similar engine which also allows to write classes and functions)](https://github.com/joaomdmoura/sweet)
|
1230
1273
|
* [Amber (Similar engine for Go)](https://github.com/eknkc/amber)
|
data/README.md
CHANGED
@@ -55,7 +55,7 @@ by the logic less plugin and the translator plugin which provides I18n. In logic
|
|
55
55
|
### Why use Slim?
|
56
56
|
|
57
57
|
* Slim allows you to write very minimal templates which are easy to maintain and pretty much guarantees that you write well-formed HTML and XML
|
58
|
-
*
|
58
|
+
* The Slim syntax is aesthetic and makes it more fun to write templates. Since you can use Slim as a drop-in replacement in all the major frameworks it is easy to adopt.
|
59
59
|
* The Slim architecture is very flexible and allows you to write syntax extensions and plugins.
|
60
60
|
|
61
61
|
___Yes, Slim is speedy!___ Slim was developed right from the start with performance in mind.
|
@@ -252,7 +252,7 @@ The doctype keyword can be used to generate the complex doctypes in a very simpl
|
|
252
252
|
|
253
253
|
XML VERSION
|
254
254
|
|
255
|
-
|
255
|
+
~~~ slim
|
256
256
|
doctype xml
|
257
257
|
<?xml version="1.0" encoding="utf-8" ?>
|
258
258
|
|
@@ -464,7 +464,7 @@ You can break quoted attributes with backslash `\`
|
|
464
464
|
|
465
465
|
~~~ slim
|
466
466
|
a data-title="help" data-content="extremely long help text that goes on\
|
467
|
-
and
|
467
|
+
and on and on and then starts over...."
|
468
468
|
~~~
|
469
469
|
|
470
470
|
#### Ruby attributes
|
@@ -487,7 +487,7 @@ The attribute value will be escaped by default. Use == if you want to disable es
|
|
487
487
|
a href==action_path(:start)
|
488
488
|
~~~
|
489
489
|
|
490
|
-
You can also break ruby attributes with backslash `\` or trailing `,` as
|
490
|
+
You can also break ruby attributes with backslash `\` or trailing `,` as described for control sections.
|
491
491
|
|
492
492
|
#### Boolean attributes
|
493
493
|
|
@@ -559,6 +559,8 @@ This renders as:
|
|
559
559
|
div class="first second third"
|
560
560
|
~~~
|
561
561
|
|
562
|
+
Splat attributes prefix may be configured via `splat_prefix` option. Default value is `'*'`
|
563
|
+
|
562
564
|
#### Dynamic tags `*`
|
563
565
|
|
564
566
|
You can create completely dynamic tags using the splat attributes. Just create a method which returns a hash
|
@@ -965,9 +967,9 @@ There are a lot of them but the good thing is, that Slim checks the configuratio
|
|
965
967
|
| Boolean | :pretty | false | Pretty HTML indenting, only block level tags are indented <b>(This is slower!)</b> |
|
966
968
|
| String | :indent | ' ' | Indentation string |
|
967
969
|
| Boolean | :streaming | false (true in Rails, see below how to disable it!) | Enable output streaming, improves the perceived performance |
|
968
|
-
| Class | :generator | Temple::Generators::
|
970
|
+
| Class | :generator | Temple::Generators::StringBuffer/ RailsOutputBuffer | Temple code generator (default generator generates string buffer) |
|
969
971
|
| String | :buffer | '_buf' ('@output_buffer' in Rails) | Variable used for buffer |
|
970
|
-
|
972
|
+
| String | :splat_prefix | '*' | Prefix used for splat attributes |
|
971
973
|
|
972
974
|
There are more options which are supported by the Temple filters but which are not exposed and are not officially supported. You
|
973
975
|
have to take a look at the Slim and Temple code for that.
|
@@ -1035,7 +1037,7 @@ html
|
|
1035
1037
|
### Rails
|
1036
1038
|
|
1037
1039
|
Rails generators are provided by [slim-rails](https://github.com/slim-template/slim-rails). slim-rails
|
1038
|
-
is not necessary to use Slim in Rails though. Just install Slim and add it to your Gemfile with `gem 'slim
|
1040
|
+
is not necessary to use Slim in Rails though. Just install Slim and add it to your Gemfile with `gem 'slim'`.
|
1039
1041
|
Then just use the .slim extension and you're good to go.
|
1040
1042
|
|
1041
1043
|
#### Streaming
|
@@ -1047,6 +1049,47 @@ performance. The rendering time in total will increase. If you want to disable i
|
|
1047
1049
|
Slim::RailsTemplate.set_options streaming: false
|
1048
1050
|
~~~
|
1049
1051
|
|
1052
|
+
### Angular2
|
1053
|
+
|
1054
|
+
Slim now supports Angular2 syntax. But you need to set some configuration options:
|
1055
|
+
|
1056
|
+
#### `splat_prefix` option
|
1057
|
+
|
1058
|
+
This option tells parser what syntax to use for splat attributes.
|
1059
|
+
Default value is asterisk: `splat_prefix: '*'`
|
1060
|
+
Asterisk is also used in Angular2 for structural directives such as `*ngIf` and others, so default configuration causes a conflict between slim and angular2 syntax.
|
1061
|
+
|
1062
|
+
There are two ways to resolve it:
|
1063
|
+
|
1064
|
+
* Set `splat_prefix` to any custom value, double asterisk, for example: `splat_prefix: '**'`. Now structural directives should work as expected. Remember that now splat attributes should be written with new custom prefix before them.
|
1065
|
+
* Use alternative directive syntax without asterisk.
|
1066
|
+
|
1067
|
+
#### Attribute delimeters
|
1068
|
+
|
1069
|
+
Angular and slim both uses brackets in their syntax. So there are also two ways:
|
1070
|
+
* Use alternative syntax for binding (`bind-...` and so on)
|
1071
|
+
* Limit attribute delimeters to curly braces only:
|
1072
|
+
```
|
1073
|
+
code_attr_delims: {
|
1074
|
+
'{' => '}',
|
1075
|
+
},
|
1076
|
+
attr_list_delims: {
|
1077
|
+
'{' => '}',
|
1078
|
+
},
|
1079
|
+
```
|
1080
|
+
|
1081
|
+
Now you can use something like this:
|
1082
|
+
```
|
1083
|
+
h1{ #var (bind1)="test" [bind2]="ok" [(bind3)]="works?" *ngIf="expr" *ngFor="expression" } {{it works}}
|
1084
|
+
```
|
1085
|
+
|
1086
|
+
Will be compiled to:
|
1087
|
+
```
|
1088
|
+
<h1 #var="" (bind1)="test" [bind2]="ok" [(bind3)]="works?" *ngIf="expr" *ngFor="expression">
|
1089
|
+
{{it works}}
|
1090
|
+
</h1>
|
1091
|
+
```
|
1092
|
+
|
1050
1093
|
## Tools
|
1051
1094
|
|
1052
1095
|
### Slim Command 'slimrb'
|
@@ -1140,8 +1183,7 @@ Travis-CI is used for continuous integration testing: <http://travis-ci.org/slim
|
|
1140
1183
|
|
1141
1184
|
Slim is working well on all major Ruby implementations:
|
1142
1185
|
|
1143
|
-
* Ruby
|
1144
|
-
* Ruby EE
|
1186
|
+
* Ruby 2.0, 2.1, 2.2 and 2.3
|
1145
1187
|
* JRuby 1.9 mode
|
1146
1188
|
* Rubinius 2.0
|
1147
1189
|
|
@@ -1155,7 +1197,7 @@ $ git clone git://github.com/slim-template/slim
|
|
1155
1197
|
|
1156
1198
|
Work your magic and then submit a pull request. We love pull requests!
|
1157
1199
|
|
1158
|
-
Please remember to keep the compatibility with Ruby versions
|
1200
|
+
Please remember to keep the compatibility with Ruby versions 2.0.0, 2.1.0, 2.2.0 and 2.3.0.
|
1159
1201
|
|
1160
1202
|
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.
|
1161
1203
|
|
@@ -1226,5 +1268,6 @@ Language ports/Similar languages:
|
|
1226
1268
|
* [Faml (Faster Haml implementation, also using Temple like Slim)](https://github.com/eagletmt/faml)
|
1227
1269
|
* [Haml (Older engine which inspired Slim)](https://github.com/haml/haml)
|
1228
1270
|
* [Jade (Similar engine for javascript)](https://github.com/visionmedia/jade)
|
1271
|
+
* [Pug (Successor of Jade, Similar engine for javascript)](https://github.com/pugjs/pug)
|
1229
1272
|
* [Sweet (Similar engine which also allows to write classes and functions)](https://github.com/joaomdmoura/sweet)
|
1230
1273
|
* [Amber (Similar engine for Go)](https://github.com/eknkc/amber)
|
File without changes
|
File without changes
|
data/doc/include.md
CHANGED
@@ -17,4 +17,4 @@ Enable the include plugin with
|
|
17
17
|
|
18
18
|
| Type | Name | Default | Purpose |
|
19
19
|
| ---- | ---- | ------- | ------- |
|
20
|
-
|
|
20
|
+
| Array | :include_dirs | [Dir.pwd, '.'] | Directories where to look for the files |
|
data/doc/jp/include.md
CHANGED
data/doc/smart.md
CHANGED
@@ -1,44 +1,60 @@
|
|
1
1
|
# Smart text
|
2
2
|
|
3
|
-
The
|
3
|
+
The <a name="smarttext">smart text plugin</a> was created to simplify the typing and combining of text and markup in Slim templates.
|
4
|
+
Using the plugin gives you:
|
4
5
|
|
5
|
-
|
6
|
+
* More convenient ways to type text in Slim templates.
|
7
|
+
* Smarter and more consistent HTML escaping of typed text.
|
8
|
+
* Easier combining of the text with inline HTML tags with smart handling of whitespace on the boundaries.
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
This automatically enables the `:implicit_text` option as well,
|
10
|
-
so you can easily type text like this:
|
10
|
+
To get started, enable the smart text plugin with
|
11
11
|
|
12
|
-
|
13
|
-
This is text.
|
14
|
-
This is text, too.
|
12
|
+
require 'slim/smart'
|
15
13
|
|
16
|
-
|
14
|
+
First of all, this automatically enables the `:implicit_text` option.
|
15
|
+
When enabled, Slim will treat any line which doesn't start
|
17
16
|
with a lowercase tag name or any of the special characters as an implicit text line.
|
18
|
-
If the text
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
17
|
+
If the text needs to span several lines, indent them as usual.
|
18
|
+
|
19
|
+
This allows you to easily type text like this, without any leading indicator:
|
20
|
+
|
21
|
+
This is an implicit text.
|
22
|
+
This is a text
|
23
|
+
which spans
|
24
|
+
several lines.
|
25
|
+
This is yet another text.
|
26
|
+
|
27
|
+
This works in addition to ways already available in stock Slim:
|
28
|
+
|
29
|
+
p This is an inline text.
|
30
|
+
p This is an inline text
|
31
|
+
which spans multiple lines.
|
32
|
+
| This is a verbatim text.
|
33
|
+
| This is a verbatim text
|
34
|
+
which spans multiple lines.
|
35
|
+
<p>This is in fact a verbatim text as well.</p>
|
36
|
+
|
37
|
+
You can also mark the text explicitly with a leading `>`.
|
38
|
+
This is used for example when the text starts with a lowercase letter or an unusual character,
|
39
|
+
or merely for aesthetic consistency when it spans several lines.
|
40
|
+
It may be also needed if you want to use uppercase tag names
|
30
41
|
and therefore need to keep the `:implicit_text` option disabled.
|
31
42
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
43
|
+
> This is an explicit text.
|
44
|
+
> This is an explicit text
|
45
|
+
which spans
|
46
|
+
several lines.
|
47
|
+
> 'This is a text, too.'
|
48
|
+
|
49
|
+
> This is another way
|
50
|
+
> of typing text which spans
|
51
|
+
> several lines, if you prefer that.
|
39
52
|
|
53
|
+
BTW, all these examples can be pasted to `slimrb -r slim/smart` to see how the generated output looks like.
|
54
|
+
|
55
|
+
The plugin also improves upon Slim's automatic HTML escaping.
|
40
56
|
As long as you leave the `:smart_text_escaping` enabled,
|
41
|
-
any non-verbatim text is automatically escaped for you.
|
57
|
+
any non-verbatim text (i.e., any implicit, explicit, and inline text) is automatically escaped for you.
|
42
58
|
However, for your convenience, any HTML entities detected are still used verbatim.
|
43
59
|
This way you are most likely to get what you really wanted,
|
44
60
|
without having to worry about HTML escaping all the time.
|
@@ -47,8 +63,8 @@ without having to worry about HTML escaping all the time.
|
|
47
63
|
footer
|
48
64
|
Copyright © #{Time.now.year}
|
49
65
|
|
50
|
-
Another cool thing about
|
51
|
-
|
66
|
+
Another cool thing about the plugin is that it makes text mix fairly well with markup.
|
67
|
+
The text lines are made to preserve newlines as needed,
|
52
68
|
so it is easy to mix them with other tags, like emphasis or links:
|
53
69
|
|
54
70
|
p
|
@@ -57,18 +73,18 @@ so it is easy to mix them with other tags, like emphasis or links:
|
|
57
73
|
> be charged now.
|
58
74
|
p
|
59
75
|
Check
|
60
|
-
a href=
|
76
|
+
a href='/faq' our FAQ
|
61
77
|
> for more info.
|
62
78
|
|
63
79
|
(Note the use of the explicit text indicator `>` to distinguish lowercase text from tags).
|
64
80
|
|
65
|
-
However, sometimes you do not want
|
66
|
-
Fortunately
|
67
|
-
The
|
68
|
-
with a character from the `:smart_text_begin_chars` set (`,.;:!?)]}` by default).
|
69
|
-
Similarly, trailing newline is suppressed if the smart text block ends
|
81
|
+
However, sometimes you do not want any whitespace around the inline tag at all.
|
82
|
+
Fortunately the plugin takes care of the most common cases for you as well.
|
83
|
+
The newline before the tag is suppressed if the preceding line ends
|
70
84
|
with a character from the `:smart_text_end_chars` set (`([{` by default).
|
71
|
-
|
85
|
+
Similarly, the newline after the tag is suppressed if the following line begins
|
86
|
+
with a character from the `:smart_text_begin_chars` set (`,.;:!?)]}` by default).
|
87
|
+
This makes it quite easy to naturally mix normal text with links or spans like this:
|
72
88
|
|
73
89
|
p
|
74
90
|
Please proceed to
|
@@ -76,10 +92,10 @@ This makes it quite easy to mix normal text with links or spans like this:
|
|
76
92
|
.
|
77
93
|
p
|
78
94
|
Status: failed (
|
79
|
-
a href="#1" details
|
95
|
+
a href="#1" see details
|
80
96
|
).
|
81
97
|
|
82
|
-
Note that
|
98
|
+
Note that the plugin is smart enough to know about tag shortcuts, too,
|
83
99
|
so it will correctly deal even with cases like this:
|
84
100
|
|
85
101
|
.class
|
@@ -88,6 +104,7 @@ so it will correctly deal even with cases like this:
|
|
88
104
|
i text
|
89
105
|
...
|
90
106
|
|
107
|
+
And that's it.
|
91
108
|
Of course, all this is meant only to make working with short text snippets more convenient.
|
92
109
|
For bulk text content, you are more than welcome to use one of the builtin embedded engines,
|
93
110
|
such as Markdown or Textile.
|
data/lib/slim/engine.rb
CHANGED
data/lib/slim/parser.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
module Slim
|
3
2
|
# Parses Slim code and transforms it to a Temple expression
|
4
3
|
# @api private
|
@@ -19,7 +18,8 @@ module Slim
|
|
19
18
|
shortcut: {
|
20
19
|
'#' => { attr: 'id' },
|
21
20
|
'.' => { attr: 'class' }
|
22
|
-
}
|
21
|
+
},
|
22
|
+
splat_prefix: '*'
|
23
23
|
|
24
24
|
class SyntaxError < StandardError
|
25
25
|
attr_reader :error, :file, :line, :lineno, :column
|
@@ -87,7 +87,7 @@ module Slim
|
|
87
87
|
# Compile string to Temple expression
|
88
88
|
#
|
89
89
|
# @param [String] str Slim code
|
90
|
-
# @return [Array] Temple expression representing the code
|
90
|
+
# @return [Array] Temple expression representing the code
|
91
91
|
def call(str)
|
92
92
|
result = [:multi]
|
93
93
|
reset(str.split(/\r?\n/), [result])
|
@@ -414,9 +414,13 @@ module Slim
|
|
414
414
|
end_re = /\A\s*#{Regexp.escape delimiter}/
|
415
415
|
end
|
416
416
|
|
417
|
+
splat_prefix = Regexp.escape(options[:splat_prefix])
|
418
|
+
splat_regexp_source = '\A\s*' << splat_prefix << '(?=[^\s]+)'
|
419
|
+
@splat_attrs_regexp = Regexp.new(splat_regexp_source)
|
420
|
+
|
417
421
|
while true
|
418
422
|
case @line
|
419
|
-
when
|
423
|
+
when @splat_attrs_regexp
|
420
424
|
# Splat attribute
|
421
425
|
@line = $'
|
422
426
|
attributes << [:slim, :splat, parse_ruby_code(delimiter)]
|
@@ -523,7 +527,7 @@ module Slim
|
|
523
527
|
line = @orig_line.lstrip
|
524
528
|
column = (@orig_line && @line ? @orig_line.size - @line.size : 0) + line.size - @orig_line.size
|
525
529
|
warn %{Deprecated syntax: #{message}
|
526
|
-
#{options[:file]}, Line #{@lineno}, Column #{
|
530
|
+
#{options[:file]}, Line #{@lineno}, Column #{column + 1}
|
527
531
|
#{line}
|
528
532
|
#{' ' * column}^
|
529
533
|
}
|
data/lib/slim/smart/parser.rb
CHANGED
data/lib/slim/version.rb
CHANGED
data/slim.gemspec
CHANGED
@@ -17,8 +17,8 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
18
|
s.require_paths = %w(lib)
|
19
19
|
|
20
|
-
s.required_ruby_version = '>=
|
20
|
+
s.required_ruby_version = '>=2.0.0'
|
21
21
|
|
22
|
-
s.add_runtime_dependency('temple', ['
|
22
|
+
s.add_runtime_dependency('temple', ['>= 0.7.6', '< 0.9'])
|
23
23
|
s.add_runtime_dependency('tilt', ['>= 1.3.3', '< 2.1'])
|
24
24
|
end
|
data/test/core/helper.rb
CHANGED
data/test/core/test_commands.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
require 'helper'
|
3
2
|
require 'open3'
|
4
3
|
require 'tempfile'
|
@@ -23,14 +22,14 @@ class TestSlimCommands < Minitest::Test
|
|
23
22
|
out, err = exec_slimrb '--help'
|
24
23
|
|
25
24
|
assert err.empty?
|
26
|
-
assert_match
|
25
|
+
assert_match %r{Show this message}, out
|
27
26
|
end
|
28
27
|
|
29
28
|
def test_option_version
|
30
29
|
out, err = exec_slimrb '--version'
|
31
30
|
|
32
31
|
assert err.empty?
|
33
|
-
assert_match
|
32
|
+
assert_match %r{\ASlim #{Regexp.escape Slim::VERSION}$}, out
|
34
33
|
end
|
35
34
|
|
36
35
|
def test_render
|
@@ -113,15 +112,15 @@ class TestSlimCommands < Minitest::Test
|
|
113
112
|
def test_error
|
114
113
|
prepare_common_test EXCEPTION_TEMPLATE, stdin_file: false do |out, err|
|
115
114
|
assert out.empty?
|
116
|
-
assert_match
|
117
|
-
assert_match
|
115
|
+
assert_match %r{NotImplementedError: NotImplementedError}, err
|
116
|
+
assert_match %r{Use --trace for backtrace}, err
|
118
117
|
end
|
119
118
|
end
|
120
119
|
|
121
120
|
def test_trace_error
|
122
121
|
prepare_common_test EXCEPTION_TEMPLATE, '--trace', stdin_file: false do |out, err|
|
123
122
|
assert out.empty?
|
124
|
-
assert_match
|
123
|
+
assert_match %r{bin\/slimrb}, err
|
125
124
|
end
|
126
125
|
end
|
127
126
|
|
@@ -358,14 +358,6 @@ p < x=(1+1) > Hello
|
|
358
358
|
assert_html '<p>{ foo="bar" x=(1+1) }</p><p x="2">Hello</p>', source, attr_list_delims: {'<' => '>'}, code_attr_delims: { '(' => ')' }
|
359
359
|
end
|
360
360
|
|
361
|
-
def test_closed_tag
|
362
|
-
source = %q{
|
363
|
-
closed/
|
364
|
-
}
|
365
|
-
|
366
|
-
assert_html '<closed />', source, format: :xhtml
|
367
|
-
end
|
368
|
-
|
369
361
|
def test_attributs_with_parens_and_spaces
|
370
362
|
source = %q{label{ for='filter' }= hello_world}
|
371
363
|
assert_html '<label for="filter">Hello World from @env</label>', source
|
@@ -65,7 +65,7 @@ p
|
|
65
65
|
img(src="img.jpg
|
66
66
|
}
|
67
67
|
|
68
|
-
assert_syntax_error "Unexpected end of file\n (__TEMPLATE__), Line 3, Column 0\n \n ^\n", source
|
68
|
+
assert_syntax_error "Unexpected end of file\n (__TEMPLATE__), Line 3, Column 0\n \n ^\n", source
|
69
69
|
end
|
70
70
|
|
71
71
|
def test_expected_closing_attribute_delimiter
|
@@ -47,7 +47,8 @@ class TestSlimTemplate < TestSlim
|
|
47
47
|
fail unless data[0] == ?h
|
48
48
|
template = Slim::Template.new('test.slim') { data }
|
49
49
|
begin
|
50
|
-
|
50
|
+
template.render(Object.new, name: 'Joe', foo: 'bar')
|
51
|
+
fail 'should have raised an exception'
|
51
52
|
rescue => ex
|
52
53
|
assert_kind_of MockError, ex
|
53
54
|
assert_backtrace(ex, 'test.slim:5')
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSplatPrefixOption < TestSlim
|
4
|
+
|
5
|
+
def prefixes
|
6
|
+
['*','**','*!','*%','*^','*$']
|
7
|
+
end
|
8
|
+
|
9
|
+
def options(prefix)
|
10
|
+
{ splat_prefix: prefix }
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_splat_without_content
|
14
|
+
prefixes.each do |prefix|
|
15
|
+
source = %Q{
|
16
|
+
#{prefix}hash
|
17
|
+
p#{prefix}hash
|
18
|
+
}
|
19
|
+
|
20
|
+
assert_html '<div a="The letter a" b="The letter b"></div><p a="The letter a" b="The letter b"></p>', source, options(prefix)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_shortcut_splat
|
25
|
+
prefixes.each do |prefix|
|
26
|
+
source = %Q{
|
27
|
+
#{prefix}hash This is my title
|
28
|
+
}
|
29
|
+
|
30
|
+
assert_html '<div a="The letter a" b="The letter b">This is my title</div>', source, options(prefix)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_splat
|
35
|
+
prefixes.each do |prefix|
|
36
|
+
source = %Q{
|
37
|
+
h1 #{prefix}hash class=[] This is my title
|
38
|
+
}
|
39
|
+
|
40
|
+
assert_html '<h1 a="The letter a" b="The letter b">This is my title</h1>', source, options(prefix)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_closed_splat
|
45
|
+
prefixes.each do |prefix|
|
46
|
+
source = %Q{
|
47
|
+
#{prefix}hash /
|
48
|
+
}
|
49
|
+
|
50
|
+
assert_html '<div a="The letter a" b="The letter b" />', source, options(prefix)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_splat_tag_name
|
55
|
+
prefixes.each do |prefix|
|
56
|
+
source = %Q{
|
57
|
+
#{prefix}{tag: 'h1', id: 'title'} This is my title
|
58
|
+
}
|
59
|
+
|
60
|
+
assert_html '<h1 id="title">This is my title</h1>', source, options(prefix)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def test_splat_empty_tag_name
|
66
|
+
prefixes.each do |prefix|
|
67
|
+
source = %Q{
|
68
|
+
#{prefix}{tag: '', id: 'test'} This is my title
|
69
|
+
}
|
70
|
+
|
71
|
+
assert_html '<div id="test">This is my title</div>', source, options(prefix)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_closed_splat_tag
|
76
|
+
prefixes.each do |prefix|
|
77
|
+
source = %Q{
|
78
|
+
#{prefix}hash /
|
79
|
+
}
|
80
|
+
|
81
|
+
assert_html '<div a="The letter a" b="The letter b" />', source, options(prefix)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_splat_with_id_shortcut
|
86
|
+
prefixes.each do |prefix|
|
87
|
+
source = %Q{
|
88
|
+
#myid#{prefix}hash This is my title
|
89
|
+
}
|
90
|
+
|
91
|
+
assert_html '<div a="The letter a" b="The letter b" id="myid">This is my title</div>', source, options(prefix)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_splat_with_class_shortcut
|
96
|
+
prefixes.each do |prefix|
|
97
|
+
source = %Q{
|
98
|
+
.myclass#{prefix}hash This is my title
|
99
|
+
}
|
100
|
+
|
101
|
+
assert_html '<div a="The letter a" b="The letter b" class="myclass">This is my title</div>', source, options(prefix)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_splat_with_id_and_class_shortcuts
|
106
|
+
prefixes.each do |prefix|
|
107
|
+
source = %Q{
|
108
|
+
#myid.myclass#{prefix}hash This is my title
|
109
|
+
}
|
110
|
+
|
111
|
+
assert_html '<div a="The letter a" b="The letter b" class="myclass" id="myid">This is my title</div>', source, options(prefix)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_splat_with_class_merging
|
116
|
+
prefixes.each do |prefix|
|
117
|
+
source = %Q{
|
118
|
+
#myid.myclass #{prefix}{class: [:secondclass, %w(x y z)]} #{prefix}hash This is my title
|
119
|
+
}
|
120
|
+
|
121
|
+
assert_html '<div a="The letter a" b="The letter b" class="myclass secondclass x y z" id="myid">This is my title</div>', source, options(prefix)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_splat_with_boolean_attribute
|
126
|
+
prefixes.each do |prefix|
|
127
|
+
source = %Q{
|
128
|
+
#{prefix}{disabled: true, empty1: false, nonempty: '', empty2: nil} This is my title
|
129
|
+
}
|
130
|
+
|
131
|
+
assert_html '<div disabled="" nonempty="">This is my title</div>', source, options(prefix)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_splat_merging_with_arrays
|
136
|
+
prefixes.each do |prefix|
|
137
|
+
source = %Q{
|
138
|
+
#{prefix}{a: 1, b: 2} #{prefix}[[:c, 3], [:d, 4]] #{prefix}[[:e, 5], [:f, 6]] This is my title
|
139
|
+
}
|
140
|
+
|
141
|
+
assert_html '<div a="1" b="2" c="3" d="4" e="5" f="6">This is my title</div>', source, options(prefix)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_splat_with_other_attributes
|
146
|
+
prefixes.each do |prefix|
|
147
|
+
source = %Q{
|
148
|
+
h1 data-id="123" #{prefix}hash This is my title
|
149
|
+
}
|
150
|
+
|
151
|
+
assert_html '<h1 a="The letter a" b="The letter b" data-id="123">This is my title</h1>', source, options(prefix)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
data/test/core/test_unicode.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Mendler
|
@@ -10,22 +10,28 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2017-05-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: temple
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- - "
|
19
|
+
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: 0.7.6
|
22
|
+
- - "<"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '0.9'
|
22
25
|
type: :runtime
|
23
26
|
prerelease: false
|
24
27
|
version_requirements: !ruby/object:Gem::Requirement
|
25
28
|
requirements:
|
26
|
-
- - "
|
29
|
+
- - ">="
|
27
30
|
- !ruby/object:Gem::Version
|
28
31
|
version: 0.7.6
|
32
|
+
- - "<"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0.9'
|
29
35
|
- !ruby/object:Gem::Dependency
|
30
36
|
name: tilt
|
31
37
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,6 +133,7 @@ files:
|
|
127
133
|
- test/core/test_pretty.rb
|
128
134
|
- test/core/test_ruby_errors.rb
|
129
135
|
- test/core/test_slim_template.rb
|
136
|
+
- test/core/test_splat_prefix_option.rb
|
130
137
|
- test/core/test_tabs.rb
|
131
138
|
- test/core/test_text_interpolation.rb
|
132
139
|
- test/core/test_thread_options.rb
|
@@ -190,7 +197,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
197
|
requirements:
|
191
198
|
- - ">="
|
192
199
|
- !ruby/object:Gem::Version
|
193
|
-
version:
|
200
|
+
version: 2.0.0
|
194
201
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
202
|
requirements:
|
196
203
|
- - ">="
|