super-slim 3.6.2 → 3.6.3

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: cdd1bc27d23e754183cb4f4e4963a935d56d030a1b73d60bccfc4ee97f8972bc
4
- data.tar.gz: 2419f8247b33000daa959e96470679eb54ef778e5c82aa6c0555323e68e7ed02
3
+ metadata.gz: bdda53d82fc2a91f77cf19258e1ee428e89b765df89a9e91e93af3517a6c2f0f
4
+ data.tar.gz: 6998c577d2553c9ab39efc167c5bdbe576eecc891a959ec31d90b3ffc822c2bd
5
5
  SHA512:
6
- metadata.gz: 545d8dd22428f0a94ccb6e36c0f1108427ca607d6242abf1abe1dc69c9969ba6db04cef1404262017214599499813f0a028b3e2392fe17f48eb9a25e5746ef50
7
- data.tar.gz: 339168144fd87e1b8a6ef09e293c1f645d31c0da65c30c3fab686fa63dd6fb9debcbf5f63e92396c244031e75ca0c7aba202c9f9ea0cf0d94a6dd69ceca47018
6
+ metadata.gz: 2adce8b7a0578e7488852e04e267fd8ff964021f59719602be4e018583b1faae79a264c8f165148352ff1879c303957d582917c1d030eaa5d086d4404e505da4
7
+ data.tar.gz: 6d40b5b0e0d8e68655c74237d82cf89f9d9afb0fd2053bf89cfb987a53d670b403de410055a711b640fa4f431529afc3e753fadbbe3fe09a36dc1a7fa5ca4bf4
data/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [3.6.3] — 2026-11-21
6
+
7
+ One fix: a line break inside an interpolation of a quoted attribute no longer shifts the lines that follow.
8
+
9
+ **Fixed**
10
+ - A quoted attribute whose `#{…}` spans lines, such as `p title="#{t(:title,` then `count: 2)}"` on the next line,
11
+ no longer moves every later line one line down per break in backtraces, `__LINE__` and compile errors. The
12
+ attributes of a `ruby:` or `markdown:` block keep their lines too.
13
+
5
14
  ## [3.6.2] — 2026-11-20
6
15
 
7
16
  Template errors found while compiling now point at their template line, in Rails too.
@@ -321,7 +330,8 @@ renders what Slim 5 renders with `format: :html, sort_attrs: false`, byte for by
321
330
  - 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,
322
331
  newer than the one Ruby 3.3 ships.
323
332
 
324
- [Unreleased]: https://github.com/levups/super-slim/compare/v3.6.2...HEAD
333
+ [Unreleased]: https://github.com/levups/super-slim/compare/v3.6.3...HEAD
334
+ [3.6.3]: https://github.com/levups/super-slim/compare/v3.6.2...v3.6.3
325
335
  [3.6.2]: https://github.com/levups/super-slim/compare/v3.6.1...v3.6.2
326
336
  [3.6.1]: https://github.com/levups/super-slim/compare/v3.6.0...v3.6.1
327
337
  [3.6.0]: https://github.com/levups/super-slim/compare/v3.5.0...v3.6.0
data/README.md CHANGED
@@ -461,11 +461,11 @@ bin/release minor --dry-run # shows the notes and the changes, writes nothing
461
461
  bin/release minor # or patch, major, or an exact version such as 1.2.0
462
462
  ```
463
463
 
464
- Nobody pushes to `main` directly, so `bin/release` dates the Unreleased section and bumps the version on a
465
- `release/vX.Y.Z` branch, opens a pull request that merges itself once CI passes, and waits for it. It then pushes
466
- a signed `vX.Y.Z` tag on the merge commit (if you stopped it while it waited, `bin/release --tag X.Y.Z` does that
467
- step). The tag starts the Release workflow, which publishes the gem to RubyGems through trusted publishing and
468
- creates the GitHub release with the notes and the `.gem` file.
464
+ `main` takes no direct push, so `bin/release` dates the notes and bumps the version on a `release/vX.Y.Z` branch,
465
+ opens a pull request that merges itself once CI is green, and waits for it (`bin/release --wait X.Y.Z` if you
466
+ stopped it). The merge starts the Release workflow, which waits for a maintainer's approval, tags the merge commit
467
+ `vX.Y.Z`, publishes the gem to RubyGems through trusted publishing and creates the GitHub release with the notes
468
+ and the `.gem`.
469
469
 
470
470
  ## License
471
471
 
@@ -106,6 +106,13 @@ module SuperSlim
106
106
  parts
107
107
  end
108
108
 
109
+ # The line breaks inside the text's interpolations, which its compiled code keeps.
110
+ def self.interpolation_newlines(text)
111
+ return 0 unless text.include?("\n") && text.include?('#{')
112
+
113
+ interpolation_parts(text).sum { |kind, code| (kind == :dynamic) ? code.count("\n") : 0 }
114
+ end
115
+
109
116
  private
110
117
 
111
118
  def compile_children(nodes)
@@ -225,8 +232,8 @@ module SuperSlim
225
232
  next if attribute.name == "class"
226
233
  if seen_names.key?(attribute.name)
227
234
  # Reported on the last line of the attributes, like the tag's compiled code, which follows their code.
228
- code_newlines = attributes.sum { _1.is_a?(CodeAttribute) ? _1.code.count("\n") : 0 }
229
- compile_error!("Multiple #{attribute.name} attributes specified", lines_ahead: code_newlines)
235
+ lines_ahead = attributes.sum { |other| code_newlines(other) }
236
+ compile_error!("Multiple #{attribute.name} attributes specified", lines_ahead:)
230
237
  end
231
238
 
232
239
  seen_names[attribute.name] = true
@@ -385,6 +392,11 @@ module SuperSlim
385
392
  end
386
393
 
387
394
  def compile_embedded(embedded)
395
+ case embedded.engine
396
+ when "ruby", "markdown"
397
+ # Their attributes are dropped, and with them the lines their interpolations go on to.
398
+ @code << ("\n" * embedded.attributes.sum { code_newlines(_1) })
399
+ end
388
400
  case embedded.engine
389
401
  when "ruby" then compile_ruby(embedded.children)
390
402
  when "javascript" then compile_tag(Tag.new("script", embedded.attributes, [TextBlock.new(embedded.children)]))
@@ -439,6 +451,16 @@ module SuperSlim
439
451
  end
440
452
  end
441
453
 
454
+ # The lines an attribute's Ruby code goes on to: a code attribute's, and those of a quoted attribute's
455
+ # interpolations, which the parser leaves to the code.
456
+ def code_newlines(attribute)
457
+ case attribute
458
+ when CodeAttribute then attribute.code.count("\n")
459
+ when QuotedAttribute then Compiler.interpolation_newlines(attribute.text)
460
+ else 0
461
+ end
462
+ end
463
+
442
464
  # The compiled code keeps each template line on its own line, so the newlines written so far give the line of
443
465
  # the node being compiled: no node carries its line, which would cost every template line. Code not written
444
466
  # yet may still hold `lines_ahead` of them.
@@ -629,6 +629,7 @@ module SuperSlim
629
629
  first = source_offset if @outline
630
630
  value = +""
631
631
  depth = 0
632
+ breaks = 0
632
633
  quote_byte = quote.ord
633
634
 
634
635
  until depth == 0 && @scanner.peek_byte == quote_byte
@@ -636,7 +637,7 @@ module SuperSlim
636
637
  # Unlike a stripped continuation line, a line read whole keeps its trailing whitespace in the value.
637
638
  @outline[@lineno].text = true if @outline && @scanner.eos? && @scanner.string.equal?(@line)
638
639
  value << (@scanner.eos? ? "\n" : " ")
639
- @stacks.last << NEWLINE
640
+ breaks += 1
640
641
  expect_next_line
641
642
  elsif (chunk = @scanner.scan(QUOTED_CHUNK_BY_QUOTE[quote]))
642
643
  value << chunk
@@ -648,6 +649,9 @@ module SuperSlim
648
649
  end
649
650
  end
650
651
 
652
+ # A break inside an interpolation is already a line of the compiled code, which keeps it: only the others get
653
+ # a newline node.
654
+ (breaks - Compiler.interpolation_newlines(value)).times { @stacks.last << NEWLINE } if breaks > 0
651
655
  record_ruby(:text, first, source_offset) if @outline
652
656
  @scanner.pos += 1
653
657
  value
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SuperSlim
4
- VERSION = "3.6.2"
4
+ VERSION = "3.6.3"
5
5
  end
data/lib/super_slim.rb CHANGED
@@ -70,8 +70,9 @@ module SuperSlim
70
70
  # Located like the parser's errors, its backtrace starting at the template line, which Rails reports.
71
71
  def compile_syntax_error(exception, source, file)
72
72
  lineno = exception.lineno
73
- # The source parsed, so it is valid UTF-8 whatever its encoding says. A construct whose compiled code takes
74
- # more lines than its template can move the count past the end: the error still raises, without that line.
73
+ # The source parsed, so it is valid UTF-8 whatever its encoding says. A count past the end guards against
74
+ # compiled code taking more lines than its template, which no construct is known to do: the error still
75
+ # raises, without that line.
75
76
  line = String.new(Parser.split_lines(source.b)[lineno - 1].to_s, encoding: Encoding::UTF_8)
76
77
  line = line.delete_prefix("") if lineno == 1
77
78
  error = SyntaxError.new(exception.message, file, line, lineno, line[/\A[ \t]*/].size)
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.6.2
4
+ version: 3.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Level UP Solutions