slim 5.1.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 +5 -0
- data/README.jp.md +13 -13
- data/README.md +38 -14
- 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 +12 -5
- data/lib/slim/railtie.rb +1 -0
- 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 +48 -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 -10
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
data/README.jp.md
CHANGED
@@ -29,13 +29,13 @@ Slim は 不可解にならない程度に view の構文を本質的な部品
|
|
29
29
|
|
30
30
|
## リンク
|
31
31
|
|
32
|
-
* ホームページ: <
|
33
|
-
* ソース: <
|
34
|
-
* バグ: <
|
35
|
-
* リスト: <
|
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>
|
36
36
|
* API ドキュメント:
|
37
|
-
* 最新の Gem: <
|
38
|
-
* 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>
|
39
39
|
|
40
40
|
## イントロダクション
|
41
41
|
|
@@ -409,7 +409,7 @@ body
|
|
409
409
|
タグの後に直接属性を書きます。通常の属性記述にはダブルクォート `"` か シングルクォート `'` を使わなければなりません (引用符で囲まれた属性)。
|
410
410
|
|
411
411
|
~~~ slim
|
412
|
-
a href="
|
412
|
+
a href="https://slim-template.github.io" title='Slim のホームページ' Slim のホームページへ
|
413
413
|
~~~
|
414
414
|
|
415
415
|
引用符で囲まれたテキストを属性として使えます。
|
@@ -445,7 +445,7 @@ h2 [ id = "tagline" ] = page_tagline
|
|
445
445
|
例:
|
446
446
|
|
447
447
|
~~~ slim
|
448
|
-
a href="
|
448
|
+
a href="https://slim-template.github.io" title='Slim のホームページ' Slim のホームページへ
|
449
449
|
~~~
|
450
450
|
|
451
451
|
引用符で囲まれたテキストを属性として使えます:
|
@@ -510,13 +510,13 @@ input type="text" disabled=nil
|
|
510
510
|
class 属性はスペース区切りで結合されます。
|
511
511
|
|
512
512
|
~~~ slim
|
513
|
-
a.menu class="highlight" href="
|
513
|
+
a.menu class="highlight" href="https://slim-template.github.io/" slim-template.github.io
|
514
514
|
~~~
|
515
515
|
|
516
516
|
レンダリング結果:
|
517
517
|
|
518
518
|
~~~ html
|
519
|
-
<a class="menu highlight" href="
|
519
|
+
<a class="menu highlight" href="https://slim-template.github.io/">slim-template.github.io</a>
|
520
520
|
~~~
|
521
521
|
|
522
522
|
また, `Array` を属性値として使うと、配列要素が区切り文字で結合されます。
|
@@ -569,7 +569,7 @@ div class="first second third"
|
|
569
569
|
~~~ slim
|
570
570
|
ruby:
|
571
571
|
def a_unless_current
|
572
|
-
@page_current ? {tag: 'span'} : {tag: 'a', href: '
|
572
|
+
@page_current ? {tag: 'span'} : {tag: 'a', href: 'https://slim-template.github.io/'}
|
573
573
|
end
|
574
574
|
- @page_current = true
|
575
575
|
*a_unless_current リンク
|
@@ -580,7 +580,7 @@ ruby:
|
|
580
580
|
レンダリング結果:
|
581
581
|
|
582
582
|
~~~ html
|
583
|
-
<span>リンク</span><a href="
|
583
|
+
<span>リンク</span><a href="https://slim-template.github.io/">リンク</a>
|
584
584
|
~~~
|
585
585
|
|
586
586
|
### ショートカット
|
@@ -794,7 +794,7 @@ end
|
|
794
794
|
そして, 次のように使用出来ます。
|
795
795
|
|
796
796
|
~~~ slim
|
797
|
-
- links = { '
|
797
|
+
- links = { 'https://slim-template.github.io' => 'The Slim Template Language' }
|
798
798
|
= capture link_list=:link_list, links do |url, text|
|
799
799
|
a href=url = text
|
800
800
|
~~~
|
data/README.md
CHANGED
@@ -29,13 +29,13 @@ A short list of the features...
|
|
29
29
|
|
30
30
|
## Links
|
31
31
|
|
32
|
-
* Homepage: <
|
33
|
-
* Source: <
|
34
|
-
* Bugs: <
|
35
|
-
* 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>
|
36
36
|
* API documentation:
|
37
|
-
* Latest Gem: <
|
38
|
-
* 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>
|
39
39
|
|
40
40
|
## Introduction
|
41
41
|
|
@@ -153,7 +153,7 @@ You can also embed html in the text line
|
|
153
153
|
| <tr><td>#{a.name}</td><td>#{a.description}</td></tr>
|
154
154
|
~~~
|
155
155
|
|
156
|
-
#### Verbatim text with leading and/or
|
156
|
+
#### Verbatim text with leading and/or trailing white space `|<` `|>` `|<>`
|
157
157
|
|
158
158
|
You can add white space around verbatim text in the same way as for `=` output:
|
159
159
|
~~~ slim
|
@@ -420,7 +420,7 @@ body
|
|
420
420
|
You write attributes directly after the tag. For normal text attributes you must use double `"` or single quotes `'` (Quoted attributes).
|
421
421
|
|
422
422
|
~~~ slim
|
423
|
-
a href="
|
423
|
+
a href="https://slim-template.github.io" title='Slim Homepage' Goto the Slim homepage
|
424
424
|
~~~
|
425
425
|
|
426
426
|
You can use text interpolation in the quoted attributes.
|
@@ -456,7 +456,7 @@ h2 [ id = "tagline" ] = page_tagline
|
|
456
456
|
Example:
|
457
457
|
|
458
458
|
~~~ slim
|
459
|
-
a href="
|
459
|
+
a href="https://slim-template.github.io" title='Slim Homepage' Goto the Slim homepage
|
460
460
|
~~~
|
461
461
|
|
462
462
|
You can use text interpolation in the quoted attributes:
|
@@ -521,13 +521,13 @@ You can configure attributes to be merged if multiple are given (See option `:me
|
|
521
521
|
this is done for class attributes with the white space as delimiter.
|
522
522
|
|
523
523
|
~~~ slim
|
524
|
-
a.menu class="highlight" href="
|
524
|
+
a.menu class="highlight" href="https://slim-template.github.io/" slim-template.github.io
|
525
525
|
~~~
|
526
526
|
|
527
527
|
This renders as:
|
528
528
|
|
529
529
|
~~~ html
|
530
|
-
<a class="menu highlight" href="
|
530
|
+
<a class="menu highlight" href="https://slim-template.github.io/">slim-template.github.io</a>
|
531
531
|
~~~
|
532
532
|
|
533
533
|
You can also use an `Array` as attribute value and the array elements will be merged using the delimiter.
|
@@ -580,7 +580,7 @@ with the :tag key.
|
|
580
580
|
~~~ slim
|
581
581
|
ruby:
|
582
582
|
def a_unless_current
|
583
|
-
@page_current ? {tag: 'span'} : {tag: 'a', href: '
|
583
|
+
@page_current ? {tag: 'span'} : {tag: 'a', href: 'https://slim-template.github.io/'}
|
584
584
|
end
|
585
585
|
- @page_current = true
|
586
586
|
*a_unless_current Link
|
@@ -591,7 +591,7 @@ ruby:
|
|
591
591
|
This renders as:
|
592
592
|
|
593
593
|
~~~ html
|
594
|
-
<span>Link</span><a href="
|
594
|
+
<span>Link</span><a href="https://slim-template.github.io/">Link</a>
|
595
595
|
~~~
|
596
596
|
|
597
597
|
### Shortcuts
|
@@ -701,6 +701,30 @@ which renders to
|
|
701
701
|
</script>
|
702
702
|
~~~
|
703
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
|
+
|
704
728
|
#### ID shortcut `#` and class shortcut `.`
|
705
729
|
|
706
730
|
You can specify the `id` and `class` attributes in the following shortcut form
|
@@ -805,7 +829,7 @@ end
|
|
805
829
|
and it would be used as follows
|
806
830
|
|
807
831
|
~~~ slim
|
808
|
-
- links = { '
|
832
|
+
- links = { 'https://slim-template.github.io' => 'The Slim Template Language' }
|
809
833
|
= capture link_list=:link_list, links do |url, text|
|
810
834
|
a href=url = text
|
811
835
|
~~~
|
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]
|
@@ -84,7 +85,7 @@ module Slim
|
|
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
|
|
@@ -335,7 +336,13 @@ module Slim
|
|
335
336
|
# The class/id attribute is :static instead of :slim :interpolate,
|
336
337
|
# because we don't want text interpolation in .class or #id shortcut
|
337
338
|
syntax_error!('Illegal shortcut') unless shortcut = @attr_shortcut[$1]
|
338
|
-
|
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
|
+
|
339
346
|
if additional_attr_pairs = @additional_attrs[$1]
|
340
347
|
additional_attr_pairs.each do |k,v|
|
341
348
|
attributes << [:html, :attr, k.to_s, [:static, v]]
|
@@ -461,7 +468,7 @@ module Slim
|
|
461
468
|
end
|
462
469
|
|
463
470
|
def parse_ruby_code(outer_delimiter)
|
464
|
-
code, count, delimiter, close_delimiter = '', 0, nil, nil
|
471
|
+
code, count, delimiter, close_delimiter = ''.dup, 0, nil, nil
|
465
472
|
|
466
473
|
# Attribute ends with space or attribute delimiter
|
467
474
|
end_re = /\A[\s#{Regexp.escape outer_delimiter.to_s}]/
|
@@ -489,7 +496,7 @@ module Slim
|
|
489
496
|
end
|
490
497
|
|
491
498
|
def parse_quoted_attribute(quote)
|
492
|
-
value, count = '', 0
|
499
|
+
value, count = ''.dup, 0
|
493
500
|
|
494
501
|
until count == 0 && @line[0] == quote[0]
|
495
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
|
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.1.
|
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.2'
|
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.2'
|
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:
|
@@ -144,6 +138,7 @@ files:
|
|
144
138
|
- test/rails/app/views/entries/edit.html.slim
|
145
139
|
- test/rails/app/views/layouts/application.html.slim
|
146
140
|
- test/rails/app/views/slim/_partial.html.slim
|
141
|
+
- test/rails/app/views/slim/attributes.html.slim
|
147
142
|
- test/rails/app/views/slim/content_for.html.slim
|
148
143
|
- test/rails/app/views/slim/erb.html.erb
|
149
144
|
- test/rails/app/views/slim/form_for.html.slim
|