slim 3.0.9 → 4.0.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 +5 -5
- data/.travis.yml +15 -41
- data/CHANGES +9 -0
- data/Gemfile +11 -16
- data/README.jp.md +27 -11
- data/README.md +25 -9
- data/benchmarks/view.erb +4 -2
- data/benchmarks/view.haml +3 -1
- data/benchmarks/view.slim +3 -1
- data/lib/slim/embedded.rb +20 -45
- data/lib/slim/grammar.rb +8 -5
- data/lib/slim/parser.rb +16 -9
- data/lib/slim/splat/builder.rb +1 -1
- data/lib/slim/version.rb +1 -1
- data/slim.gemspec +1 -1
- data/test/core/test_code_blocks.rb +11 -0
- data/test/core/test_code_output.rb +4 -4
- data/test/core/test_commands.rb +4 -4
- data/test/core/test_embedded_engines.rb +79 -78
- data/test/core/test_html_attributes.rb +26 -1
- data/test/core/test_ruby_errors.rb +2 -28
- data/test/rails/config/application.rb +16 -0
- data/test/rails/test/helper.rb +3 -0
- data/test/rails/test/test_slim.rb +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b6aa24cf9ce985085cb2c3f4d43b948aba03bc19afbf165c090f4e4f63497cb6
|
4
|
+
data.tar.gz: 23c6a1e7778c9feca0c85a2e5eee90e8019e008c4bbb58b533be2ad2733a9a41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e799d123737fd44fd02e9bb889dac596bdea8093db6395759908565325a3670a142589820e534b248d23751ea3de51694723392827ed4fe56b4867abfa4f306f
|
7
|
+
data.tar.gz: '031793ed5801a279b8de180b2058357b3ce35c413b3152dfb6cf30220a574c405ad712aa6d26fbdebb1b27eecc731657bd32001efdf1bf310eef041c1001666f'
|
data/.travis.yml
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
+
# https://www.ruby-lang.org/en/downloads/releases/
|
1
2
|
language: ruby
|
2
|
-
|
3
3
|
rvm:
|
4
|
-
-
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
-
- 2.
|
8
|
-
- 2.0.0
|
9
|
-
-
|
10
|
-
- jruby-head
|
11
|
-
- jruby-19mode
|
4
|
+
- 2.5.1
|
5
|
+
- 2.5.0
|
6
|
+
- 2.4.4
|
7
|
+
- 2.4.3
|
8
|
+
- jruby-9.2.0.0
|
9
|
+
- jruby-9.1.17.0
|
12
10
|
|
13
|
-
sudo
|
11
|
+
# Recommend sudo required when using trusty dist
|
12
|
+
# https://docs.travis-ci.com/user/reference/trusty/
|
13
|
+
sudo: required
|
14
14
|
dist: trusty
|
15
15
|
|
16
16
|
script: "bundle exec rake $TASK"
|
@@ -23,39 +23,13 @@ env:
|
|
23
23
|
# travis encrypt CODECLIMATE_REPO_TOKEN=???
|
24
24
|
- secure: "a7sD9iwPJJn3Fj+mn62GAmy/PEguh3elrilsp1KS+WfDiCiIKD8Q5KG2Jv67DGcQAGI3dPWeh7+ZhZ/W7nEipwWUBmSvGYVeoF63y8j6mNRLeekqspj94l47hXyFePj9bCadY1b1/xY4lE1pMEU8eA8AOUHUqCSuH+Kk/MuvyLM="
|
25
25
|
matrix:
|
26
|
-
- "TASK=test:core_and_plugins
|
27
|
-
- "TASK=test:
|
28
|
-
- "TASK=test:
|
29
|
-
- "TASK=test:
|
30
|
-
- "TASK=test:
|
31
|
-
- "TASK=test:rails RAILS=3.1.12 TILT=1.3.4"
|
32
|
-
- "TASK=test:rails RAILS=3.2.21 TILT=1.3.4"
|
33
|
-
- "TASK=test:rails RAILS=4.0.13"
|
34
|
-
- "TASK=test:rails RAILS=4.1.10"
|
35
|
-
- "TASK=test:rails RAILS=4.2.1"
|
36
|
-
- "TASK=test:sinatra SINATRA=master"
|
37
|
-
- "TASK=test:sinatra SINATRA=1.3.6"
|
38
|
-
- "TASK=test:sinatra SINATRA=1.4.6"
|
26
|
+
- "TASK=test:core_and_plugins"
|
27
|
+
- "TASK=test:rails RAILS=5.2.0"
|
28
|
+
- "TASK=test:rails RAILS=5.1.6"
|
29
|
+
- "TASK=test:sinatra SINATRA=2.0.1"
|
30
|
+
- "TASK=test:sinatra SINATRA=1.4.8"
|
39
31
|
- "TASK=bench"
|
40
32
|
- "TASK=bench slow=1"
|
41
33
|
|
42
|
-
matrix:
|
43
|
-
exclude:
|
44
|
-
- rvm: rbx-3
|
45
|
-
env: "TASK=test:rails RAILS=master"
|
46
|
-
- rvm: 2.0.0
|
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"
|
52
|
-
allow_failures:
|
53
|
-
- env: "TASK=test:core_and_plugins TILT=master"
|
54
|
-
- env: "TASK=test:rails RAILS=master"
|
55
|
-
- env: "TASK=test:sinatra SINATRA=master"
|
56
|
-
- rvm: ruby-head
|
57
|
-
- rvm: jruby-19mode
|
58
|
-
- rvm: jruby-head
|
59
|
-
|
60
34
|
notifications:
|
61
35
|
irc: "chat.freenode.net#slim-lang"
|
data/CHANGES
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
4.0.0 (2018-08-26)
|
2
|
+
* Add ability to specify attributes for embedded engines using TagEngine - #653
|
3
|
+
* Set Tilt's default encoding to utf-8 - #800
|
4
|
+
* Prevent generation of invalid Ruby code in heredoc - #770
|
5
|
+
* Don't convert underscores to dashes on data attributes - #807 [Backward incompatible]
|
6
|
+
* Update description in README.jp.md - #795
|
7
|
+
* Removed support for embedded engines: Asciidoc, Builder, Creole, Erb, Nokogiri, Opal, Org-Ruby, Styl, Wikicloth
|
8
|
+
* Fix tests
|
9
|
+
|
1
10
|
3.0.9 (2017-11-09)
|
2
11
|
|
3
12
|
* Fixed Cross-site Scripting in splat attributes names (See #767)
|
data/Gemfile
CHANGED
@@ -2,13 +2,17 @@ source 'https://rubygems.org/'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
if ENV['TRAVIS']
|
6
|
-
gem '
|
5
|
+
if ENV['TRAVIS']
|
6
|
+
gem 'rails-controller-testing'
|
7
|
+
end
|
8
|
+
|
9
|
+
if ENV['TEMPLE'] == 'master'
|
10
|
+
gem 'temple', :github => 'judofyr/temple'
|
7
11
|
end
|
8
12
|
|
9
13
|
if ENV['TILT']
|
10
14
|
if ENV['TILT'] == 'master'
|
11
|
-
gem 'tilt', github
|
15
|
+
gem 'tilt', :github => 'rtomayko/tilt'
|
12
16
|
else
|
13
17
|
gem 'tilt', "= #{ENV['TILT']}"
|
14
18
|
end
|
@@ -16,14 +20,8 @@ end
|
|
16
20
|
|
17
21
|
if ENV['RAILS']
|
18
22
|
# we need some smarter test logic for the different Rails versions
|
19
|
-
if RUBY_VERSION >= '2.1.0'
|
20
|
-
gem 'nokogiri'
|
21
|
-
else
|
22
|
-
gem 'nokogiri', '~> 1.6.8'
|
23
|
-
end
|
24
|
-
|
25
23
|
if ENV['RAILS'] == 'master'
|
26
|
-
gem 'rails', github
|
24
|
+
gem 'rails', :github => 'rails/rails'
|
27
25
|
else
|
28
26
|
gem 'rails', "= #{ENV['RAILS']}"
|
29
27
|
end
|
@@ -48,19 +46,16 @@ end
|
|
48
46
|
if ENV['SINATRA']
|
49
47
|
gem 'rack-test'
|
50
48
|
if ENV['SINATRA'] == 'master'
|
51
|
-
gem 'sinatra', github
|
49
|
+
gem 'sinatra', :github => 'sinatra/sinatra'
|
52
50
|
else
|
53
|
-
|
51
|
+
# Need the slim_test.rb file not included in the Sinatra gem.
|
52
|
+
gem 'sinatra', :github => 'sinatra/sinatra', :tag => "v#{ENV['SINATRA']}"
|
54
53
|
end
|
55
54
|
end
|
56
55
|
|
57
56
|
gem 'rake', '>= 0.8.7'
|
58
57
|
gem 'sass', '>= 3.1.0'
|
59
58
|
gem 'kramdown'
|
60
|
-
gem 'creole'
|
61
|
-
gem 'builder'
|
62
|
-
gem 'asciidoctor'
|
63
|
-
gem 'org-ruby'
|
64
59
|
|
65
60
|
if ENV['TASK'] == 'bench'
|
66
61
|
gem 'benchmark-ips'
|
data/README.jp.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Slim
|
2
2
|
|
3
|
-
[](http://rubygems.org/gems/slim) [](http://travis-ci.org/slim-template/slim) [](http://rubygems.org/gems/slim) [](http://travis-ci.org/slim-template/slim) [](https://codeclimate.com/github/slim-template/slim) [](https://codeclimate.com/github/slim-template/slim/coverage)
|
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 は 不可解にならない程度に view の構文を本質的な部品まで減らすことを目指したテンプレート言語です。標準的な HTML テンプレートからどれだけのものを減らせるか、検証するところから始まりました。(<, >, 閉じタグなど) 多くの人が Slim に興味を持ったことで, 機能的で柔軟な構文に成長しました。
|
@@ -40,7 +40,7 @@ Slim は 不可解にならない程度に view の構文を本質的な部品
|
|
40
40
|
|
41
41
|
### Slim とは?
|
42
42
|
|
43
|
-
Slim は __Rails3
|
43
|
+
Slim は __Rails3 以降__ に対応した高速, 軽量なテンプレートエンジンです。主要な Ruby の実装全てでしっかりテストされています。
|
44
44
|
私たちは継続的インテグレーションを採用しています。(travis-ci)
|
45
45
|
|
46
46
|
Slim の核となる構文は1つの考えによって導かれています: "この動作を行うために最低限必要なものは何か。"
|
@@ -118,8 +118,7 @@ html
|
|
118
118
|
|
119
119
|
### テキスト `|`
|
120
120
|
|
121
|
-
パイプを使うと, Slim
|
122
|
-
パイプよりも深くインデントされた全ての行がコピーされます。
|
121
|
+
パイプを使うと, Slim はパイプよりも深くインデントされた全ての行をコピーします。行中の処理は基本的にどのようなものでもエスケープされます。
|
123
122
|
|
124
123
|
~~~ slim
|
125
124
|
body
|
@@ -869,17 +868,10 @@ p: markdown: Tag with **inline** markdown!
|
|
869
868
|
| sass: | sass | コンパイル時 | sass コードを埋め込み、style タグで囲む |
|
870
869
|
| scss: | sass | コンパイル時 | scss コードを埋め込み、style タグで囲む |
|
871
870
|
| less: | less | コンパイル時 | less コードを埋め込み、style タグで囲む |
|
872
|
-
| styl: | styl | コンパイル時 | stylus コードを埋め込み、 style タグで囲む |
|
873
871
|
| coffee: | coffee-script | コンパイル時 | CoffeeScript をコンパイルし、 script タグで囲む |
|
874
|
-
| asciidoc: | asciidoctor | コンパイル時 + 展開 | AsciiDoc をコンパイルし、テキスト中の # \{variables} を展開 |
|
875
872
|
| markdown: | redcarpet/rdiscount/kramdown | コンパイル時 + 展開 | Markdown をコンパイルし、テキスト中の # \{variables} を展開 |
|
876
873
|
| textile: | redcloth | コンパイル時 + 展開 | textile をコンパイルし、テキスト中の # \{variables} を展開 |
|
877
|
-
| creole: | creole | コンパイル時 + 展開 | cleole をコンパイルし、テキスト中の # \{variables} を展開 |
|
878
|
-
| wiki:, mediawiki: | wikicloth | コンパイル時 + 展開 | wiki をコンパイルし、テキスト中の # \{variables} を展開 |
|
879
874
|
| rdoc: | rdoc | コンパイル時 + 展開 | RDoc をコンパイルし、テキスト中の # \{variables} を展開 |
|
880
|
-
| builder: | builder | プレコンパイル | builder コードの埋め込み |
|
881
|
-
| nokogiri: | nokogiri | プレコンパイル | nokogiri コードの埋め込み |
|
882
|
-
| erb: | なし | プレコンパイル | erb コードの埋め込み |
|
883
875
|
|
884
876
|
埋め込みエンジンは Slim の `Slim::Embedded` フィルタのオプションで直接設定されます。例:
|
885
877
|
|
@@ -887,6 +879,29 @@ p: markdown: Tag with **inline** markdown!
|
|
887
879
|
Slim::Embedded.options[:markdown] = {auto_ids: false}
|
888
880
|
~~~
|
889
881
|
|
882
|
+
以下埋め込みエンジンの場合はHTMLのattributeも指定できます:
|
883
|
+
|
884
|
+
* Javascript
|
885
|
+
* CSS
|
886
|
+
* CoffeeScript
|
887
|
+
* LESS
|
888
|
+
* SASS
|
889
|
+
* SCSS
|
890
|
+
|
891
|
+
例:
|
892
|
+
|
893
|
+
~~~ scss
|
894
|
+
scss class="myClass":
|
895
|
+
$color: #f00;
|
896
|
+
body { color: $color; }
|
897
|
+
~~~
|
898
|
+
|
899
|
+
レンダリング結果:
|
900
|
+
|
901
|
+
~~~ html
|
902
|
+
<style class="myClass" type="text/css">body{color:red}</style>
|
903
|
+
~~~
|
904
|
+
|
890
905
|
## Slim の設定
|
891
906
|
|
892
907
|
Slim とその基礎となる [Temple](https://github.com/judofyr/temple) は非常に柔軟に設定可能です。
|
@@ -1271,3 +1286,4 @@ Slim は [MIT license](http://www.opensource.org/licenses/MIT) に基づいて
|
|
1271
1286
|
* [Pug (Successor of Jade, Similar engine for javascript)](https://github.com/pugjs/pug)
|
1272
1287
|
* [Sweet (Similar engine which also allows to write classes and functions)](https://github.com/joaomdmoura/sweet)
|
1273
1288
|
* [Amber (Similar engine for Go)](https://github.com/eknkc/amber)
|
1289
|
+
* [Slang (Slim-inspired templating language for Crystal)](https://github.com/jeromegn/slang)
|
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) [](http://rubygems.org/gems/slim) [](http://travis-ci.org/slim-template/slim) [](https://codeclimate.com/github/slim-template/slim) [](https://codeclimate.com/github/slim-template/slim/coverage)
|
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.
|
@@ -40,7 +40,7 @@ A short list of the features...
|
|
40
40
|
|
41
41
|
### What is Slim?
|
42
42
|
|
43
|
-
Slim is a fast, lightweight templating engine with support for __Rails 3 and
|
43
|
+
Slim is a fast, lightweight templating engine with support for __Rails 3 and later__. It has been heavily tested on all major ruby implementations. We use
|
44
44
|
continuous integration (travis-ci).
|
45
45
|
|
46
46
|
Slim's core syntax is guided by one thought: "What's the minimum required to make this work".
|
@@ -869,17 +869,10 @@ Supported engines:
|
|
869
869
|
| sass: | sass | Compile time | Embed sass code and wrap in style tag |
|
870
870
|
| scss: | sass | Compile time | Embed scss code and wrap in style tag |
|
871
871
|
| less: | less | Compile time | Embed less css code and wrap in style tag |
|
872
|
-
| styl: | styl | Compile time | Embed stylus css code and wrap in style tag |
|
873
872
|
| coffee: | coffee-script | Compile time | Compile coffee script code and wrap in script tag |
|
874
|
-
| asciidoc: | asciidoctor | Compile time + Interpolation | Compile AsciiDoc code and interpolate #\{variables} in text |
|
875
873
|
| markdown: | redcarpet/rdiscount/kramdown | Compile time + Interpolation | Compile markdown code and interpolate #\{variables} in text |
|
876
874
|
| textile: | redcloth | Compile time + Interpolation | Compile textile code and interpolate #\{variables} in text |
|
877
|
-
| creole: | creole | Compile time + Interpolation | Compile creole code and interpolate #\{variables} in text |
|
878
|
-
| wiki:, mediawiki: | wikicloth | Compile time + Interpolation | Compile wiki code and interpolate #\{variables} in text |
|
879
875
|
| rdoc: | rdoc | Compile time + Interpolation | Compile rdoc code and interpolate #\{variables} in text |
|
880
|
-
| builder: | builder | Precompiled | Embed builder code |
|
881
|
-
| nokogiri: | nokogiri | Precompiled | Embed nokogiri builder code |
|
882
|
-
| erb: | none | Precompiled | Embed erb code |
|
883
876
|
|
884
877
|
The embedded engines can be configured in Slim by setting the options directly on the `Slim::Embedded` filter. Example:
|
885
878
|
|
@@ -887,6 +880,28 @@ The embedded engines can be configured in Slim by setting the options directly o
|
|
887
880
|
Slim::Embedded.options[:markdown] = {auto_ids: false}
|
888
881
|
~~~
|
889
882
|
|
883
|
+
You can also specify HTML attributes for the following embedded engines:
|
884
|
+
* Javascript
|
885
|
+
* CSS
|
886
|
+
* CoffeeScript
|
887
|
+
* LESS
|
888
|
+
* SASS
|
889
|
+
* SCSS
|
890
|
+
|
891
|
+
Example:
|
892
|
+
|
893
|
+
~~~ scss
|
894
|
+
scss class="myClass":
|
895
|
+
$color: #f00;
|
896
|
+
body { color: $color; }
|
897
|
+
~~~
|
898
|
+
|
899
|
+
This will generate the following HTML:
|
900
|
+
|
901
|
+
~~~ html
|
902
|
+
<style class="myClass" type="text/css">body{color:red}</style>
|
903
|
+
~~~
|
904
|
+
|
890
905
|
## Configuring Slim
|
891
906
|
|
892
907
|
Slim and the underlying [Temple](https://github.com/judofyr/temple) framework are highly configurable.
|
@@ -1271,3 +1286,4 @@ Language ports/Similar languages:
|
|
1271
1286
|
* [Pug (Successor of Jade, Similar engine for javascript)](https://github.com/pugjs/pug)
|
1272
1287
|
* [Sweet (Similar engine which also allows to write classes and functions)](https://github.com/joaomdmoura/sweet)
|
1273
1288
|
* [Amber (Similar engine for Go)](https://github.com/eknkc/amber)
|
1289
|
+
* [Slang (Slim-inspired templating language for Crystal)](https://github.com/jeromegn/slang)
|
data/benchmarks/view.erb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
<!DOCTYPE HTML>
|
2
2
|
|
3
|
-
<html>
|
3
|
+
<html lang="en">
|
4
4
|
<head>
|
5
5
|
<title>Simple Benchmark</title>
|
6
|
+
<meta charset="utf-8">
|
7
|
+
<meta name="description" content="This is an example of a meta description.">
|
6
8
|
</head>
|
7
9
|
<body>
|
8
10
|
<h1><%= header %></h1>
|
@@ -20,4 +22,4 @@
|
|
20
22
|
<p>The list is empty.</p>
|
21
23
|
<% end %>
|
22
24
|
</body>
|
23
|
-
</html>
|
25
|
+
</html>
|
data/benchmarks/view.haml
CHANGED
data/benchmarks/view.slim
CHANGED
data/lib/slim/embedded.rb
CHANGED
@@ -96,11 +96,11 @@ module Slim
|
|
96
96
|
@disabled = normalize_engine_list(options[:disable_engines])
|
97
97
|
end
|
98
98
|
|
99
|
-
def on_slim_embedded(name, body)
|
99
|
+
def on_slim_embedded(name, body, attrs)
|
100
100
|
name = name.to_sym
|
101
101
|
raise(Temple::FilterError, "Embedded engine #{name} is disabled") unless enabled?(name)
|
102
102
|
@engines[name] ||= self.class.create(name, options)
|
103
|
-
@engines[name].on_slim_embedded(name, body)
|
103
|
+
@engines[name].on_slim_embedded(name, body, attrs)
|
104
104
|
end
|
105
105
|
|
106
106
|
def enabled?(name)
|
@@ -131,9 +131,10 @@ module Slim
|
|
131
131
|
|
132
132
|
# Basic tilt engine
|
133
133
|
class TiltEngine < Engine
|
134
|
-
def on_slim_embedded(engine, body)
|
134
|
+
def on_slim_embedded(engine, body, attrs)
|
135
135
|
tilt_engine = Tilt[engine] || raise(Temple::FilterError, "Tilt engine #{engine} is not available.")
|
136
136
|
tilt_options = options[engine.to_sym] || {}
|
137
|
+
tilt_options[:default_encoding] ||= 'utf-8'
|
137
138
|
[:multi, tilt_render(tilt_engine, tilt_options, collect_text(body)), collect_newlines(body)]
|
138
139
|
end
|
139
140
|
|
@@ -159,16 +160,6 @@ module Slim
|
|
159
160
|
end
|
160
161
|
end
|
161
162
|
|
162
|
-
# Tilt-based engine which is precompiled
|
163
|
-
class PrecompiledTiltEngine < TiltEngine
|
164
|
-
protected
|
165
|
-
|
166
|
-
def tilt_render(tilt_engine, tilt_options, text)
|
167
|
-
# HACK: Tilt::Engine#precompiled is protected
|
168
|
-
[:dynamic, tilt_engine.new(tilt_options) { text }.send(:precompiled, {}).first]
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
163
|
# Static template with interpolated ruby code
|
173
164
|
class InterpolateTiltEngine < TiltEngine
|
174
165
|
def collect_text(body)
|
@@ -190,35 +181,31 @@ module Slim
|
|
190
181
|
end
|
191
182
|
end
|
192
183
|
|
193
|
-
# ERB engine (uses the Temple ERB implementation)
|
194
|
-
class ERBEngine < Engine
|
195
|
-
def on_slim_embedded(engine, body)
|
196
|
-
[:multi, [:newline], erb_parser.call(collect_text(body))]
|
197
|
-
end
|
198
|
-
|
199
|
-
protected
|
200
|
-
|
201
|
-
def erb_parser
|
202
|
-
@erb_parser ||= Temple::ERB::Parser.new
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
184
|
# Tag wrapper engine
|
207
185
|
# Generates a html tag and wraps another engine (specified via :engine option)
|
208
186
|
class TagEngine < Engine
|
209
187
|
disable_option_validator!
|
210
188
|
|
211
|
-
def on_slim_embedded(engine, body)
|
189
|
+
def on_slim_embedded(engine, body, attrs)
|
190
|
+
|
191
|
+
unless options[:attributes].empty?
|
192
|
+
options[:attributes].map do|k, v|
|
193
|
+
attrs << [:html, :attr, k, [:static, v]]
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
212
197
|
if options[:engine]
|
213
198
|
opts = {}.update(options)
|
214
199
|
opts.delete(:engine)
|
215
200
|
opts.delete(:tag)
|
216
201
|
opts.delete(:attributes)
|
217
202
|
@engine ||= options[:engine].new(opts)
|
218
|
-
body = @engine.on_slim_embedded(engine, body)
|
203
|
+
body = @engine.on_slim_embedded(engine, body, attrs)
|
219
204
|
end
|
220
|
-
|
205
|
+
|
206
|
+
[:html, :tag, options[:tag], attrs, body]
|
221
207
|
end
|
208
|
+
|
222
209
|
end
|
223
210
|
|
224
211
|
# Javascript wrapper engine.
|
@@ -228,41 +215,29 @@ module Slim
|
|
228
215
|
|
229
216
|
set_options tag: :script, attributes: {}
|
230
217
|
|
231
|
-
def on_slim_embedded(engine, body)
|
232
|
-
super(engine, [:html, :js, body])
|
218
|
+
def on_slim_embedded(engine, body, attrs)
|
219
|
+
super(engine, [:html, :js, body], attrs)
|
233
220
|
end
|
234
221
|
end
|
235
222
|
|
236
223
|
# Embeds ruby code
|
237
224
|
class RubyEngine < Engine
|
238
|
-
def on_slim_embedded(engine, body)
|
239
|
-
[:multi, [:newline], [:code, collect_text(body)]]
|
225
|
+
def on_slim_embedded(engine, body, attrs)
|
226
|
+
[:multi, [:newline], [:code, "#{collect_text(body)}\n"]]
|
240
227
|
end
|
241
228
|
end
|
242
229
|
|
243
230
|
# These engines are executed at compile time, embedded ruby is interpolated
|
244
|
-
register :asciidoc, InterpolateTiltEngine
|
245
231
|
register :markdown, InterpolateTiltEngine
|
246
232
|
register :textile, InterpolateTiltEngine
|
247
233
|
register :rdoc, InterpolateTiltEngine
|
248
|
-
register :creole, InterpolateTiltEngine
|
249
|
-
register :wiki, InterpolateTiltEngine
|
250
|
-
register :mediawiki, InterpolateTiltEngine
|
251
|
-
register :org, InterpolateTiltEngine
|
252
234
|
|
253
235
|
# These engines are executed at compile time
|
254
236
|
register :coffee, JavaScriptEngine, engine: TiltEngine
|
255
|
-
register :opal, JavaScriptEngine, engine: TiltEngine
|
256
237
|
register :less, TagEngine, tag: :style, attributes: { type: 'text/css' }, engine: TiltEngine
|
257
|
-
register :styl, TagEngine, tag: :style, attributes: { type: 'text/css' }, engine: TiltEngine
|
258
238
|
register :sass, TagEngine, :pretty, tag: :style, attributes: { type: 'text/css' }, engine: SassEngine
|
259
239
|
register :scss, TagEngine, :pretty, tag: :style, attributes: { type: 'text/css' }, engine: SassEngine
|
260
240
|
|
261
|
-
# These engines are precompiled, code is embedded
|
262
|
-
register :erb, ERBEngine
|
263
|
-
register :nokogiri, PrecompiledTiltEngine
|
264
|
-
register :builder, PrecompiledTiltEngine
|
265
|
-
|
266
241
|
# Embedded javascript/css
|
267
242
|
register :javascript, JavaScriptEngine
|
268
243
|
register :css, TagEngine, tag: :style, attributes: { type: 'text/css' }
|
data/lib/slim/grammar.rb
CHANGED
@@ -7,14 +7,17 @@ module Slim
|
|
7
7
|
TextTypes << :verbatim | :explicit | :implicit | :inline
|
8
8
|
|
9
9
|
Expression <<
|
10
|
-
[:slim, :control, String, Expression]
|
11
|
-
[:slim, :output, Bool, String, Expression]
|
12
|
-
[:slim, :interpolate, String]
|
13
|
-
[:slim, :embedded, String, Expression]
|
14
|
-
[:slim, :text, TextTypes, Expression]
|
10
|
+
[:slim, :control, String, Expression] |
|
11
|
+
[:slim, :output, Bool, String, Expression] |
|
12
|
+
[:slim, :interpolate, String] |
|
13
|
+
[:slim, :embedded, String, Expression, HTMLAttrGroup] |
|
14
|
+
[:slim, :text, TextTypes, Expression] |
|
15
15
|
[:slim, :attrvalue, Bool, String]
|
16
16
|
|
17
17
|
HTMLAttr <<
|
18
18
|
[:slim, :splat, String]
|
19
|
+
|
20
|
+
HTMLAttrGroup <<
|
21
|
+
[:html, :attrs, 'HTMLAttr*']
|
19
22
|
end
|
20
23
|
end
|
data/lib/slim/parser.rb
CHANGED
@@ -77,11 +77,15 @@ module Slim
|
|
77
77
|
@code_attr_delims_re = /\A[#{keys}]/
|
78
78
|
keys = Regexp.escape @attr_list_delims.keys.join
|
79
79
|
@attr_list_delims_re = /\A\s*([#{keys}])/
|
80
|
-
@embedded_re = /\A(#{Regexp.union(Embedded.engines.keys.map(&:to_s))})
|
80
|
+
@embedded_re = /\A(#{Regexp.union(Embedded.engines.keys.map(&:to_s))})(?:\s*(?:(.*)))?:(\s*)/
|
81
81
|
keys = Regexp.escape ('"\'></='.split(//) + @attr_list_delims.flatten + @code_attr_delims.flatten).uniq.join
|
82
82
|
@attr_name = "\\A\\s*([^\0\s#{keys}]+)"
|
83
83
|
@quoted_attr_re = /#{@attr_name}\s*=(=?)\s*("|')/
|
84
84
|
@code_attr_re = /#{@attr_name}\s*=(=?)\s*/
|
85
|
+
|
86
|
+
splat_prefix = Regexp.escape(options[:splat_prefix])
|
87
|
+
splat_regexp_source = '\A\s*' << splat_prefix << '(?=[^\s]+)'
|
88
|
+
@splat_attrs_regexp = Regexp.new(splat_regexp_source)
|
85
89
|
end
|
86
90
|
|
87
91
|
# Compile string to Temple expression
|
@@ -180,7 +184,7 @@ module Slim
|
|
180
184
|
@stacks.pop
|
181
185
|
end
|
182
186
|
|
183
|
-
# This line's indentation happens lie "between" two other line's
|
187
|
+
# This line's indentation happens to lie "between" two other line's
|
184
188
|
# indentation:
|
185
189
|
#
|
186
190
|
# hello
|
@@ -238,7 +242,9 @@ module Slim
|
|
238
242
|
@stacks << block
|
239
243
|
when @embedded_re
|
240
244
|
# Embedded template detected. It is treated as block.
|
241
|
-
@
|
245
|
+
@line = $2
|
246
|
+
attrs = parse_attributes
|
247
|
+
@stacks.last << [:slim, :embedded, $1, parse_text_block($', @orig_line.size - $'.size + $2.size), attrs]
|
242
248
|
when /\Adoctype\b/
|
243
249
|
# Found doctype declaration
|
244
250
|
@stacks.last << [:html, :doctype, $'.strip]
|
@@ -362,7 +368,11 @@ module Slim
|
|
362
368
|
# Block expansion
|
363
369
|
@line = $'
|
364
370
|
if @line =~ @embedded_re
|
365
|
-
|
371
|
+
|
372
|
+
# Parse attributes
|
373
|
+
@line = $2
|
374
|
+
attrs = parse_attributes
|
375
|
+
tag << [:slim, :embedded, $1, parse_text_block($', @orig_line.size - $'.size + $2.size), attrs]
|
366
376
|
else
|
367
377
|
(@line =~ @tag_re) || syntax_error!('Expected tag')
|
368
378
|
@line = $' if $1
|
@@ -401,7 +411,7 @@ module Slim
|
|
401
411
|
end
|
402
412
|
end
|
403
413
|
|
404
|
-
def parse_attributes(attributes)
|
414
|
+
def parse_attributes(attributes = [:html, :attrs])
|
405
415
|
# Check to see if there is a delimiter right after the tag name
|
406
416
|
delimiter = nil
|
407
417
|
if @line =~ @attr_list_delims_re
|
@@ -414,10 +424,6 @@ module Slim
|
|
414
424
|
end_re = /\A\s*#{Regexp.escape delimiter}/
|
415
425
|
end
|
416
426
|
|
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
|
-
|
421
427
|
while true
|
422
428
|
case @line
|
423
429
|
when @splat_attrs_regexp
|
@@ -461,6 +467,7 @@ module Slim
|
|
461
467
|
end
|
462
468
|
end
|
463
469
|
end
|
470
|
+
attributes || [:html, :attrs]
|
464
471
|
end
|
465
472
|
|
466
473
|
def parse_ruby_code(outer_delimiter)
|
data/lib/slim/splat/builder.rb
CHANGED
@@ -91,7 +91,7 @@ module Slim
|
|
91
91
|
def hyphen_attr(name, escape, value)
|
92
92
|
if Hash === value
|
93
93
|
value.each do |n, v|
|
94
|
-
hyphen_attr("#{name}-#{n
|
94
|
+
hyphen_attr("#{name}-#{n}", escape, v)
|
95
95
|
end
|
96
96
|
else
|
97
97
|
attr(name, escape_html(value != true && escape, value))
|
data/lib/slim/version.rb
CHANGED
data/slim.gemspec
CHANGED
@@ -180,4 +180,15 @@ p
|
|
180
180
|
}
|
181
181
|
assert_html '', source
|
182
182
|
end
|
183
|
+
|
184
|
+
def test_output_format_with_if
|
185
|
+
source = %q{
|
186
|
+
h3.subtitle
|
187
|
+
- if true
|
188
|
+
a href="#" Title true
|
189
|
+
- else
|
190
|
+
a href="#" Title false
|
191
|
+
}
|
192
|
+
assert_html '<h3 class="subtitle"><a href="#">Title true</a></h3>', source
|
193
|
+
end
|
183
194
|
end
|
@@ -13,7 +13,7 @@ p
|
|
13
13
|
def test_render_with_trailing_whitespace
|
14
14
|
source = %q{
|
15
15
|
p
|
16
|
-
|
16
|
+
=> hello_world
|
17
17
|
}
|
18
18
|
|
19
19
|
assert_html '<p>Hello World from @env </p>', source
|
@@ -21,7 +21,7 @@ p
|
|
21
21
|
|
22
22
|
def test_render_with_trailing_whitespace_after_tag
|
23
23
|
source = %q{
|
24
|
-
p
|
24
|
+
p=> hello_world
|
25
25
|
}
|
26
26
|
|
27
27
|
assert_html '<p>Hello World from @env</p> ', source
|
@@ -30,7 +30,7 @@ p=' hello_world
|
|
30
30
|
def test_no_escape_render_with_trailing_whitespace
|
31
31
|
source = %q{
|
32
32
|
p
|
33
|
-
|
33
|
+
==> hello_world
|
34
34
|
}
|
35
35
|
|
36
36
|
assert_html '<p>Hello World from @env </p>', source
|
@@ -38,7 +38,7 @@ p
|
|
38
38
|
|
39
39
|
def test_no_escape_render_with_trailing_whitespace_after_tag
|
40
40
|
source = %q{
|
41
|
-
p
|
41
|
+
p==> hello_world
|
42
42
|
}
|
43
43
|
|
44
44
|
assert_html '<p>Hello World from @env</p> ', source
|
data/test/core/test_commands.rb
CHANGED
@@ -146,7 +146,7 @@ private
|
|
146
146
|
|
147
147
|
# case 1. $stdin → $stdout
|
148
148
|
unless options[:stdin_stdout] == false
|
149
|
-
out, err = exec_slimrb
|
149
|
+
out, err = exec_slimrb(*args, '--stdin') do |i|
|
150
150
|
i.write content
|
151
151
|
end
|
152
152
|
yield out, err
|
@@ -155,7 +155,7 @@ private
|
|
155
155
|
# case 2. file → $stdout
|
156
156
|
unless options[:file_stdout] == false
|
157
157
|
with_tempfile content do |in_file|
|
158
|
-
out, err = exec_slimrb
|
158
|
+
out, err = exec_slimrb(*args, in_file)
|
159
159
|
yield out, err
|
160
160
|
end
|
161
161
|
end
|
@@ -163,7 +163,7 @@ private
|
|
163
163
|
# case 3. $stdin → file
|
164
164
|
unless options[:stdin_file] == false
|
165
165
|
with_tempfile content do |out_file|
|
166
|
-
_, err = exec_slimrb
|
166
|
+
_, err = exec_slimrb(*args, '--stdin', out_file) do |i|
|
167
167
|
i.write content
|
168
168
|
end
|
169
169
|
yield File.read(out_file), err
|
@@ -174,7 +174,7 @@ private
|
|
174
174
|
unless options[:file_file] == false
|
175
175
|
with_tempfile '' do |out_file|
|
176
176
|
with_tempfile content do |in_file|
|
177
|
-
_, err = exec_slimrb
|
177
|
+
_, err = exec_slimrb(*args, in_file, out_file) do |i|
|
178
178
|
i.write content
|
179
179
|
end
|
180
180
|
yield File.read(out_file), err
|
@@ -1,35 +1,7 @@
|
|
1
1
|
require 'helper'
|
2
|
-
require 'erb'
|
2
|
+
require 'erb'
|
3
3
|
|
4
4
|
class TestSlimEmbeddedEngines < TestSlim
|
5
|
-
def test_render_with_erb
|
6
|
-
source = %q{
|
7
|
-
p
|
8
|
-
- text = 'before erb block'
|
9
|
-
erb:
|
10
|
-
<b>Hello from <%= text.upcase %>!</b>
|
11
|
-
Second Line!
|
12
|
-
<% if true %><%= true %><% end %>
|
13
|
-
}
|
14
|
-
|
15
|
-
assert_html "<p><b>Hello from BEFORE ERB BLOCK!</b>\nSecond Line!\ntrue</p>", source
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_wip_render_with_asciidoc
|
19
|
-
source = %q{
|
20
|
-
asciidoc:
|
21
|
-
== Header
|
22
|
-
Hello from #{"AsciiDoc!"}
|
23
|
-
|
24
|
-
#{1+2}
|
25
|
-
|
26
|
-
* one
|
27
|
-
* two
|
28
|
-
}
|
29
|
-
output = render(source)
|
30
|
-
assert_match 'sect1', output
|
31
|
-
assert_match 'Hello from AsciiDoc!', output
|
32
|
-
end
|
33
5
|
|
34
6
|
def test_render_with_markdown
|
35
7
|
source = %q{
|
@@ -60,61 +32,41 @@ markdown:
|
|
60
32
|
end
|
61
33
|
end
|
62
34
|
|
63
|
-
def
|
35
|
+
def test_render_with_css
|
64
36
|
source = %q{
|
65
|
-
|
66
|
-
|
67
|
-
== head2
|
37
|
+
css:
|
38
|
+
h1 { color: blue }
|
68
39
|
}
|
69
|
-
|
40
|
+
assert_html "<style type=\"text/css\">h1 { color: blue }</style>", source
|
70
41
|
end
|
71
42
|
|
72
|
-
def
|
43
|
+
def test_render_with_css_empty_attributes
|
73
44
|
source = %q{
|
74
|
-
|
75
|
-
|
76
|
-
= Headline
|
77
|
-
Text
|
78
|
-
.nested: creole: **Strong**
|
45
|
+
css []:
|
46
|
+
h1 { color: blue }
|
79
47
|
}
|
80
|
-
|
48
|
+
assert_html "<style type=\"text/css\">h1 { color: blue }</style>", source
|
81
49
|
end
|
82
50
|
|
83
|
-
def
|
84
|
-
# HACK: org-ruby registers itself in Tilt
|
85
|
-
require 'org-ruby'
|
86
|
-
|
51
|
+
def test_render_with_css_attribute
|
87
52
|
source = %q{
|
88
|
-
|
89
|
-
|
90
|
-
* point2
|
53
|
+
css scoped = "true":
|
54
|
+
h1 { color: blue }
|
91
55
|
}
|
92
|
-
|
56
|
+
assert_html "<style scoped=\"true\" type=\"text/css\">h1 { color: blue }</style>", source
|
93
57
|
end
|
94
58
|
|
95
|
-
def
|
59
|
+
def test_render_with_css_multiple_attributes
|
96
60
|
source = %q{
|
97
|
-
|
98
|
-
|
99
|
-
xml.text!('Hello')
|
100
|
-
}
|
61
|
+
css class="myClass" scoped = "true" :
|
62
|
+
h1 { color: blue }
|
101
63
|
}
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_render_with_wiki
|
106
|
-
source = %q{
|
107
|
-
wiki:
|
108
|
-
= head1
|
109
|
-
== head2
|
110
|
-
}
|
111
|
-
assert_html "<h1>head1</h1><h2>head2</h2>", source
|
64
|
+
assert_html "<style class=\"myClass\" scoped=\"true\" type=\"text/css\">h1 { color: blue }</style>", source
|
112
65
|
end
|
113
66
|
|
114
67
|
def test_render_with_javascript
|
115
|
-
# Keep the trailing space behind "javascript: "!
|
116
68
|
source = %q{
|
117
|
-
javascript:
|
69
|
+
javascript:
|
118
70
|
$(function() {});
|
119
71
|
|
120
72
|
|
@@ -124,19 +76,28 @@ p Hi
|
|
124
76
|
assert_html %{<script>$(function() {});\n\n\nalert('hello')</script><p>Hi</p>}, source
|
125
77
|
end
|
126
78
|
|
127
|
-
def
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
79
|
+
def test_render_with_javascript_empty_attributes
|
80
|
+
source = %q{
|
81
|
+
javascript ():
|
82
|
+
alert('hello')
|
83
|
+
}
|
84
|
+
assert_html %{<script>alert('hello')</script>}, source
|
85
|
+
end
|
134
86
|
|
87
|
+
def test_render_with_javascript_attribute
|
135
88
|
source = %q{
|
136
|
-
|
137
|
-
|
89
|
+
javascript [class = "myClass"]:
|
90
|
+
alert('hello')
|
138
91
|
}
|
139
|
-
|
92
|
+
assert_html %{<script class=\"myClass\">alert('hello')</script>}, source
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_render_with_javascript_multiple_attributes
|
96
|
+
source = %q{
|
97
|
+
javascript { class = "myClass" id="myId" other-attribute = 'my_other_attribute' } :
|
98
|
+
alert('hello')
|
99
|
+
}
|
100
|
+
assert_html %{<script class=\"myClass\" id=\"myId\" other-attribute=\"my_other_attribute\">alert('hello')</script>}, source
|
140
101
|
end
|
141
102
|
|
142
103
|
def test_render_with_javascript_with_tabs
|
@@ -145,10 +106,9 @@ opal:
|
|
145
106
|
end
|
146
107
|
|
147
108
|
def test_render_with_javascript_including_variable
|
148
|
-
# Keep the trailing space behind "javascript: "!
|
149
109
|
source = %q{
|
150
110
|
- func = "alert('hello');"
|
151
|
-
javascript:
|
111
|
+
javascript:
|
152
112
|
$(function() { #{func} });
|
153
113
|
}
|
154
114
|
assert_html %q|<script>$(function() { alert('hello'); });</script>|, source
|
@@ -192,6 +152,17 @@ ruby:
|
|
192
152
|
assert_html '3', source
|
193
153
|
end
|
194
154
|
|
155
|
+
def test_render_with_ruby_heredoc
|
156
|
+
source = %q{
|
157
|
+
ruby:
|
158
|
+
variable = <<-MSG
|
159
|
+
foobar
|
160
|
+
MSG
|
161
|
+
= variable
|
162
|
+
}
|
163
|
+
assert_html "foobar\n", source
|
164
|
+
end
|
165
|
+
|
195
166
|
def test_render_with_scss
|
196
167
|
source = %q{
|
197
168
|
scss:
|
@@ -201,6 +172,36 @@ scss:
|
|
201
172
|
assert_html "<style type=\"text/css\">body{color:red}</style>", source
|
202
173
|
end
|
203
174
|
|
175
|
+
def test_render_with_scss_attribute
|
176
|
+
source = %q{
|
177
|
+
scss [class="myClass"]:
|
178
|
+
$color: #f00;
|
179
|
+
body { color: $color; }
|
180
|
+
}
|
181
|
+
assert_html "<style class=\"myClass\" type=\"text/css\">body{color:red}</style>", source
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_render_with_sass
|
185
|
+
source = %q{
|
186
|
+
sass:
|
187
|
+
$color: #f00
|
188
|
+
body
|
189
|
+
color: $color
|
190
|
+
}
|
191
|
+
assert_html "<style type=\"text/css\">body{color:red}</style>", source
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_render_with_sass_attribute
|
195
|
+
source = %q{
|
196
|
+
sass [class="myClass"]:
|
197
|
+
$color: #f00
|
198
|
+
body
|
199
|
+
color: $color
|
200
|
+
}
|
201
|
+
assert_html "<style class=\"myClass\" type=\"text/css\">body{color:red}</style>", source
|
202
|
+
end
|
203
|
+
|
204
|
+
|
204
205
|
def test_disabled_embedded_engine
|
205
206
|
source = %{
|
206
207
|
ruby:
|
@@ -113,7 +113,7 @@ option(selected class="clazz") Text
|
|
113
113
|
.alpha data={a: 'alpha', b: 'beta', c_d: 'gamma', c: {e: 'epsilon'}}
|
114
114
|
}
|
115
115
|
|
116
|
-
assert_html '<div class="alpha" data-a="alpha" data-b="beta" data-c-
|
116
|
+
assert_html '<div class="alpha" data-a="alpha" data-b="beta" data-c-e="epsilon" data-c_d="gamma"></div>', source
|
117
117
|
end
|
118
118
|
|
119
119
|
def test_splat_without_content
|
@@ -265,4 +265,29 @@ p
|
|
265
265
|
}
|
266
266
|
assert_html '<p><img src="img.png" whatsthis?!="" /><img src="img.png" whatsthis?!="wtf" /></p>', source
|
267
267
|
end
|
268
|
+
|
269
|
+
def test_multiline_attribute_with_space
|
270
|
+
source = %q{
|
271
|
+
a data-title="help" data-content="extremely long help text that goes on\
|
272
|
+
and one and one and then starts over...." Link
|
273
|
+
}
|
274
|
+
assert_html '<a data-content="extremely long help text that goes on and one and one and then starts over...." data-title="help">Link</a>', source
|
275
|
+
end
|
276
|
+
|
277
|
+
def test_multiline_attribute_without_space
|
278
|
+
source= %q{
|
279
|
+
link rel="stylesheet" type="text/css" href="https://stylesheet-cdn.com/\
|
280
|
+
this/is/a/quite/long/url/that/would/be/nice/to/split/up"
|
281
|
+
}
|
282
|
+
assert_html '<link rel="stylesheet" type="text/css" href="https://stylesheet-cdn.com/this/is/a/quite/long/url/that/would/be/nice/to/split/up" />', source
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_eme
|
286
|
+
source = %q{
|
287
|
+
script#template[type="text/x-template"]
|
288
|
+
div[v-bind:class="{'some-class': boolean_var}"]
|
289
|
+
span contents
|
290
|
+
}
|
291
|
+
assert_html '<script></script>', source
|
292
|
+
end
|
268
293
|
end
|
@@ -19,17 +19,7 @@ p = hello_world + \
|
|
19
19
|
unknown_ruby_method
|
20
20
|
}
|
21
21
|
|
22
|
-
|
23
|
-
# This is actually a jruby issue. Jruby reports a wrong
|
24
|
-
# line number 1 in this case:
|
25
|
-
#
|
26
|
-
# test = 1+\
|
27
|
-
# unknown_variable
|
28
|
-
if RUBY_PLATFORM == "java"
|
29
|
-
assert_ruby_error NameError, "test.slim:2", source, file: 'test.slim'
|
30
|
-
else
|
31
|
-
assert_ruby_error NameError, "test.slim:4", source, file: 'test.slim'
|
32
|
-
end
|
22
|
+
assert_ruby_error NameError, "test.slim:4", source, file: 'test.slim'
|
33
23
|
end
|
34
24
|
|
35
25
|
def test_broken_output_line2
|
@@ -94,22 +84,6 @@ p Text line 1
|
|
94
84
|
assert_ruby_error NameError,"(__TEMPLATE__):4", source
|
95
85
|
end
|
96
86
|
|
97
|
-
def test_embedded_erb
|
98
|
-
source = %q{
|
99
|
-
erb:
|
100
|
-
<%= 123 %>
|
101
|
-
Hello from ERB!
|
102
|
-
<%#
|
103
|
-
comment block
|
104
|
-
%>
|
105
|
-
<% if true %>
|
106
|
-
Text
|
107
|
-
<% end %>
|
108
|
-
= unknown_ruby_method
|
109
|
-
}
|
110
|
-
assert_ruby_error NameError,"(__TEMPLATE__):11", source
|
111
|
-
end
|
112
|
-
|
113
87
|
def test_embedded_ruby1
|
114
88
|
source = %q{
|
115
89
|
ruby:
|
@@ -119,7 +93,7 @@ ruby:
|
|
119
93
|
= unknown_ruby_method
|
120
94
|
}
|
121
95
|
|
122
|
-
assert_ruby_error NameError,"(__TEMPLATE__):
|
96
|
+
assert_ruby_error NameError,"(__TEMPLATE__):7", source
|
123
97
|
end
|
124
98
|
|
125
99
|
def test_embedded_ruby2
|
@@ -5,6 +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
9
|
|
9
10
|
require 'slim'
|
10
11
|
|
@@ -40,5 +41,20 @@ module Dummy
|
|
40
41
|
|
41
42
|
# Configure sensitive parameters which will be filtered from the log file.
|
42
43
|
config.filter_parameters += [:password]
|
44
|
+
|
45
|
+
# From slim-rails fix for "ActionView::Template::Error: Unknown line indicator"
|
46
|
+
# https://github.com/slim-template/slim-rails/blob/991589ea5648e5e896781e68912bc51beaf4102a/lib/slim-rails/register_engine.rb
|
47
|
+
if config.respond_to?(:assets)
|
48
|
+
config.assets.configure do |env|
|
49
|
+
if env.respond_to?(:register_transformer) && Sprockets::VERSION.to_i > 3
|
50
|
+
env.register_mime_type 'text/slim', extensions: ['.slim', '.slim.html']
|
51
|
+
env.register_transformer 'text/slim', 'text/html', RegisterEngine::Transformer
|
52
|
+
elsif env.respond_to?(:register_engine)
|
53
|
+
args = ['.slim', Slim::Template]
|
54
|
+
args << { silence_deprecation: true } if Sprockets::VERSION.start_with?('3')
|
55
|
+
env.register_engine(*args)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
43
59
|
end
|
44
60
|
end
|
data/test/rails/test/helper.rb
CHANGED
@@ -5,6 +5,9 @@ require File.expand_path("../../config/environment.rb", __FILE__)
|
|
5
5
|
require "rails/test_help"
|
6
6
|
require "nokogiri"
|
7
7
|
|
8
|
+
require 'rails-controller-testing'
|
9
|
+
Rails::Controller::Testing.install
|
10
|
+
|
8
11
|
Rails.backtrace_cleaner.remove_silencers!
|
9
12
|
|
10
13
|
class ActionDispatch::IntegrationTest
|
@@ -65,9 +65,9 @@ class TestSlim < ActionDispatch::IntegrationTest
|
|
65
65
|
end
|
66
66
|
|
67
67
|
test "render thread_options" do
|
68
|
-
get "/slim/thread_options", attr: 'role'
|
68
|
+
get "/slim/thread_options", params: { attr: 'role'}
|
69
69
|
assert_html '<p role="empty">Test</p>'
|
70
|
-
get "/slim/thread_options", attr: 'id' # Overwriting doesn't work because of caching
|
70
|
+
get "/slim/thread_options", params: { attr: 'id'} # Overwriting doesn't work because of caching
|
71
71
|
assert_html '<p role="empty">Test</p>'
|
72
72
|
end
|
73
73
|
|
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:
|
4
|
+
version: 4.0.0
|
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:
|
13
|
+
date: 2018-08-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: temple
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 2.0.6
|
42
42
|
- - "<"
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: '2.1'
|
@@ -48,7 +48,7 @@ dependencies:
|
|
48
48
|
requirements:
|
49
49
|
- - ">="
|
50
50
|
- !ruby/object:Gem::Version
|
51
|
-
version:
|
51
|
+
version: 2.0.6
|
52
52
|
- - "<"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.1'
|
@@ -205,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
205
|
version: '0'
|
206
206
|
requirements: []
|
207
207
|
rubyforge_project:
|
208
|
-
rubygems_version: 2.
|
208
|
+
rubygems_version: 2.7.6
|
209
209
|
signing_key:
|
210
210
|
specification_version: 4
|
211
211
|
summary: Slim is a template language.
|