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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7876d1b9fd825ae7f0afc3a94ceae2464b34d14a74018ad90f812b512d8cc4c0
4
- data.tar.gz: b522e774b1d808a57842796a414df8f9380ea8b24491d3799a1bd237c5ba71d1
3
+ metadata.gz: 032ed4e8911b32aa669a7e0a6196a9955d2f2cdadbcc8432aa589039bc3a7b50
4
+ data.tar.gz: 94ce4618acbca850dce85c0ce3379e77a8b03ca846b84edcb25a09dfa050e848
5
5
  SHA512:
6
- metadata.gz: db31ed4b35df749588fb4acf91e7180c8971931c3647b754afbcaf4f2c654aa65b908e1af13f86a68510a00774cddb2e23fc28eae56f60d0ba13b63c0df4fc12
7
- data.tar.gz: 77494b4cdac5ecb85d1ba4d569adcba6ebe01fb4024e5a4a02da4db6f96bf5af10919365af57783ad88b79ddcef75e113af20412225ab3166b2948f1a3967b3c
6
+ metadata.gz: e25e4b9230e092183013063ece1dbb3233b267eb118f90e41dca7d4a2221fe4e00b1c572d6d1b5defac7b0912bba0b00ff442785c930f49f06849819d699ecb7
7
+ data.tar.gz: 065b7317b43379f0c7ecf85a0ce4fd398b9ecac13e3b6793de9293711776468bd24c15b2a19f029dd04a16aaf724b1210e0fab600a06a23db57f172054d7f798
@@ -9,7 +9,7 @@ on:
9
9
  - synchronize
10
10
  - reopened
11
11
  schedule:
12
- - cron: "00 15 * * *"
12
+ - cron: "0 15 * * 0"
13
13
  jobs:
14
14
  basic:
15
15
  runs-on: ubuntu-latest
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
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
+
1
6
  5.1.0 (2023-03-06)
2
7
 
3
8
  * Allow whitespace markers for verbatim text: `|<`, `|>`, and `|<>` - #912
data/README.jp.md CHANGED
@@ -29,13 +29,13 @@ Slim は 不可解にならない程度に view の構文を本質的な部品
29
29
 
30
30
  ## リンク
31
31
 
32
- * ホームページ: <http://github.com/slim-template/slim>
33
- * ソース: <http://github.com/slim-template/slim>
34
- * バグ: <http://github.com/slim-template/slim/issues>
35
- * リスト: <http://groups.google.com/group/slim-template>
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: <http://rubydoc.info/gems/slim/frames> <https://www.omniref.com/ruby/gems/slim>
38
- * GitHub master: <http://rubydoc.info/github/slim-template/slim/master/frames> <https://www.omniref.com/github/slim-template/slim>
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="http://github.com/slim-template/slim" title='Slim のホームページ' Slim のホームページへ
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="http://github.com/slim-template/slim" title='Slim のホームページ' Slim のホームページへ
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="http://github.com/slim-template/slim/" github.com/slim-template/slim
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="http://github.com/slim-template/slim/">github.com/slim-template/slim</a>
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: 'http://github.com/slim-template/slim/'}
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="http://github.com/slim-template/slim/">リンク</a>
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 = { 'http://github.com/slim-template/slim' => 'The Slim Template Language' }
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: <http://github.com/slim-template/slim>
33
- * Source: <http://github.com/slim-template/slim>
34
- * Bugs: <http://github.com/slim-template/slim/issues>
35
- * List: <http://groups.google.com/group/slim-template>
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: <http://rubydoc.info/gems/slim/frames> <https://www.omniref.com/ruby/gems/slim>
38
- * GitHub master: <http://rubydoc.info/github/slim-template/slim/master/frames> <https://www.omniref.com/github/slim-template/slim>
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 treailing white space `|<` `|>` `|<>`
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="http://github.com/slim-template/slim" title='Slim Homepage' Goto the Slim homepage
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="http://github.com/slim-template/slim" title='Slim Homepage' Goto the Slim homepage
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="http://github.com/slim-template/slim/" github.com/slim-template/slim
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="http://github.com/slim-template/slim/">github.com/slim-template/slim</a>
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: 'http://github.com/slim-template/slim/'}
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="http://github.com/slim-template/slim/">Link</a>
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 = { 'http://github.com/slim-template/slim' => 'The Slim Template Language' }
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
  ~~~
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Slim
2
3
  # @api private
3
4
  class CodeAttributes < Filter
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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Slim
2
3
  # @api private
3
4
  class Controls < Filter
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Slim
2
3
  # In Slim you don't need the do keyword sometimes. This
3
4
  # filter adds the missing keyword.
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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Slim
2
3
  # In Slim you don't need to close any blocks:
3
4
  #
data/lib/slim/engine.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # The Slim module contains all Slim related classes (e.g. Engine, Parser).
2
3
  # Plugins might also reside within the Slim module (e.g. Include, Smart).
3
4
  # @api public
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'slim'
2
3
 
3
4
  module Slim
data/lib/slim/filter.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Slim
2
3
  # Base class for Temple filters used in Slim
3
4
  #
data/lib/slim/grammar.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Slim
2
3
  # Slim expression grammar
3
4
  # @api private
data/lib/slim/include.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'slim'
2
3
 
3
4
  module Slim
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Slim
2
3
  # Perform interpolation of #{var_name} in the
3
4
  # expressions `[:slim, :interpolate, string]`.
@@ -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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Slim
2
3
  # Handle logic less mode
3
4
  # This filter can be activated with the option "logic_less"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'slim'
2
3
  require 'slim/logic_less/filter'
3
4
  require 'slim/logic_less/context'
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*' << splat_prefix << '(?=[^\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
- shortcut.each {|a| attributes << [:html, :attr, a, [:static, $2]] }
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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Slim
2
3
  class Railtie < ::Rails::Railtie
3
4
  initializer "initialize slim template handler" do
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Slim
2
3
  module Smart
3
4
  # Perform smart entity escaping in the
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Slim
2
3
  module Smart
3
4
  # Perform newline processing in the
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Slim
2
3
  module Smart
3
4
  # @api private
data/lib/slim/smart.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'slim'
2
3
  require 'slim/smart/filter'
3
4
  require 'slim/smart/escaper'
@@ -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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Slim
2
3
  module Splat
3
4
  # @api private
data/lib/slim/template.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Slim
2
3
  # Tilt template implementation for Slim
3
4
  # @api public
@@ -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
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  module Slim
2
3
  # Slim version string
3
4
  # @api public
4
- VERSION = '5.1.0'
5
+ VERSION = '5.1.1'
5
6
  end
data/lib/slim.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'temple'
2
3
  require 'slim/parser'
3
4
  require 'slim/filter'
data/slim.gemspec CHANGED
@@ -19,5 +19,5 @@ Gem::Specification.new do |s|
19
19
  s.required_ruby_version = '>= 2.5.0'
20
20
 
21
21
  s.add_runtime_dependency('temple', ['~> 0.10.0'])
22
- s.add_runtime_dependency('tilt', ['>= 2.0.6', '< 2.2'])
22
+ s.add_runtime_dependency('tilt', ['>= 2.1.0'])
23
23
  end
data/test/core/helper.rb CHANGED
@@ -121,7 +121,7 @@ class Env
121
121
  end
122
122
 
123
123
  def hello_world(text = "Hello World from @env", opts = {})
124
- text << opts.to_a * " " if opts.any?
124
+ text = text + (opts.to_a * " ") if opts.any?
125
125
  if block_given?
126
126
  "#{text} #{yield} #{text}"
127
127
  else
@@ -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
- Slim::Engine.with_options(shortcut: {'@' => { attr: params[:attr] }}) do
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
@@ -0,0 +1,3 @@
1
+ / Exercises Temple `:capture` handling (used here for preparing HTML attributes) with the
2
+ / Rails-specific Temple generators
3
+ .static class="#{['a', 'b'].join('-')}"
@@ -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.0
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-03-06 00:00:00.000000000 Z
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.6
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.6
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