slim 3.0.0 → 3.0.1
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/.travis.yml +1 -0
- data/CHANGES +5 -0
- data/README.jp.md +13 -11
- data/README.md +2 -2
- data/lib/slim/code_attributes.rb +1 -1
- data/lib/slim/interpolation.rb +2 -20
- data/lib/slim/parser.rb +7 -11
- data/lib/slim/version.rb +1 -1
- data/test/core/test_code_evaluation.rb +8 -0
- data/test/core/test_html_attributes.rb +9 -0
- data/test/core/test_parser_errors.rb +0 -9
- metadata +2 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eeabe6b2a2349dba5997fc11b9f8308b8c059b64
|
|
4
|
+
data.tar.gz: bf7ecd8073af2e89a0ee3cf413ac8db8bdf2392f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e84616653fbc224fbff5e4ce111a38d38afaa75a20a70f6f7c0428e65a225ca23228a4b0bf9c26d01784b3ee919d476cd369aaffdfe602d13a2cc2c8aa04cb1e
|
|
7
|
+
data.tar.gz: 122cfa59ce81ad34e11d67b9988768b69fa7a9cdb18bacd02a0a4d1f722631b7cfa5a22985dcde14c743fa99cb8726dda8a8a8b9d264c47066d55b8eb3fef289
|
data/.travis.yml
CHANGED
|
@@ -22,6 +22,7 @@ env:
|
|
|
22
22
|
- "TASK=test:rails RAILS=3.2.21 TILT=1.3.4"
|
|
23
23
|
- "TASK=test:rails RAILS=4.0.12"
|
|
24
24
|
- "TASK=test:rails RAILS=4.1.8"
|
|
25
|
+
- "TASK=test:rails RAILS=4.2.0"
|
|
25
26
|
- "TASK=test:sinatra SINATRA=master"
|
|
26
27
|
- "TASK=test:sinatra SINATRA=1.3.6"
|
|
27
28
|
- "TASK=test:sinatra SINATRA=1.4.5"
|
data/CHANGES
CHANGED
data/README.jp.md
CHANGED
|
@@ -199,14 +199,14 @@ body
|
|
|
199
199
|
|
|
200
200
|
行末がカンマ `,` で終わる場合 (例 関数呼び出し) には行末にバックスラッシュを追加する必要はありません。行末スペースを追加するために修飾子の `>` や `<` もサポートします。
|
|
201
201
|
|
|
202
|
-
* `=>` は末尾のスペースを伴った出力をします。 末尾のスペースが追加されることを除いて, 単一の等合 (`=`)
|
|
202
|
+
* `=>` は末尾のスペースを伴った出力をします。 末尾のスペースが追加されることを除いて, 単一の等合 (`=`) と同じです。
|
|
203
203
|
* `=<` は先頭のスペースを伴った出力をします。先頭のスペースが追加されることを除いて, 単一の等号 (`=`) と同じです。
|
|
204
204
|
|
|
205
205
|
### HTML エスケープを伴わない出力 `==`
|
|
206
206
|
|
|
207
207
|
単一のイコール (`=`) と同じですが, `escape_html` メソッドを経由しません。 末尾や先頭のスペースを追加するための修飾子 `>` と `<` はサポートされています。
|
|
208
208
|
|
|
209
|
-
* `==>` は HTML エスケープを行わず末尾のスペースを伴った出力をします。末尾のスペースが追加されることを除いて, 二重等号 (`==`) と同じです。
|
|
209
|
+
* `==>` は HTML エスケープを行わず末尾のスペースを伴った出力をします。末尾のスペースが追加されることを除いて, 二重等号 (`==`) と同じです。
|
|
210
210
|
* `==<` は HTML エスケープを行わず先頭のスペースを伴った出力をします。先頭のスペースが追加されることを除いて, 二重等号 (`==`) と同じです。
|
|
211
211
|
|
|
212
212
|
### コードコメント `/`
|
|
@@ -870,10 +870,7 @@ Slim を設定する方法はコンパイル機構に少し依存します。(Ra
|
|
|
870
870
|
### デフォルトオプション
|
|
871
871
|
|
|
872
872
|
~~~ ruby
|
|
873
|
-
# デバック用に html をきれいにインデントし属性をソートしない
|
|
874
|
-
Slim::Engine.set_options pretty: true. sort_attrs: false
|
|
875
|
-
|
|
876
|
-
# デバック用に html をきれいにインデントし属性をソートしない (Ruby 1.9)
|
|
873
|
+
# デバック用に html をきれいにインデントし属性をソートしない
|
|
877
874
|
Slim::Engine.set_options pretty: true, sort_attrs: false
|
|
878
875
|
~~~
|
|
879
876
|
|
|
@@ -944,7 +941,7 @@ end
|
|
|
944
941
|
| シンボル | :js_wrapper | nil | :comment, :cdata や :both で JavaScript をラップします。:guess を指定することで :format オプションに基いて設定することもできます |
|
|
945
942
|
| 真偽値 | :pretty | false | 綺麗な html インデント <b>(遅くなります!)</b> |
|
|
946
943
|
| 文字列 | :indent | ' ' | インデントに使用される文字列 |
|
|
947
|
-
| 真偽値 | :streaming | false (Rails では true) |
|
|
944
|
+
| 真偽値 | :streaming | false (Rails では true, 無効化するにはストリーミングを参照) | ストリーミング出力の有効化, 体感的なパフォーマンスの向上 |
|
|
948
945
|
| Class | :generator | Temple::Generators::ArrayBuffer/ RailsOutputBuffer | Temple コードジェネレータ (デフォルトのジェネレータは配列バッファを生成します) |
|
|
949
946
|
| 文字列 | :buffer | '_buf' (Rails では '@output_buffer') | バッファに使用される変数 |
|
|
950
947
|
|
|
@@ -1015,12 +1012,17 @@ html
|
|
|
1015
1012
|
### Rails
|
|
1016
1013
|
|
|
1017
1014
|
Rails のジェネレータは [slim-rails](https://github.com/slim-template/slim-rails) によって提供されます。
|
|
1018
|
-
slim-rails は Rails で Slim を使用する場合に必須ではありません。Slim をインストールし Gemfile に `gem 'slim'` を追加するだけです。
|
|
1015
|
+
slim-rails は Rails で Slim を使用する場合に必須ではありません。Slim をインストールし Gemfile に `gem 'slim-rails'` を追加するだけです。
|
|
1019
1016
|
後は .slim 拡張子を使えば Rails で使用できます。
|
|
1020
1017
|
|
|
1021
|
-
####
|
|
1018
|
+
#### ストリーミング
|
|
1019
|
+
|
|
1020
|
+
HTTP ストリーミングは Rails がそれをサポートしているバージョンであればデフォルトで有効化されています。しかし, ストリーミングが体感的なパフォーマンスを改善していることを知る必要があります。
|
|
1021
|
+
レンダリング時間は増加するでしょう。ストリーミングを無効化したい場合の設定です:
|
|
1022
1022
|
|
|
1023
|
-
|
|
1023
|
+
~~~ ruby
|
|
1024
|
+
Slim::RailsTemplate.set_options streaming: false
|
|
1025
|
+
~~~
|
|
1024
1026
|
|
|
1025
1027
|
## ツール
|
|
1026
1028
|
|
|
@@ -1113,7 +1115,7 @@ Travis-CI は継続的インテグレーションテストに利用されてい
|
|
|
1113
1115
|
|
|
1114
1116
|
Slim はすべての主要な Ruby 実装で動作します:
|
|
1115
1117
|
|
|
1116
|
-
* Ruby 1.
|
|
1118
|
+
* Ruby 1.9.3, 2.0.0 および 2.1.0
|
|
1117
1119
|
* Ruby EE
|
|
1118
1120
|
* JRuby 1.9 mode
|
|
1119
1121
|
* Rubinius 2.0
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Slim
|
|
2
2
|
|
|
3
|
-
[](http://rubygems.org/gems/slim) [](http://travis-ci.org/slim-template/slim) [](https://gemnasium.com/slim-template/slim) [](https://codeclimate.com/github/slim-template/slim) [](https://www.gittip.com/min4d/ "Donate weekly to this project using Gittip")
|
|
4
4
|
[](https://flattr.com/submit/auto?user_id=min4d&url=http%3A%2F%2Fslim-lang.org%2F "Donate monthly to this project using Flattr")
|
|
5
5
|
|
|
6
6
|
Slim is a template language whose goal is to reduce the view syntax to the essential parts without becoming cryptic. It started as an exercise to see how much could be removed from a standard html template (<, >, closing tags, etc...). As more people took an interest in Slim, the functionality grew and so did the flexibility of the syntax.
|
|
@@ -1148,7 +1148,7 @@ Slim is released under the [MIT license](http://www.opensource.org/licenses/MIT)
|
|
|
1148
1148
|
|
|
1149
1149
|
If you want to support this project please visit the Gittip and Flattr pages.
|
|
1150
1150
|
|
|
1151
|
-
[](https://www.gittip.com/min4d/ "Donate weekly to this project using Gittip")
|
|
1152
1152
|
[](https://flattr.com/submit/auto?user_id=min4d&url=http%3A%2F%2Fslim-lang.org%2F "Donate monthly to this project using Flattr")
|
|
1153
1153
|
|
|
1154
1154
|
Currently the donations will be used to cover the hosting costs (domain name etc).
|
data/lib/slim/code_attributes.rb
CHANGED
|
@@ -54,7 +54,7 @@ module Slim
|
|
|
54
54
|
[:code, "#{tmp} = #{code}"],
|
|
55
55
|
[:if, "Array === #{tmp}",
|
|
56
56
|
[:multi,
|
|
57
|
-
[:code, "#{tmp}.flatten
|
|
57
|
+
[:code, "#{tmp} = #{tmp}.flatten"],
|
|
58
58
|
[:code, "#{tmp}.map!(&:to_s)"],
|
|
59
59
|
[:code, "#{tmp}.reject!(&:empty?)"],
|
|
60
60
|
[:escape, escape, [:dynamic, "#{tmp}.join(#{delimiter.inspect})"]]],
|
data/lib/slim/interpolation.rb
CHANGED
|
@@ -18,9 +18,9 @@ module Slim
|
|
|
18
18
|
# Escaped interpolation
|
|
19
19
|
block << [:static, '#{']
|
|
20
20
|
string = $'
|
|
21
|
-
when /\A#\{/
|
|
21
|
+
when /\A#\{((?>[^{}]|(\{(?>[^{}]|\g<1>)*\}))*)\}/
|
|
22
22
|
# Interpolation
|
|
23
|
-
string, code =
|
|
23
|
+
string, code = $', $1
|
|
24
24
|
escape = code !~ /\A\{.*\}\Z/
|
|
25
25
|
block << [:slim, :output, escape, escape ? code : code[1..-2], [:multi]]
|
|
26
26
|
when /\A([#\\]?[^#\\]*([#\\][^\\#\{][^#\\]*)*)/
|
|
@@ -31,23 +31,5 @@ module Slim
|
|
|
31
31
|
end until string.empty?
|
|
32
32
|
block
|
|
33
33
|
end
|
|
34
|
-
|
|
35
|
-
protected
|
|
36
|
-
|
|
37
|
-
def parse_expression(string)
|
|
38
|
-
count, i = 1, 0
|
|
39
|
-
while i < string.size && count != 0
|
|
40
|
-
if string[i] == ?{
|
|
41
|
-
count += 1
|
|
42
|
-
elsif string[i] == ?}
|
|
43
|
-
count -= 1
|
|
44
|
-
end
|
|
45
|
-
i += 1
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
raise(Temple::FilterError, "Text interpolation: Expected closing }") if count != 0
|
|
49
|
-
|
|
50
|
-
return string[i..-1], string[0, i-1]
|
|
51
|
-
end
|
|
52
34
|
end
|
|
53
35
|
end
|
data/lib/slim/parser.rb
CHANGED
|
@@ -72,8 +72,10 @@ module Slim
|
|
|
72
72
|
@code_attr_delims_re = /\A[#{keys}]/
|
|
73
73
|
keys = Regexp.escape @attr_list_delims.keys.join
|
|
74
74
|
@attr_list_delims_re = /\A\s*([#{keys}])/
|
|
75
|
-
# Access available engine keys to allow nicer one-line syntax
|
|
76
75
|
@embedded_re = /\A(#{Regexp.union(Embedded.engines.keys.map(&:to_s))}):(\s*)/
|
|
76
|
+
@attr_name = "\\A\\s*([^\0\"'><\/=\s#{(@attr_list_delims.flatten + @code_attr_delims.flatten).map {|x| Regexp.escape(x) }.join}]+)"
|
|
77
|
+
@quoted_attr_re = /#{@attr_name}\s*=(=?)\s*("|')/
|
|
78
|
+
@code_attr_re = /#{@attr_name}\s*=(=?)\s*/
|
|
77
79
|
end
|
|
78
80
|
|
|
79
81
|
# Compile string to Temple expression
|
|
@@ -92,10 +94,6 @@ module Slim
|
|
|
92
94
|
|
|
93
95
|
protected
|
|
94
96
|
|
|
95
|
-
ATTR_NAME = '\\A\\s*(\p{Word}(?:\p{Word}|:|-)*)'
|
|
96
|
-
QUOTED_ATTR_RE = /#{ATTR_NAME}\s*=(=?)\s*("|')/
|
|
97
|
-
CODE_ATTR_RE = /#{ATTR_NAME}\s*=(=?)\s*/
|
|
98
|
-
|
|
99
97
|
def reset(lines = nil, stacks = nil)
|
|
100
98
|
# Since you can indent however you like in Slim, we need to keep a list
|
|
101
99
|
# of how deeply indented you are. For instance, in a template like this:
|
|
@@ -235,7 +233,7 @@ module Slim
|
|
|
235
233
|
when @embedded_re
|
|
236
234
|
# Embedded template detected. It is treated as block.
|
|
237
235
|
@stacks.last << [:slim, :embedded, $1, parse_text_block($', @orig_line.size - $'.size + $2.size)]
|
|
238
|
-
when /\Adoctype\
|
|
236
|
+
when /\Adoctype\b/
|
|
239
237
|
# Found doctype declaration
|
|
240
238
|
@stacks.last << [:html, :doctype, $'.strip]
|
|
241
239
|
when @tag_re
|
|
@@ -398,7 +396,7 @@ module Slim
|
|
|
398
396
|
end
|
|
399
397
|
|
|
400
398
|
if delimiter
|
|
401
|
-
boolean_attr_re = /#{
|
|
399
|
+
boolean_attr_re = /#{@attr_name}(?=(\s|#{Regexp.escape delimiter}|\Z))/
|
|
402
400
|
end_re = /\A\s*#{Regexp.escape delimiter}/
|
|
403
401
|
end
|
|
404
402
|
|
|
@@ -408,12 +406,12 @@ module Slim
|
|
|
408
406
|
# Splat attribute
|
|
409
407
|
@line = $'
|
|
410
408
|
attributes << [:slim, :splat, parse_ruby_code(delimiter)]
|
|
411
|
-
when
|
|
409
|
+
when @quoted_attr_re
|
|
412
410
|
# Value is quoted (static)
|
|
413
411
|
@line = $'
|
|
414
412
|
attributes << [:html, :attr, $1,
|
|
415
413
|
[:escape, $2.empty?, [:slim, :interpolate, parse_quoted_attribute($3)]]]
|
|
416
|
-
when
|
|
414
|
+
when @code_attr_re
|
|
417
415
|
# Value is ruby code
|
|
418
416
|
@line = $'
|
|
419
417
|
name = $1
|
|
@@ -492,9 +490,7 @@ module Slim
|
|
|
492
490
|
end
|
|
493
491
|
end
|
|
494
492
|
|
|
495
|
-
syntax_error!("Expected closing brace }") if count != 0
|
|
496
493
|
@line.slice!(0)
|
|
497
|
-
|
|
498
494
|
value
|
|
499
495
|
end
|
|
500
496
|
|
data/lib/slim/version.rb
CHANGED
|
@@ -162,6 +162,14 @@ p id=(1 + 1)*5 Test it
|
|
|
162
162
|
assert_html '<p id="10">Test it</p>', source
|
|
163
163
|
end
|
|
164
164
|
|
|
165
|
+
def test_code_attribute_does_not_modify_argument
|
|
166
|
+
template = 'span class=attribute'
|
|
167
|
+
model = OpenStruct.new(attribute: [:a, :b, [:c, :d]])
|
|
168
|
+
output = Slim::Template.new { template }.render(model)
|
|
169
|
+
assert_equal('<span class="a b c d"></span>', output)
|
|
170
|
+
assert_equal([:a, :b, [:c, :d]], model.attribute)
|
|
171
|
+
end
|
|
172
|
+
|
|
165
173
|
def test_number_type_interpolation
|
|
166
174
|
source = %q{
|
|
167
175
|
p = output_number
|
|
@@ -256,4 +256,13 @@ p(id="marvin" class=nil nonempty=("".to_s) data-info="Illudium Q-36")= output_nu
|
|
|
256
256
|
|
|
257
257
|
assert_html '<p data-info="Illudium Q-36" id="marvin" nonempty="">1337</p>', source
|
|
258
258
|
end
|
|
259
|
+
|
|
260
|
+
def test_weird_attribute
|
|
261
|
+
source = %q{
|
|
262
|
+
p
|
|
263
|
+
img(src='img.png' whatsthis?!)
|
|
264
|
+
img src='img.png' whatsthis?!="wtf"
|
|
265
|
+
}
|
|
266
|
+
assert_html '<p><img src="img.png" whatsthis?!="" /><img src="img.png" whatsthis?!="wtf" /></p>', source
|
|
267
|
+
end
|
|
259
268
|
end
|
|
@@ -77,15 +77,6 @@ p
|
|
|
77
77
|
assert_syntax_error "Expected closing delimiter ]\n (__TEMPLATE__), Line 3, Column 28\n img src=[hash[1] + hash[2]\n ^\n", source
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
def test_expected_attribute
|
|
81
|
-
source = %q{
|
|
82
|
-
p
|
|
83
|
-
img(src='img.png' whatsthis?!)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
assert_syntax_error "Expected attribute\n (__TEMPLATE__), Line 3, Column 20\n img(src='img.png' whatsthis?!)\n ^\n", source
|
|
87
|
-
end
|
|
88
|
-
|
|
89
80
|
def test_invalid_empty_attribute
|
|
90
81
|
source = %q{
|
|
91
82
|
p
|
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.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Mendler
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2014-12-
|
|
13
|
+
date: 2014-12-22 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: temple
|
|
@@ -201,4 +201,3 @@ signing_key:
|
|
|
201
201
|
specification_version: 4
|
|
202
202
|
summary: Slim is a template language.
|
|
203
203
|
test_files: []
|
|
204
|
-
has_rdoc:
|