slim 5.0.0 → 5.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +1 -1
- data/CHANGES +13 -0
- data/Gemfile +4 -20
- data/README.jp.md +13 -15
- data/README.md +48 -15
- data/Rakefile +0 -5
- data/lib/slim/code_attributes.rb +1 -0
- data/lib/slim/command.rb +1 -7
- data/lib/slim/controls.rb +1 -0
- data/lib/slim/do_inserter.rb +1 -0
- data/lib/slim/embedded.rb +3 -2
- 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 +2 -1
- data/lib/slim/logic_less/filter.rb +1 -0
- data/lib/slim/logic_less.rb +1 -0
- data/lib/slim/parser.rb +21 -11
- data/lib/slim/railtie.rb +2 -1
- data/lib/slim/smart/escaper.rb +1 -0
- data/lib/slim/smart/filter.rb +1 -0
- data/lib/slim/smart/parser.rb +1 -0
- data/lib/slim/smart.rb +1 -0
- data/lib/slim/splat/builder.rb +2 -1
- data/lib/slim/splat/filter.rb +1 -0
- data/lib/slim/template.rb +1 -0
- data/lib/slim/translator.rb +3 -2
- data/lib/slim/version.rb +2 -1
- data/lib/slim.rb +1 -0
- data/slim.gemspec +1 -1
- data/test/core/helper.rb +1 -1
- data/test/core/test_encoding.rb +2 -2
- data/test/core/test_html_structure.rb +54 -0
- data/test/literate/TESTS.md +50 -0
- data/test/literate/run.rb +1 -1
- data/test/rails/app/controllers/slim_controller.rb +2 -1
- data/test/rails/app/views/slim/attributes.html.slim +3 -0
- data/test/rails/test/test_slim.rb +5 -0
- metadata +5 -18
- data/benchmarks/context.rb +0 -11
- data/benchmarks/profile-parser.rb +0 -10
- data/benchmarks/profile-render.rb +0 -12
- data/benchmarks/run-benchmarks.rb +0 -115
- data/benchmarks/run-diffbench.rb +0 -21
- data/benchmarks/view.erb +0 -25
- data/benchmarks/view.haml +0 -20
- data/benchmarks/view.slim +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 032ed4e8911b32aa669a7e0a6196a9955d2f2cdadbcc8432aa589039bc3a7b50
|
4
|
+
data.tar.gz: 94ce4618acbca850dce85c0ce3379e77a8b03ca846b84edcb25a09dfa050e848
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e25e4b9230e092183013063ece1dbb3233b267eb118f90e41dca7d4a2221fe4e00b1c572d6d1b5defac7b0912bba0b00ff442785c930f49f06849819d699ecb7
|
7
|
+
data.tar.gz: 065b7317b43379f0c7ecf85a0ce4fd398b9ecac13e3b6793de9293711776468bd24c15b2a19f029dd04a16aaf724b1210e0fab600a06a23db57f172054d7f798
|
data/.github/workflows/test.yml
CHANGED
data/CHANGES
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
5.1.1 (2023-05-16)
|
2
|
+
|
3
|
+
* Support lambda functions as shortcuts - #677 #813 #903
|
4
|
+
* Support --enable-frozen-string-literal - #851
|
5
|
+
|
6
|
+
5.1.0 (2023-03-06)
|
7
|
+
|
8
|
+
* Allow whitespace markers for verbatim text: `|<`, `|>`, and `|<>` - #912
|
9
|
+
* Do not swallow single quote after output line indicator - #911
|
10
|
+
* Support Tilt 2.1.0 - #910
|
11
|
+
* Fix Railtie load error - #904
|
12
|
+
* Fix attribute parsing with square brackets - #796
|
13
|
+
|
1
14
|
5.0.0 (2023-01-23)
|
2
15
|
|
3
16
|
* Fix markdown interpolation #773
|
data/Gemfile
CHANGED
@@ -2,11 +2,10 @@ source 'https://rubygems.org/'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
5
|
+
gem 'test-unit', '~> 3.5'
|
6
|
+
gem 'minitest', '~> 5.15'
|
7
|
+
gem 'rake', '~> 13.0'
|
8
|
+
gem 'kramdown', '~> 2.4'
|
10
9
|
|
11
10
|
if ENV['TEMPLE'] && ENV['TEMPLE'] != 'master'
|
12
11
|
gem 'temple', "= #{ENV['TEMPLE']}"
|
@@ -34,11 +33,6 @@ if ENV['RAILS']
|
|
34
33
|
end
|
35
34
|
end
|
36
35
|
|
37
|
-
gem 'test-unit', '~> 3.5'
|
38
|
-
gem 'minitest', '~> 5.15'
|
39
|
-
gem 'rake', '~> 13.0'
|
40
|
-
gem 'kramdown', '~> 2.4'
|
41
|
-
|
42
36
|
if ENV['SINATRA']
|
43
37
|
gem 'rack-test'
|
44
38
|
|
@@ -48,13 +42,3 @@ if ENV['SINATRA']
|
|
48
42
|
gem 'sinatra', :tag => "v#{ENV['SINATRA']}"
|
49
43
|
end
|
50
44
|
end
|
51
|
-
|
52
|
-
if ENV['TASK'] == 'bench'
|
53
|
-
gem 'benchmark-ips'
|
54
|
-
gem 'erubi'
|
55
|
-
gem 'haml'
|
56
|
-
end
|
57
|
-
|
58
|
-
if ENV['CODECLIMATE_REPO_TOKEN']
|
59
|
-
gem 'codeclimate-test-reporter'
|
60
|
-
end
|
data/README.jp.md
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://img.shields.io/gem/v/slim.svg)](http://rubygems.org/gems/slim)
|
4
4
|
![Build Status](https://github.com/slim-template/slim/actions/workflows/test.yml/badge.svg)
|
5
|
-
[![Code Climate](https://codeclimate.com/github/slim-template/slim/badges/gpa.svg)](https://codeclimate.com/github/slim-template/slim)
|
6
|
-
[![Test Coverage](https://codeclimate.com/github/slim-template/slim/badges/coverage.svg)](https://codeclimate.com/github/slim-template/slim/coverage)
|
7
5
|
[![GitHub Sponsors](https://img.shields.io/github/sponsors/slim-template)](https://github.com/sponsors/slim-template)
|
8
6
|
|
9
7
|
Slim は 不可解にならない程度に view の構文を本質的な部品まで減らすことを目指したテンプレート言語です。標準的な HTML テンプレートからどれだけのものを減らせるか、検証するところから始まりました。(<, >, 閉じタグなど) 多くの人が Slim に興味を持ったことで, 機能的で柔軟な構文に成長しました。
|
@@ -31,13 +29,13 @@ Slim は 不可解にならない程度に view の構文を本質的な部品
|
|
31
29
|
|
32
30
|
## リンク
|
33
31
|
|
34
|
-
* ホームページ: <
|
35
|
-
* ソース: <
|
36
|
-
* バグ: <
|
37
|
-
* リスト: <
|
32
|
+
* ホームページ: <https://slim-template.github.io>
|
33
|
+
* ソース: <https://github.com/slim-template/slim>
|
34
|
+
* バグ: <https://github.com/slim-template/slim/issues>
|
35
|
+
* リスト: <https://groups.google.com/group/slim-template>
|
38
36
|
* API ドキュメント:
|
39
|
-
* 最新の Gem: <
|
40
|
-
* GitHub master: <
|
37
|
+
* 最新の Gem: <https://rubydoc.info/gems/slim/frames> <https://www.omniref.com/ruby/gems/slim>
|
38
|
+
* GitHub master: <https://rubydoc.info/github/slim-template/slim/master/frames> <https://www.omniref.com/github/slim-template/slim>
|
41
39
|
|
42
40
|
## イントロダクション
|
43
41
|
|
@@ -411,7 +409,7 @@ body
|
|
411
409
|
タグの後に直接属性を書きます。通常の属性記述にはダブルクォート `"` か シングルクォート `'` を使わなければなりません (引用符で囲まれた属性)。
|
412
410
|
|
413
411
|
~~~ slim
|
414
|
-
a href="
|
412
|
+
a href="https://slim-template.github.io" title='Slim のホームページ' Slim のホームページへ
|
415
413
|
~~~
|
416
414
|
|
417
415
|
引用符で囲まれたテキストを属性として使えます。
|
@@ -447,7 +445,7 @@ h2 [ id = "tagline" ] = page_tagline
|
|
447
445
|
例:
|
448
446
|
|
449
447
|
~~~ slim
|
450
|
-
a href="
|
448
|
+
a href="https://slim-template.github.io" title='Slim のホームページ' Slim のホームページへ
|
451
449
|
~~~
|
452
450
|
|
453
451
|
引用符で囲まれたテキストを属性として使えます:
|
@@ -512,13 +510,13 @@ input type="text" disabled=nil
|
|
512
510
|
class 属性はスペース区切りで結合されます。
|
513
511
|
|
514
512
|
~~~ slim
|
515
|
-
a.menu class="highlight" href="
|
513
|
+
a.menu class="highlight" href="https://slim-template.github.io/" slim-template.github.io
|
516
514
|
~~~
|
517
515
|
|
518
516
|
レンダリング結果:
|
519
517
|
|
520
518
|
~~~ html
|
521
|
-
<a class="menu highlight" href="
|
519
|
+
<a class="menu highlight" href="https://slim-template.github.io/">slim-template.github.io</a>
|
522
520
|
~~~
|
523
521
|
|
524
522
|
また, `Array` を属性値として使うと、配列要素が区切り文字で結合されます。
|
@@ -571,7 +569,7 @@ div class="first second third"
|
|
571
569
|
~~~ slim
|
572
570
|
ruby:
|
573
571
|
def a_unless_current
|
574
|
-
@page_current ? {tag: 'span'} : {tag: 'a', href: '
|
572
|
+
@page_current ? {tag: 'span'} : {tag: 'a', href: 'https://slim-template.github.io/'}
|
575
573
|
end
|
576
574
|
- @page_current = true
|
577
575
|
*a_unless_current リンク
|
@@ -582,7 +580,7 @@ ruby:
|
|
582
580
|
レンダリング結果:
|
583
581
|
|
584
582
|
~~~ html
|
585
|
-
<span>リンク</span><a href="
|
583
|
+
<span>リンク</span><a href="https://slim-template.github.io/">リンク</a>
|
586
584
|
~~~
|
587
585
|
|
588
586
|
### ショートカット
|
@@ -796,7 +794,7 @@ end
|
|
796
794
|
そして, 次のように使用出来ます。
|
797
795
|
|
798
796
|
~~~ slim
|
799
|
-
- links = { '
|
797
|
+
- links = { 'https://slim-template.github.io' => 'The Slim Template Language' }
|
800
798
|
= capture link_list=:link_list, links do |url, text|
|
801
799
|
a href=url = text
|
802
800
|
~~~
|
data/README.md
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://img.shields.io/gem/v/slim.svg)](http://rubygems.org/gems/slim)
|
4
4
|
![Build Status](https://github.com/slim-template/slim/actions/workflows/test.yml/badge.svg)
|
5
|
-
[![Code Climate](https://codeclimate.com/github/slim-template/slim/badges/gpa.svg)](https://codeclimate.com/github/slim-template/slim)
|
6
|
-
[![Test Coverage](https://codeclimate.com/github/slim-template/slim/badges/coverage.svg)](https://codeclimate.com/github/slim-template/slim/coverage)
|
7
5
|
[![GitHub Sponsors](https://img.shields.io/github/sponsors/slim-template)](https://github.com/sponsors/slim-template)
|
8
6
|
|
9
7
|
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.
|
@@ -31,13 +29,13 @@ A short list of the features...
|
|
31
29
|
|
32
30
|
## Links
|
33
31
|
|
34
|
-
* Homepage: <
|
35
|
-
* Source: <
|
36
|
-
* Bugs: <
|
37
|
-
* List: <
|
32
|
+
* Homepage: <https://slim-template.github.io>
|
33
|
+
* Source: <https://github.com/slim-template/slim>
|
34
|
+
* Bugs: <https://github.com/slim-template/slim/issues>
|
35
|
+
* List: <https://groups.google.com/group/slim-template>
|
38
36
|
* API documentation:
|
39
|
-
* Latest Gem: <
|
40
|
-
* GitHub master: <
|
37
|
+
* Latest Gem: <https://rubydoc.info/gems/slim/frames> <https://www.omniref.com/ruby/gems/slim>
|
38
|
+
* GitHub master: <https://rubydoc.info/github/slim-template/slim/master/frames> <https://www.omniref.com/github/slim-template/slim>
|
41
39
|
|
42
40
|
## Introduction
|
43
41
|
|
@@ -155,6 +153,17 @@ You can also embed html in the text line
|
|
155
153
|
| <tr><td>#{a.name}</td><td>#{a.description}</td></tr>
|
156
154
|
~~~
|
157
155
|
|
156
|
+
#### Verbatim text with leading and/or trailing white space `|<` `|>` `|<>`
|
157
|
+
|
158
|
+
You can add white space around verbatim text in the same way as for `=` output:
|
159
|
+
~~~ slim
|
160
|
+
| This line will not have any extra white space.
|
161
|
+
| This line will have a leading space, but it is difficult to see.
|
162
|
+
|< This line will have a leading white space.
|
163
|
+
|> This line will have a trailing white space.
|
164
|
+
|<> This line will have both leading and trailing white space.
|
165
|
+
~~~
|
166
|
+
|
158
167
|
### Verbatim text with trailing white space `'`
|
159
168
|
|
160
169
|
The single quote tells Slim to copy the line (similar to `|`), but makes sure that a single trailing white space is appended.
|
@@ -411,7 +420,7 @@ body
|
|
411
420
|
You write attributes directly after the tag. For normal text attributes you must use double `"` or single quotes `'` (Quoted attributes).
|
412
421
|
|
413
422
|
~~~ slim
|
414
|
-
a href="
|
423
|
+
a href="https://slim-template.github.io" title='Slim Homepage' Goto the Slim homepage
|
415
424
|
~~~
|
416
425
|
|
417
426
|
You can use text interpolation in the quoted attributes.
|
@@ -447,7 +456,7 @@ h2 [ id = "tagline" ] = page_tagline
|
|
447
456
|
Example:
|
448
457
|
|
449
458
|
~~~ slim
|
450
|
-
a href="
|
459
|
+
a href="https://slim-template.github.io" title='Slim Homepage' Goto the Slim homepage
|
451
460
|
~~~
|
452
461
|
|
453
462
|
You can use text interpolation in the quoted attributes:
|
@@ -512,13 +521,13 @@ You can configure attributes to be merged if multiple are given (See option `:me
|
|
512
521
|
this is done for class attributes with the white space as delimiter.
|
513
522
|
|
514
523
|
~~~ slim
|
515
|
-
a.menu class="highlight" href="
|
524
|
+
a.menu class="highlight" href="https://slim-template.github.io/" slim-template.github.io
|
516
525
|
~~~
|
517
526
|
|
518
527
|
This renders as:
|
519
528
|
|
520
529
|
~~~ html
|
521
|
-
<a class="menu highlight" href="
|
530
|
+
<a class="menu highlight" href="https://slim-template.github.io/">slim-template.github.io</a>
|
522
531
|
~~~
|
523
532
|
|
524
533
|
You can also use an `Array` as attribute value and the array elements will be merged using the delimiter.
|
@@ -571,7 +580,7 @@ with the :tag key.
|
|
571
580
|
~~~ slim
|
572
581
|
ruby:
|
573
582
|
def a_unless_current
|
574
|
-
@page_current ? {tag: 'span'} : {tag: 'a', href: '
|
583
|
+
@page_current ? {tag: 'span'} : {tag: 'a', href: 'https://slim-template.github.io/'}
|
575
584
|
end
|
576
585
|
- @page_current = true
|
577
586
|
*a_unless_current Link
|
@@ -582,7 +591,7 @@ ruby:
|
|
582
591
|
This renders as:
|
583
592
|
|
584
593
|
~~~ html
|
585
|
-
<span>Link</span><a href="
|
594
|
+
<span>Link</span><a href="https://slim-template.github.io/">Link</a>
|
586
595
|
~~~
|
587
596
|
|
588
597
|
### Shortcuts
|
@@ -692,6 +701,30 @@ which renders to
|
|
692
701
|
</script>
|
693
702
|
~~~
|
694
703
|
|
704
|
+
#### Lambda shortcuts
|
705
|
+
|
706
|
+
You can define custom shortcuts using lambdas.
|
707
|
+
|
708
|
+
In this example we add `~` to create a shortcut with a special processing (adding a prefix) for the class attribute.
|
709
|
+
|
710
|
+
~~~ ruby
|
711
|
+
Slim::Engine.set_options shortcut: {'~' => {attr: ->(v) {{class: "styled-#{v}"}}}}
|
712
|
+
~~~
|
713
|
+
|
714
|
+
We can use it in Slim code like this
|
715
|
+
|
716
|
+
~~~ slim
|
717
|
+
h1~title Hello
|
718
|
+
~text~question.paragraph How are you?
|
719
|
+
~~~
|
720
|
+
|
721
|
+
which renders to
|
722
|
+
|
723
|
+
~~~ html
|
724
|
+
<h1 class="styled-title">Hello</h1>
|
725
|
+
<div class="styled-text styled-question paragraph">How are you?</div>
|
726
|
+
~~~
|
727
|
+
|
695
728
|
#### ID shortcut `#` and class shortcut `.`
|
696
729
|
|
697
730
|
You can specify the `id` and `class` attributes in the following shortcut form
|
@@ -796,7 +829,7 @@ end
|
|
796
829
|
and it would be used as follows
|
797
830
|
|
798
831
|
~~~ slim
|
799
|
-
- links = { '
|
832
|
+
- links = { 'https://slim-template.github.io' => 'The Slim Template Language' }
|
800
833
|
= capture link_list=:link_list, links do |url, text|
|
801
834
|
a href=url = text
|
802
835
|
~~~
|
data/Rakefile
CHANGED
@@ -6,11 +6,6 @@ end
|
|
6
6
|
|
7
7
|
require 'rake/testtask'
|
8
8
|
|
9
|
-
desc 'Run Slim benchmarks! (default parameters slow=false)'
|
10
|
-
task :bench, :slow do
|
11
|
-
ruby('benchmarks/run-benchmarks.rb')
|
12
|
-
end
|
13
|
-
|
14
9
|
task 'test' => %w(test:core test:literate test:logic_less test:translator test:smart test:include)
|
15
10
|
|
16
11
|
namespace 'test' do
|
data/lib/slim/code_attributes.rb
CHANGED
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
|
|
@@ -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
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
|
data/lib/slim/end_inserter.rb
CHANGED
data/lib/slim/engine.rb
CHANGED
data/lib/slim/erb_converter.rb
CHANGED
data/lib/slim/filter.rb
CHANGED
data/lib/slim/grammar.rb
CHANGED
data/lib/slim/include.rb
CHANGED
data/lib/slim/interpolation.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Slim
|
2
3
|
class LogicLess
|
3
4
|
# @api private
|
@@ -16,7 +17,7 @@ module Slim
|
|
16
17
|
yield
|
17
18
|
else
|
18
19
|
new_scope do
|
19
|
-
dict.inject('') do |result, d|
|
20
|
+
dict.inject(''.dup) do |result, d|
|
20
21
|
scope.dict = d
|
21
22
|
result << yield
|
22
23
|
end
|
data/lib/slim/logic_less.rb
CHANGED
data/lib/slim/parser.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Slim
|
2
3
|
# Parses Slim code and transforms it to a Temple expression
|
3
4
|
# @api private
|
@@ -63,7 +64,7 @@ module Slim
|
|
63
64
|
raise ArgumentError, 'You can only use special characters for attribute shortcuts' if k =~ /(\p{Word}|-)/
|
64
65
|
end
|
65
66
|
if v.include?(:attr)
|
66
|
-
@attr_shortcut[k] = [v[:attr]].flatten
|
67
|
+
@attr_shortcut[k] = v[:attr].is_a?(Proc) ? v[:attr] : [v[:attr]].flatten
|
67
68
|
end
|
68
69
|
if v.include?(:additional_attrs)
|
69
70
|
@additional_attrs[k] = v[:additional_attrs]
|
@@ -79,12 +80,12 @@ module Slim
|
|
79
80
|
@attr_list_delims_re = /\A\s*([#{keys}])/
|
80
81
|
@embedded_re = /\A(#{Regexp.union(Embedded.engines.keys.map(&:to_s))})(?:\s*(?:(.*)))?:(\s*)/
|
81
82
|
keys = Regexp.escape ('"\'></='.split(//) + @attr_list_delims.flatten + @code_attr_delims.flatten).uniq.join
|
82
|
-
@attr_name = "\\A\\s*([
|
83
|
+
@attr_name = "\\A\\s*([^\\0\\s#{keys}]+)"
|
83
84
|
@quoted_attr_re = /#{@attr_name}\s*=(=?)\s*("|')/
|
84
85
|
@code_attr_re = /#{@attr_name}\s*=(=?)\s*/
|
85
86
|
|
86
87
|
splat_prefix = Regexp.escape(options[:splat_prefix])
|
87
|
-
splat_regexp_source = '\A\s*'
|
88
|
+
splat_regexp_source = '\A\s*' + splat_prefix + '(?=[^\s]+)'
|
88
89
|
@splat_attrs_regexp = Regexp.new(splat_regexp_source)
|
89
90
|
end
|
90
91
|
|
@@ -209,10 +210,12 @@ module Slim
|
|
209
210
|
when /\A\//
|
210
211
|
# Slim comment
|
211
212
|
parse_comment_block
|
212
|
-
when /\A([\|'])( ?)/
|
213
|
+
when /\A([\|'])([<>]{1,2}(?: |\z)| ?)/
|
213
214
|
# Found verbatim text block.
|
214
|
-
|
215
|
-
|
215
|
+
leading_ws = $2.include?('<'.freeze)
|
216
|
+
trailing_ws = ($1 == "'") || $2.include?('>'.freeze)
|
217
|
+
@stacks.last << [:static, ' '] if leading_ws
|
218
|
+
@stacks.last << [:slim, :text, :verbatim, parse_text_block($', @indents.last + $2.count(' ') + 1)]
|
216
219
|
@stacks.last << [:static, ' '] if trailing_ws
|
217
220
|
when /\A</
|
218
221
|
# Inline html
|
@@ -226,13 +229,14 @@ module Slim
|
|
226
229
|
block = [:multi]
|
227
230
|
@stacks.last << [:slim, :control, parse_broken_line, block]
|
228
231
|
@stacks << block
|
229
|
-
when /\A=(=?)([
|
232
|
+
when /\A=(=?)([<>]*)/
|
230
233
|
# Found an output block.
|
231
234
|
# We expect the line to be broken or the next line to be indented.
|
232
235
|
@line = $'
|
236
|
+
leading_ws = $2.include?('<'.freeze)
|
233
237
|
trailing_ws = $2.include?('>'.freeze)
|
234
238
|
block = [:multi]
|
235
|
-
@stacks.last << [:static, ' '] if
|
239
|
+
@stacks.last << [:static, ' '] if leading_ws
|
236
240
|
@stacks.last << [:slim, :output, $1.empty?, parse_broken_line, block]
|
237
241
|
@stacks.last << [:static, ' '] if trailing_ws
|
238
242
|
@stacks << block
|
@@ -332,7 +336,13 @@ module Slim
|
|
332
336
|
# The class/id attribute is :static instead of :slim :interpolate,
|
333
337
|
# because we don't want text interpolation in .class or #id shortcut
|
334
338
|
syntax_error!('Illegal shortcut') unless shortcut = @attr_shortcut[$1]
|
335
|
-
|
339
|
+
|
340
|
+
if shortcut.is_a?(Proc)
|
341
|
+
shortcut.call($2).each {|a, v| attributes << [:html, :attr, a, [:static, v]] }
|
342
|
+
else
|
343
|
+
shortcut.each {|a| attributes << [:html, :attr, a, [:static, $2]] }
|
344
|
+
end
|
345
|
+
|
336
346
|
if additional_attr_pairs = @additional_attrs[$1]
|
337
347
|
additional_attr_pairs.each do |k,v|
|
338
348
|
attributes << [:html, :attr, k.to_s, [:static, v]]
|
@@ -458,7 +468,7 @@ module Slim
|
|
458
468
|
end
|
459
469
|
|
460
470
|
def parse_ruby_code(outer_delimiter)
|
461
|
-
code, count, delimiter, close_delimiter = '', 0, nil, nil
|
471
|
+
code, count, delimiter, close_delimiter = ''.dup, 0, nil, nil
|
462
472
|
|
463
473
|
# Attribute ends with space or attribute delimiter
|
464
474
|
end_re = /\A[\s#{Regexp.escape outer_delimiter.to_s}]/
|
@@ -486,7 +496,7 @@ module Slim
|
|
486
496
|
end
|
487
497
|
|
488
498
|
def parse_quoted_attribute(quote)
|
489
|
-
value, count = '', 0
|
499
|
+
value, count = ''.dup, 0
|
490
500
|
|
491
501
|
until count == 0 && @line[0] == quote[0]
|
492
502
|
if @line =~ /\A(\\)?\Z/
|
data/lib/slim/railtie.rb
CHANGED
data/lib/slim/smart/escaper.rb
CHANGED
data/lib/slim/smart/filter.rb
CHANGED
data/lib/slim/smart/parser.rb
CHANGED
data/lib/slim/smart.rb
CHANGED
data/lib/slim/splat/builder.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Slim
|
2
3
|
class InvalidAttributeNameError < StandardError; end
|
3
4
|
module Splat
|
@@ -90,7 +91,7 @@ module Slim
|
|
90
91
|
|
91
92
|
def hyphen_attr(name, escape, value)
|
92
93
|
if Hash === value
|
93
|
-
if @options[:hyphen_underscore_attrs]
|
94
|
+
if @options[:hyphen_underscore_attrs]
|
94
95
|
value.each do |n, v|
|
95
96
|
hyphen_attr("#{name}-#{n.to_s.gsub('_', '-')}", escape, v)
|
96
97
|
end
|
data/lib/slim/splat/filter.rb
CHANGED
data/lib/slim/template.rb
CHANGED
data/lib/slim/translator.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'slim'
|
2
3
|
|
3
4
|
module Slim
|
@@ -62,7 +63,7 @@ module Slim
|
|
62
63
|
end
|
63
64
|
|
64
65
|
def call(exp)
|
65
|
-
@text, @captures = '', []
|
66
|
+
@text, @captures = ''.dup, []
|
66
67
|
result = compile(exp)
|
67
68
|
|
68
69
|
text = @translate.call(@text)
|
@@ -89,7 +90,7 @@ module Slim
|
|
89
90
|
define_options :tr_fn
|
90
91
|
|
91
92
|
def call(exp)
|
92
|
-
@captures_count, @captures_var, @text = 0, unique_name, ''
|
93
|
+
@captures_count, @captures_var, @text = 0, unique_name, ''.dup
|
93
94
|
|
94
95
|
result = compile(exp)
|
95
96
|
|
data/lib/slim/version.rb
CHANGED
data/lib/slim.rb
CHANGED
data/slim.gemspec
CHANGED
data/test/core/helper.rb
CHANGED
data/test/core/test_encoding.rb
CHANGED
@@ -8,10 +8,10 @@ class TestSlimEncoding < TestSlim
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_binary
|
11
|
-
source = "| \xFF\xFF"
|
11
|
+
source = "| \xFF\xFF".dup
|
12
12
|
source.force_encoding(Encoding::BINARY)
|
13
13
|
|
14
|
-
result = "\xFF\xFF"
|
14
|
+
result = "\xFF\xFF".dup
|
15
15
|
result.force_encoding(Encoding::BINARY)
|
16
16
|
|
17
17
|
out = render(source, default_encoding: 'binary')
|
@@ -115,6 +115,54 @@ h1#title This is my title
|
|
115
115
|
source, shortcut: {'^' => {tag: 'script', attr: 'data-binding', additional_attrs: { type: "application/json" }}}
|
116
116
|
end
|
117
117
|
|
118
|
+
def test_render_with_custom_lambda_shortcut
|
119
|
+
begin
|
120
|
+
Slim::Parser.options[:shortcut]['~'] = {attr: ->(v) {{class: "styled-#{v}", id: "id-#{v}"}}}
|
121
|
+
source = %q{
|
122
|
+
~foo Hello
|
123
|
+
}
|
124
|
+
assert_html '<div class="styled-foo" id="id-foo">Hello</div>', source
|
125
|
+
ensure
|
126
|
+
Slim::Parser.options[:shortcut].delete('~')
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_render_with_custom_lambda_shortcut_and_multiple_values
|
131
|
+
begin
|
132
|
+
Slim::Parser.options[:shortcut]['~'] = {attr: ->(v) {{class: "styled-#{v}"}}}
|
133
|
+
source = %q{
|
134
|
+
~foo~bar Hello
|
135
|
+
}
|
136
|
+
assert_html '<div class="styled-foo styled-bar">Hello</div>', source
|
137
|
+
ensure
|
138
|
+
Slim::Parser.options[:shortcut].delete('~')
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_render_with_custom_lambda_shortcut_and_existing_class
|
143
|
+
begin
|
144
|
+
Slim::Parser.options[:shortcut]['~'] = {attr: ->(v) {{class: "styled-#{v}"}}}
|
145
|
+
source = %q{
|
146
|
+
~foo.baz Hello
|
147
|
+
}
|
148
|
+
assert_html '<div class="styled-foo baz">Hello</div>', source
|
149
|
+
ensure
|
150
|
+
Slim::Parser.options[:shortcut].delete('~')
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_render_with_existing_class_and_custom_lambda_shortcut
|
155
|
+
begin
|
156
|
+
Slim::Parser.options[:shortcut]['~'] = {attr: ->(v) {{class: "styled-#{v}"}}}
|
157
|
+
source = %q{
|
158
|
+
.baz~foo Hello
|
159
|
+
}
|
160
|
+
assert_html '<div class="baz styled-foo">Hello</div>', source
|
161
|
+
ensure
|
162
|
+
Slim::Parser.options[:shortcut].delete('~')
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
118
166
|
def test_render_with_text_block
|
119
167
|
source = %q{
|
120
168
|
p
|
@@ -311,6 +359,12 @@ p[id="marvin" class="martian" data-info="Illudium Q-36"] = output_number
|
|
311
359
|
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', source
|
312
360
|
end
|
313
361
|
|
362
|
+
# Regression test for bug #796
|
363
|
+
def test_square_brackets_around_attributes_multiline_with_tabs
|
364
|
+
source = "div\n\tp[\n\t\tclass=\"martian\"\n\t]\n\tp Next line"
|
365
|
+
assert_html '<div><p class="martian"></p><p>Next line</p></div>', source
|
366
|
+
end
|
367
|
+
|
314
368
|
def test_parens_around_attributes_with_equal_sign_snug_to_right_paren
|
315
369
|
source = %q{
|
316
370
|
p(id="marvin" class="martian" data-info="Illudium Q-36")= output_number
|
data/test/literate/TESTS.md
CHANGED
@@ -27,6 +27,22 @@ renders as
|
|
27
27
|
Text block
|
28
28
|
~~~
|
29
29
|
|
30
|
+
You can add leading or trailing white space with the `<` and `>` markers:
|
31
|
+
|
32
|
+
~~~ slim
|
33
|
+
|< Text with leading whitespace.
|
34
|
+
| Text with leading whitespace.
|
35
|
+
|> Text with trailing whitespace.
|
36
|
+
|<> Text with both leading and trailing whitespace.
|
37
|
+
~~~
|
38
|
+
|
39
|
+
renders as
|
40
|
+
|
41
|
+
~~~ html
|
42
|
+
Text with leading whitespace. Text with leading whitespace.Text with trailing whitespace. Text with both leading and trailing whitespace.
|
43
|
+
~~~
|
44
|
+
|
45
|
+
|
30
46
|
Multiple lines can be indented beneath the first text line.
|
31
47
|
|
32
48
|
~~~ slim
|
@@ -77,6 +93,30 @@ Text
|
|
77
93
|
lines
|
78
94
|
~~~
|
79
95
|
|
96
|
+
~~~ slim
|
97
|
+
|><
|
98
|
+
|
99
|
+
Text
|
100
|
+
block
|
101
|
+
|
102
|
+
with
|
103
|
+
|
104
|
+
multiple
|
105
|
+
lines
|
106
|
+
~~~
|
107
|
+
|
108
|
+
renders as
|
109
|
+
|
110
|
+
~~~ html
|
111
|
+
Text
|
112
|
+
block
|
113
|
+
|
114
|
+
with
|
115
|
+
|
116
|
+
multiple
|
117
|
+
lines
|
118
|
+
~~~
|
119
|
+
|
80
120
|
You can nest text blocks beneath tags.
|
81
121
|
|
82
122
|
~~~ slim
|
@@ -104,6 +144,16 @@ renders as
|
|
104
144
|
<a href="http://github.com/slim-template/slim">github.com/slim-template/slim</a>
|
105
145
|
~~~
|
106
146
|
|
147
|
+
~~~ slim
|
148
|
+
|<a href="http://github.com/slim-template/slim">github.com/slim-template/slim</a>
|
149
|
+
~~~
|
150
|
+
|
151
|
+
renders as
|
152
|
+
|
153
|
+
~~~ html
|
154
|
+
<a href="http://github.com/slim-template/slim">github.com/slim-template/slim</a>
|
155
|
+
~~~
|
156
|
+
|
107
157
|
### Text with trailing white space `'`
|
108
158
|
|
109
159
|
A text blocks with trailing white space starts with the `'` as line indicator.
|
data/test/literate/run.rb
CHANGED
@@ -63,7 +63,7 @@ class LiterateTest < Temple::Engine
|
|
63
63
|
def on_html(code)
|
64
64
|
raise Temple::FilterError, 'Html block must be preceded by slim block' unless @in_testcase
|
65
65
|
@in_testcase = false
|
66
|
-
result = " html = #{code.inspect}\n"
|
66
|
+
result = " html = #{code.inspect}\n".dup
|
67
67
|
if @opts.empty?
|
68
68
|
result << " _(render(slim)).must_equal html\nend\n"
|
69
69
|
else
|
@@ -26,7 +26,8 @@ class SlimController < ApplicationController
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def thread_options
|
29
|
-
|
29
|
+
default_shortcut = {'#' => {attr: 'id'}, '.' => {attr: 'class'} }
|
30
|
+
Slim::Engine.with_options(shortcut: default_shortcut.merge({'@' => { attr: params[:attr] }})) do
|
30
31
|
render
|
31
32
|
end
|
32
33
|
end
|
@@ -77,6 +77,11 @@ class TestSlim < ActionDispatch::IntegrationTest
|
|
77
77
|
assert_xpath '//input[@id="entry_name" and @name="entry[name]" and @type="text"]'
|
78
78
|
end
|
79
79
|
|
80
|
+
test "attributes" do
|
81
|
+
get "/slim/attributes"
|
82
|
+
assert_html "<div class=\"static a-b\"></div>"
|
83
|
+
end
|
84
|
+
|
80
85
|
test "splat" do
|
81
86
|
get "/slim/splat"
|
82
87
|
assert_html "<div id=\"splat\"><splat>Hello</splat></div>"
|
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: 5.
|
4
|
+
version: 5.1.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: 2023-
|
13
|
+
date: 2023-05-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: temple
|
@@ -32,20 +32,14 @@ dependencies:
|
|
32
32
|
requirements:
|
33
33
|
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: 2.0
|
36
|
-
- - "<"
|
37
|
-
- !ruby/object:Gem::Version
|
38
|
-
version: '2.1'
|
35
|
+
version: 2.1.0
|
39
36
|
type: :runtime
|
40
37
|
prerelease: false
|
41
38
|
version_requirements: !ruby/object:Gem::Requirement
|
42
39
|
requirements:
|
43
40
|
- - ">="
|
44
41
|
- !ruby/object:Gem::Version
|
45
|
-
version: 2.0
|
46
|
-
- - "<"
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: '2.1'
|
42
|
+
version: 2.1.0
|
49
43
|
description: Slim is a template language whose goal is reduce the syntax to the essential
|
50
44
|
parts without becoming cryptic.
|
51
45
|
email:
|
@@ -66,14 +60,6 @@ files:
|
|
66
60
|
- README.jp.md
|
67
61
|
- README.md
|
68
62
|
- Rakefile
|
69
|
-
- benchmarks/context.rb
|
70
|
-
- benchmarks/profile-parser.rb
|
71
|
-
- benchmarks/profile-render.rb
|
72
|
-
- benchmarks/run-benchmarks.rb
|
73
|
-
- benchmarks/run-diffbench.rb
|
74
|
-
- benchmarks/view.erb
|
75
|
-
- benchmarks/view.haml
|
76
|
-
- benchmarks/view.slim
|
77
63
|
- bin/slimrb
|
78
64
|
- doc/include.md
|
79
65
|
- doc/jp/include.md
|
@@ -152,6 +138,7 @@ files:
|
|
152
138
|
- test/rails/app/views/entries/edit.html.slim
|
153
139
|
- test/rails/app/views/layouts/application.html.slim
|
154
140
|
- test/rails/app/views/slim/_partial.html.slim
|
141
|
+
- test/rails/app/views/slim/attributes.html.slim
|
155
142
|
- test/rails/app/views/slim/content_for.html.slim
|
156
143
|
- test/rails/app/views/slim/erb.html.erb
|
157
144
|
- test/rails/app/views/slim/form_for.html.slim
|
data/benchmarks/context.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'), File.dirname(__FILE__))
|
4
|
-
|
5
|
-
require 'slim'
|
6
|
-
require 'context'
|
7
|
-
|
8
|
-
content = File.read(File.dirname(__FILE__) + '/view.slim')
|
9
|
-
slim = Slim::Template.new { content }
|
10
|
-
context = Context.new
|
11
|
-
|
12
|
-
10000.times { slim.render(context) }
|
@@ -1,115 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'), File.dirname(__FILE__))
|
4
|
-
|
5
|
-
require 'slim'
|
6
|
-
require 'context'
|
7
|
-
|
8
|
-
require 'benchmark/ips'
|
9
|
-
require 'tilt'
|
10
|
-
require 'erubi'
|
11
|
-
require 'erb'
|
12
|
-
require 'haml'
|
13
|
-
|
14
|
-
class SlimBenchmarks
|
15
|
-
def initialize(slow)
|
16
|
-
@benches = Hash.new { |h, k| h[k] = [] }
|
17
|
-
|
18
|
-
@erb_code = File.read(File.dirname(__FILE__) + '/view.erb')
|
19
|
-
@haml_code = File.read(File.dirname(__FILE__) + '/view.haml')
|
20
|
-
@slim_code = File.read(File.dirname(__FILE__) + '/view.slim')
|
21
|
-
|
22
|
-
init_compiled_benches
|
23
|
-
init_tilt_benches
|
24
|
-
init_parsing_benches if slow
|
25
|
-
end
|
26
|
-
|
27
|
-
def init_compiled_benches
|
28
|
-
context = Context.new
|
29
|
-
|
30
|
-
context.instance_eval %{
|
31
|
-
def run_erb; #{ERB.new(@erb_code).src}; end
|
32
|
-
def run_erubi; #{Erubi::Engine.new(@erb_code).src}; end
|
33
|
-
def run_temple_erb; #{Temple::ERB::Engine.new.call @erb_code}; end
|
34
|
-
def run_slim_pretty; #{Slim::Engine.new(pretty: true).call @slim_code}; end
|
35
|
-
def run_slim_ugly; #{Slim::Engine.new.call @slim_code}; end
|
36
|
-
def run_haml; #{Haml::Engine.new.call @haml_code}; end
|
37
|
-
}
|
38
|
-
|
39
|
-
bench(:compiled, 'erb') { context.run_erb }
|
40
|
-
bench(:compiled, 'erubi') { context.run_erubi }
|
41
|
-
bench(:compiled, 'temple erb') { context.run_temple_erb }
|
42
|
-
bench(:compiled, 'slim pretty') { context.run_slim_pretty }
|
43
|
-
bench(:compiled, 'slim ugly') { context.run_slim_ugly }
|
44
|
-
bench(:compiled, 'haml') { context.run_haml }
|
45
|
-
end
|
46
|
-
|
47
|
-
def init_tilt_benches
|
48
|
-
tilt_erb = Tilt::ERBTemplate.new { @erb_code }
|
49
|
-
tilt_erubi = Tilt::ErubiTemplate.new { @erb_code }
|
50
|
-
tilt_temple_erb = Temple::ERB::Template.new { @erb_code }
|
51
|
-
tilt_haml = Tilt::HamlTemplate.new(format: :html5) { @haml_code }
|
52
|
-
tilt_slim_pretty = Slim::Template.new(pretty: true) { @slim_code }
|
53
|
-
tilt_slim_ugly = Slim::Template.new { @slim_code }
|
54
|
-
|
55
|
-
context = Context.new
|
56
|
-
|
57
|
-
bench(:tilt, 'erb') { tilt_erb.render(context) }
|
58
|
-
bench(:tilt, 'erubi') { tilt_erubi.render(context) }
|
59
|
-
bench(:tilt, 'temple erb') { tilt_temple_erb.render(context) }
|
60
|
-
bench(:tilt, 'slim pretty') { tilt_slim_pretty.render(context) }
|
61
|
-
bench(:tilt, 'slim ugly') { tilt_slim_ugly.render(context) }
|
62
|
-
bench(:tilt, 'haml') { tilt_haml.render(context) }
|
63
|
-
end
|
64
|
-
|
65
|
-
def init_parsing_benches
|
66
|
-
context = Context.new
|
67
|
-
context_binding = context.instance_eval { binding }
|
68
|
-
|
69
|
-
bench(:parsing, 'erb') { ERB.new(@erb_code).result(context_binding) }
|
70
|
-
bench(:parsing, 'erubi') { Erubi::Engine.new(@erb_code).result(context_binding) }
|
71
|
-
bench(:parsing, 'temple erb') { Temple::ERB::Template.new { @erb_code }.render(context) }
|
72
|
-
bench(:parsing, 'slim pretty') { Slim::Template.new(pretty: true) { @slim_code }.render(context) }
|
73
|
-
bench(:parsing, 'slim ugly') { Slim::Template.new { @slim_code }.render(context) }
|
74
|
-
bench(:parsing, 'haml') { Haml::Engine.new(@haml_code, format: :html5).render(context) }
|
75
|
-
end
|
76
|
-
|
77
|
-
def run
|
78
|
-
@benches.each do |group_name, group_benches|
|
79
|
-
puts "Running #{group_name} benchmarks:"
|
80
|
-
|
81
|
-
Benchmark.ips do |x|
|
82
|
-
group_benches.each do |name, block|
|
83
|
-
x.report("#{group_name} #{name}", &block)
|
84
|
-
end
|
85
|
-
|
86
|
-
x.compare!
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
puts "
|
91
|
-
Compiled benchmark: Template is parsed before the benchmark and
|
92
|
-
generated ruby code is compiled into a method.
|
93
|
-
This is the fastest evaluation strategy because it benchmarks
|
94
|
-
pure execution speed of the generated ruby code.
|
95
|
-
|
96
|
-
Compiled Tilt benchmark: Template is compiled with Tilt, which gives a more
|
97
|
-
accurate result of the performance in production mode in frameworks like
|
98
|
-
Sinatra, Ramaze and Camping. (Rails still uses its own template
|
99
|
-
compilation.)
|
100
|
-
|
101
|
-
Parsing benchmark: Template is parsed every time.
|
102
|
-
This is not the recommended way to use the template engine
|
103
|
-
and Slim is not optimized for it. Activate this benchmark with 'rake bench slow=1'.
|
104
|
-
|
105
|
-
Temple ERB is the ERB implementation using the Temple framework. It shows the
|
106
|
-
overhead added by the Temple framework compared to ERB.
|
107
|
-
"
|
108
|
-
end
|
109
|
-
|
110
|
-
def bench(group, name, &block)
|
111
|
-
@benches[group].push([name, block])
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
SlimBenchmarks.new(ENV['slow']).run
|
data/benchmarks/run-diffbench.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'), File.dirname(__FILE__))
|
4
|
-
|
5
|
-
require 'slim'
|
6
|
-
require 'context'
|
7
|
-
require 'diffbench'
|
8
|
-
|
9
|
-
content = File.read(File.dirname(__FILE__) + '/view.slim')
|
10
|
-
engine = Slim::Engine.new
|
11
|
-
template = Slim::Template.new { content }
|
12
|
-
context = Context.new
|
13
|
-
|
14
|
-
DiffBench.bm do
|
15
|
-
report("Parse") do
|
16
|
-
2000.times { engine.call(content) }
|
17
|
-
end
|
18
|
-
report("Render") do
|
19
|
-
100000.times { template.render(context) }
|
20
|
-
end
|
21
|
-
end
|
data/benchmarks/view.erb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
<!DOCTYPE HTML>
|
2
|
-
|
3
|
-
<html lang="en">
|
4
|
-
<head>
|
5
|
-
<title>Simple Benchmark</title>
|
6
|
-
<meta charset="utf-8">
|
7
|
-
<meta name="description" content="This is an example of a meta description.">
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
<h1><%= header %></h1>
|
11
|
-
<% unless item.empty? %>
|
12
|
-
<ul>
|
13
|
-
<% for i in item %>
|
14
|
-
<% if i[:current] %>
|
15
|
-
<li><strong><%= i[:name] %></strong></li>
|
16
|
-
<% else %>
|
17
|
-
<li><a href="<%= i[:url] %>"><%= i[:name] %></a></li>
|
18
|
-
<% end %>
|
19
|
-
<% end %>
|
20
|
-
</ul>
|
21
|
-
<% else %>
|
22
|
-
<p>The list is empty.</p>
|
23
|
-
<% end %>
|
24
|
-
</body>
|
25
|
-
</html>
|
data/benchmarks/view.haml
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
!!! html
|
2
|
-
|
3
|
-
%html{ lang: "en" }
|
4
|
-
%head
|
5
|
-
%title Simple Benchmark
|
6
|
-
%meta{ charset: "utf-8" }
|
7
|
-
%meta{ name: "description", content: "This is an example of a meta description." }
|
8
|
-
%body
|
9
|
-
%h1= header
|
10
|
-
- unless item.empty?
|
11
|
-
%ul
|
12
|
-
- for i in item
|
13
|
-
- if i[:current]
|
14
|
-
%li
|
15
|
-
%strong= i[:name]
|
16
|
-
- else
|
17
|
-
%li
|
18
|
-
%a{:href => i[:url]}= i[:name]
|
19
|
-
- else
|
20
|
-
%p The list is empty.
|
data/benchmarks/view.slim
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
doctype html
|
2
|
-
html lang="en"
|
3
|
-
head
|
4
|
-
title Simple Benchmark
|
5
|
-
meta charset="utf-8"
|
6
|
-
meta name="description" content="This is an example of a meta description."
|
7
|
-
body
|
8
|
-
h1 == header
|
9
|
-
- unless item.empty?
|
10
|
-
ul
|
11
|
-
- for i in item
|
12
|
-
- if i[:current]
|
13
|
-
li
|
14
|
-
strong == i[:name]
|
15
|
-
- else
|
16
|
-
li
|
17
|
-
a href==i[:url] == i[:name]
|
18
|
-
- else
|
19
|
-
p The list is empty.
|