super-slim 3.2.0 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f7d1e689786582fc22547722bf3b3ef03847b976163b3560c48a9ab06e8178e
4
- data.tar.gz: 7b422a5d70567feef50061078f19bceb966fb7d6363c9fc48040fae004335f34
3
+ metadata.gz: e61c8e5ff4dbffc6d96f83c16093ab70e01bebf2c943e42f22a580ee623f860f
4
+ data.tar.gz: 439ae6165f61cdd7f434b726d633153b5ae8e9e63e7b52420e34ed84b9c91b2e
5
5
  SHA512:
6
- metadata.gz: e5578534152295f0f13694febb4b5f54fa2c6b72a3e9ce0852f0ea45cbbe200f782bf51d6eb1ec19f3f798d9117351e62d3b2fdd9096d9e4cb016c12da51f198
7
- data.tar.gz: dcef262dc4ff56c2e908d9a57e55b77818370fe2057685e4084b31e1f1d056e9bf66108487000e2f5ecec4f5a00a0027c4127c311e611cc0f7aa5718a0f5a413
6
+ metadata.gz: 17d2f764fefb35db24a26671a43aa27ec0e9df38d54e583cf7ef432a3fe2c386082edadf20a74d60a55d8d2673ed0af130ae84fa60a4bf13b29c9cc063fc95f2
7
+ data.tar.gz: 2d2a726a40e22a75158a61091fc65234d8ec3e68077e1d14277db3746dcfedfa148014978c34c9fc90cf73a4aed9ddf342dab91ec1e432fae0e56a9377e13323
data/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [3.2.1] — 2026-11-06
6
+
7
+ A comment after Ruby code no longer breaks the template.
8
+
9
+ **Fixed**
10
+ - A comment that ends a line of Ruby code, as in
11
+ `= render CardComponent.new(post:) # rubocop:disable Some/Cop -- reason`,
12
+ no longer makes the template a syntax error: it is left out of the
13
+ compiled Ruby, after `=`, `==` and `-` alike, so a RuboCop directive can
14
+ sit on the line it is about. Slim refuses these lines.
15
+
5
16
  ## [3.2.0] — 2026-11-06
6
17
 
7
18
  One layout per line and per tag in `super-slim format`, cache digests that follow Slim partials, and a faster lint.
@@ -172,7 +183,8 @@ renders what Slim 5 renders with `format: :html, sort_attrs: false`, byte for by
172
183
  - Ruby 3.3 or later, every Ruby still maintained, Rails 8.0 or 8.1 for the railtie, and strscan 3.1.1 or later,
173
184
  newer than the one Ruby 3.3 ships.
174
185
 
175
- [Unreleased]: https://github.com/levups/super-slim/compare/v3.2.0...HEAD
186
+ [Unreleased]: https://github.com/levups/super-slim/compare/v3.2.1...HEAD
187
+ [3.2.1]: https://github.com/levups/super-slim/compare/v3.2.0...v3.2.1
176
188
  [3.2.0]: https://github.com/levups/super-slim/compare/v3.1.1...v3.2.0
177
189
  [3.1.1]: https://github.com/levups/super-slim/compare/v3.1.0...v3.1.1
178
190
  [3.1.0]: https://github.com/levups/super-slim/compare/v3.0.0...v3.1.0
data/README.md CHANGED
@@ -249,7 +249,7 @@ attributes and whitespace markers (`span> title="x" = name`), so you may see a f
249
249
 
250
250
  ## Additions to Slim
251
251
 
252
- Two additions read templates that Slim refuses or misreads. Neither changes a template that already works with
252
+ Three additions read templates that Slim refuses or misreads. None changes a template that already works with
253
253
  Slim.
254
254
 
255
255
  ### Ruby code over several lines
@@ -271,6 +271,13 @@ an opening `(`, `[` or `{` at the end of a line, until the bracket is closed:
271
271
  A bracket opened in the middle of a line, as in `- items.each { |item|`, works as before: the lines below it are
272
272
  its children.
273
273
 
274
+ ### Comments after Ruby code
275
+
276
+ Slim compiles `= render CardComponent.new(post:) # rubocop:disable Some/Cop -- reason` into a syntax error: the
277
+ comment swallows the parenthesis that closes the output, or the `do` of a block. SuperSlim leaves a comment that
278
+ follows code on its line out of the compiled Ruby, after `=`, `==` and `-` alike, so a RuboCop directive can sit on
279
+ the line it is about.
280
+
274
281
  ### Tailwind class names
275
282
 
276
283
  Slim stops a `.class` shortcut at characters such as `[`, `:` or `/`, which Tailwind uses all the time. It renders
@@ -149,9 +149,22 @@ module SuperSlim
149
149
  end
150
150
 
151
151
  def with_do(code, children)
152
+ code = without_trailing_comment(code)
152
153
  (code.match?(BLOCK_SELF_OPENING) || AST.empty?(children)) ? code : "#{code} do"
153
154
  end
154
155
 
156
+ # A comment that ends the code would swallow what the compiler writes after it, such as the closing
157
+ # parenthesis of an output or the `do` of a block. It never runs, so it is left out. One alone on a line
158
+ # stays: a backslash before it carries the code on to that line.
159
+ def without_trailing_comment(code)
160
+ return code unless code.include?("#")
161
+
162
+ comment_offset = Parser::RubyBrackets.new(code).trailing_comment_offset or return code
163
+
164
+ code_before = code.byteslice(0, comment_offset).sub(/[ \t]+\z/, "")
165
+ (code_before.empty? || code_before.end_with?("\n")) ? code : code_before
166
+ end
167
+
155
168
  def compile_tag(tag)
156
169
  return compile_dynamic_tag(tag) if tag.name == "*"
157
170
 
@@ -3,7 +3,7 @@
3
3
  module SuperSlim
4
4
  class Parser
5
5
  # Read by hand, a line at a time: Prism would cost every process that renders templates its load time and memory.
6
- # Misread, all rare after a bracket that ends its line: heredocs, `?(`, `$'`, a regexp after a method name or a
6
+ # Misread, all rare after a bracket that ends its line or before a comment that ends the code: heredocs, `?(`, `$'`, a regexp after a method name or a
7
7
  # keyword (`when /'/`), `%` glued to a value (`"%d"%[a]`), interpolation in a %-literal and %-literals between
8
8
  # other delimiters (`%|a(|`).
9
9
  class RubyBrackets
@@ -28,7 +28,11 @@ module SuperSlim
28
28
  read
29
29
  end
30
30
 
31
+ # The byte offset of the comment that ends the code, if one does.
32
+ attr_reader :trailing_comment_offset
33
+
31
34
  def <<(line)
35
+ @trailing_comment_offset = nil
32
36
  @scanner << "\n" << line
33
37
  read
34
38
  self
@@ -63,7 +67,10 @@ module SuperSlim
63
67
  when '"', "'", "`" then return @literals << character
64
68
  when "/" then return @literals << character if regexp_start?
65
69
  when "%" then return open_percent_literal if @scanner.scan(PERCENT_LITERAL_OPENING)
66
- when "#" then @scanner.skip_until(LINE_END)
70
+ when "#"
71
+ comment_offset = @scanner.pos - 1
72
+ @scanner.skip_until(LINE_END)
73
+ @trailing_comment_offset = comment_offset if @scanner.eos?
67
74
  end
68
75
  end
69
76
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SuperSlim
4
- VERSION = "3.2.0"
4
+ VERSION = "3.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super-slim
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Level UP Solutions