super-slim 3.7.0 → 3.8.0

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: 52391ec6b8e744b8b883f3f2c7673b0d16c64156869d2d529d4bf37f0d0502cc
4
- data.tar.gz: bb76a49c673a063e5d8cae8d7a2829776885894673623ba8ee08689533e0be4b
3
+ metadata.gz: c62c06c47157da25a9d318b8f1b29d044f3354034eb96321c6b884532866301f
4
+ data.tar.gz: 6587e5102eff9f73b36351dbbdec7cf419a85785dbb7ba4dc6fd85620f828aaf
5
5
  SHA512:
6
- metadata.gz: 4b2fe8cf05a6937e42c9bb4e376f34981d9dd0cf522e9b131e0f471d14e612bcc47bb917f789200357824536644a8325f5edf8cc208c73e191a84afb6df97109
7
- data.tar.gz: a7eba7d8442da3a42c4b97b6d264c69d0d873ed1df12f91c56928361b4af8ae0c2dc1651a65556f83223e4d2592529633702d18101ae23871de09f49312c7377
6
+ metadata.gz: 069404facc261d86666252ef43a693760a262cd0d5974242be6a98d67c7ee6e188752216fe25000c1a3f6fa02e10f8233e908ceec625e9fdd911f916777431e4
7
+ data.tar.gz: bbd35b5adb251e1e0005b7308a3d91a832e7c85b64e2306d75b09e3195a2858ff19a72c2e6fc1c11d65b002911c6106fd0c9b4824f79cdcb29879140ac3c358b
data/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [3.8.0] — 2026-11-26
6
+
7
+ SuperSlim now works from any Ractor, and the formatter and the linter load on their own.
8
+
9
+ **New**
10
+ - Compiling, rendering, formatting and linting work from any Ractor, with the same result as on the main one.
11
+ Outside the main Ractor, escaping needs erb 5.0.2 and parsing Prism 1.5, which Ruby 4.0 ships: Ruby 3.3 and 3.4
12
+ need `gem "erb"` in the Gemfile, and `gem "prism"` when theirs is older. Ruby 3.3, which can't autoload outside
13
+ the main Ractor, needs `require "super_slim/formatter"` on the main Ractor first. A `markdown:` block still
14
+ compiles on the main Ractor only. The constants under `SuperSlim` are now deeply frozen, nested values included.
15
+
16
+ **Fixed**
17
+ - `require "super_slim/formatter"` and `require "super_slim/linter"` work without `require "super_slim"` first: the
18
+ formatter raised `NameError` while loading, and the linter on its first call. Requiring the formatter after the
19
+ engine no longer warns of a circular require under `ruby -w`.
20
+
5
21
  ## [3.7.0] — 2026-11-24
6
22
 
7
23
  Faster rendering of splats and data hashes, faster compiling, and one fix.
@@ -345,7 +361,8 @@ renders what Slim 5 renders with `format: :html, sort_attrs: false`, byte for by
345
361
  - 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,
346
362
  newer than the one Ruby 3.3 ships.
347
363
 
348
- [Unreleased]: https://github.com/levups/super-slim/compare/v3.7.0...HEAD
364
+ [Unreleased]: https://github.com/levups/super-slim/compare/v3.8.0...HEAD
365
+ [3.8.0]: https://github.com/levups/super-slim/compare/v3.7.0...v3.8.0
349
366
  [3.7.0]: https://github.com/levups/super-slim/compare/v3.6.3...v3.7.0
350
367
  [3.6.3]: https://github.com/levups/super-slim/compare/v3.6.2...v3.6.3
351
368
  [3.6.2]: https://github.com/levups/super-slim/compare/v3.6.1...v3.6.2
data/README.md CHANGED
@@ -10,6 +10,9 @@ parser, so they never disagree with it about what a template means.
10
10
 
11
11
  Website and guide: https://levups.github.io/super-slim/
12
12
 
13
+ Coding agents can start from <https://levups.github.io/super-slim/llms.txt>, or read this README and the
14
+ website's pages as one Markdown file: <https://levups.github.io/super-slim/llms-full.txt>.
15
+
13
16
  ## Why SuperSlim
14
17
 
15
18
  A template engine does two jobs. It compiles each template into Ruby code, which Rails does the first time a
@@ -17,19 +20,19 @@ template renders and again after you edit it in development. Then it runs that c
17
20
  makes both cheaper.
18
21
 
19
22
  `bench/compare.rb` renders the same blog page (24 post cards) with five engines and checks that they all produce
20
- the same HTML. On the last run (November 2026, Ruby 4.0 with YJIT), SuperSlim compiled the page 9.3 times faster
21
- than Slim and rendered it 2.3 times faster, with a quarter of the allocations:
23
+ the same HTML. On the last run (November 2026, Ruby 4.0 with YJIT), SuperSlim compiled the page 11 times faster
24
+ than Slim and rendered it 2.2 times faster, with a quarter of the allocations:
22
25
 
23
26
  | Engine | Compiles per second | Renders per second | Objects allocated per render |
24
27
  |---|---:|---:|---:|
25
- | SuperSlim 1.0.0 | 12,423 | 60,725 | 111 |
26
- | Slim 5.2.2 | 1,341 | 26,786 | 480 |
27
- | Haml 7.5.2 | 1,559 | 37,704 | 471 |
28
- | Herb 0.11.1 | 5,600 | 17,496 | 830 |
29
- | Erubi 1.13.1 (ERB) | 51,144 | 62,746 | 115 |
30
-
31
- On whole apps, the 1,399 templates of a production Rails app compile in 108 ms instead of 522 ms, and 6,053
32
- templates from 30 open-source projects in 529 ms instead of 2,472 ms. The linter takes about a third of the CPU
28
+ | SuperSlim 3.7.0 | 16,384 | 69,202 | 111 |
29
+ | Slim 5.2.2 | 1,441 | 31,452 | 480 |
30
+ | Haml 7.5.2 | 1,772 | 42,477 | 471 |
31
+ | Herb 0.11.2 | 6,478 | 19,513 | 830 |
32
+ | Erubi 1.13.1 (ERB) | 56,668 | 68,360 | 115 |
33
+
34
+ On whole apps, the 1,214 templates of a production Rails app compile in 69 ms instead of 361 ms, and 6,056
35
+ templates from 30 open-source projects in 421 ms instead of 2,309 ms. The linter takes about half the CPU
33
36
  time slim-lint takes on the same templates. The [benchmarks page](https://levups.github.io/super-slim/benchmarks.html)
34
37
  has the charts and the steps to reproduce them.
35
38
 
@@ -66,6 +69,11 @@ ruby_code = SuperSlim.compile(File.read("page.slim"), file: "page.slim") # file:
66
69
  html = eval(ruby_code, binding)
67
70
  ```
68
71
 
72
+ SuperSlim compiles, renders, formats and lints from any Ractor. Outside the main Ractor, escaping needs erb 5.0.2
73
+ or later and parsing Prism 1.5 or later: Ruby 4.0 ships both. Ruby 3.3 and 3.4 need `gem "erb"` in your Gemfile,
74
+ and `gem "prism"` too when theirs is older (Ruby 3.4.0 ships Prism 1.2, Ruby 3.4.8 1.5.2). Ruby 3.3 also can't autoload outside the main Ractor: `require "super_slim/formatter"` there
75
+ first. A `markdown:` block compiles on the main Ractor only, as markly can't leave it.
76
+
69
77
  ## A first template
70
78
 
71
79
  ```slim
@@ -97,6 +105,9 @@ defaults are different (`format: :xhtml, sort_attrs: true`), so if you never cha
97
105
  2. Replace `slim-rails` with `super-slim` in your Gemfile and remove any `Slim::Engine.set_options` or
98
106
  `with_options` call.
99
107
 
108
+ To hand the migration to a coding agent, the website has [a prompt](https://levups.github.io/super-slim/migrate.html#agents)
109
+ that takes it step by step, one commit each, through the linter and formatter switch.
110
+
100
111
  Templates for XML formats (`.xml`, `.rss`, `.atom`) render as XML automatically, with `<link />` and
101
112
  `doctype xml`.
102
113
 
@@ -381,7 +392,8 @@ unquoted attribute of inline HTML, or in the URL of a `markdown:` link can still
381
392
 
382
393
  ## What SuperSlim leaves out
383
394
 
384
- These parts of Slim aren't supported. Each one fails when the template compiles, with an error that names it:
395
+ These parts of Slim aren't supported. Each one fails when the template compiles, with an error that names it, except a custom
396
+ shortcut written after a tag (`input&text`), which reads as text:
385
397
 
386
398
  - the XHTML format, the `sort_attrs`, `attr_quote`, `pretty` and `js_wrapper` options, and every Temple option;
387
399
  - the `coffee:`, `sass:`, `scss:`, `less:`, `erb:`, `builder:`, `textile:`, `rdoc:`, `asciidoc:` and wiki
@@ -395,7 +407,7 @@ come back if people ask for them, as long as they don't slow down rendering.
395
407
 
396
408
  ## Learn more
397
409
 
398
- The website has a [guide](https://levups.github.io/super-slim/guide.html) with every option, a page on the
410
+ The website has [a step-by-step switch from Slim](https://levups.github.io/super-slim/migrate.html), a [guide](https://levups.github.io/super-slim/guide.html) with every option, a page on the
399
411
  [formatter and linter](https://levups.github.io/super-slim/tools.html) with an example for each rule, the
400
412
  [benchmarks](https://levups.github.io/super-slim/benchmarks.html) and the
401
413
  [test setup](https://levups.github.io/super-slim/testing.html). [CHANGELOG.md](CHANGELOG.md) lists the changes in
data/lib/super-slim.rb CHANGED
@@ -2,3 +2,5 @@
2
2
 
3
3
  # Bundler requires a gem by its name: super-slim, then super/slim.
4
4
  require_relative "super_slim"
5
+ # Again here: when the linter or the formatter was required before Rails, super_slim.rb ran without Rails.
6
+ require_relative "super_slim/railtie" if defined?(Rails::Railtie)
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # shareable_constant_value: experimental_everything
2
3
 
3
4
  require "tempfile"
4
5
  require_relative "../super_slim"
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # shareable_constant_value: experimental_everything
2
3
 
3
4
  require "strscan"
4
5
 
@@ -1,6 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "prism"
4
+ require_relative "../super_slim"
5
+
6
+ module SuperSlim
7
+ # Defined here before the files below reopen it: from them, the autoload of SuperSlim::Formatter would load this
8
+ # file again, a circular require.
9
+ class Formatter; end
10
+ end
11
+
4
12
  require_relative "formatter/attribute_arranger"
5
13
  require_relative "formatter/code_wrapper"
6
14
  require_relative "formatter/line_wrapper"
@@ -410,13 +418,14 @@ module SuperSlim
410
418
  # a deep template would exhaust Ruby's.
411
419
  def same_node?(node, other_node)
412
420
  pending_values = [node, other_node]
421
+ comparator_by_node_class = Formatter.send(:ractor_cache, :COMPARATOR_BY_NODE_CLASS)
413
422
  until pending_values.empty?
414
423
  other_value = pending_values.pop
415
424
  value = pending_values.pop
416
425
  case value
417
426
  when Prism::Node
418
427
  if value.instance_of?(other_value.class)
419
- return false unless node_comparator(value).call(value, other_value, pending_values)
428
+ return false unless node_comparator(value, comparator_by_node_class).call(value, other_value, pending_values)
420
429
  else
421
430
  pairs = negated_if_pairs(value, other_value) or return false
422
431
  pending_values.concat(pairs)
@@ -451,13 +460,21 @@ module SuperSlim
451
460
  [negation.receiver, unless_node.predicate, if_node.statements, unless_node.statements]
452
461
  end
453
462
 
454
- def node_comparator(node)
455
- COMPARATOR_BY_NODE_CLASS[node.class] ||= Formatter.send(:comparator_for, node.class, *node_fields(node))
463
+ def node_comparator(node, comparator_by_node_class)
464
+ comparator_by_node_class[node.class] ||= Formatter.send(:comparator_for, node.class, *node_fields(node))
456
465
  end
457
466
 
458
467
  class << self
459
468
  private
460
469
 
470
+ # The constant on the main Ractor, shared by every formatter. Another Ractor can't read a mutable constant: it
471
+ # fills caches of its own. TruffleRuby has no Ractor.
472
+ def ractor_cache(name)
473
+ return const_get(name) if !defined?(Ractor) || Ractor.current == Ractor.main
474
+
475
+ Ractor.current[:"super_slim_#{name.downcase}"] ||= {}
476
+ end
477
+
461
478
  # Compares what two nodes of one class hold besides their children, and pushes their children on `pending_values`.
462
479
  def comparator_for(node_class, field_names, located_names, flagged)
463
480
  if node_class <= Prism::SourceLineNode
@@ -503,7 +520,7 @@ module SuperSlim
503
520
  # 2026-11: Prism 0.19 (Ruby 3.3) has no reflection API: the field names come from the first node of each
504
521
  # class. Prism 1.x keeps flags out of deconstruct_keys.
505
522
  def node_fields(node)
506
- FIELDS_BY_NODE_CLASS[node.class] ||= begin
523
+ Formatter.send(:ractor_cache, :FIELDS_BY_NODE_CLASS)[node.class] ||= begin
507
524
  keys = node.deconstruct_keys(nil).keys
508
525
  located_names, field_names = (keys - %i[node_id flags location])
509
526
  .reject { _1.end_with?("_loc") }
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # shareable_constant_value: experimental_everything
2
3
 
3
4
  module SuperSlim
4
5
  class Linter
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # shareable_constant_value: experimental_everything
2
3
 
3
4
  require "prism"
4
5
 
@@ -17,8 +18,9 @@ module SuperSlim
17
18
  DEFAULTS = {enabled: true}.freeze
18
19
  GLOB_FLAGS = File::FNM_PATHNAME | File::FNM_EXTGLOB | File::FNM_DOTMATCH
19
20
 
21
+ # Not memoized: a Ractor other than the main one can't set a class's instance variable.
20
22
  def self.rule_name
21
- @rule_name ||= name.split("::").last
23
+ name.split("::").last
22
24
  end
23
25
 
24
26
  def initialize(options)
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
+ # shareable_constant_value: experimental_everything
2
3
 
3
4
  require "yaml"
5
+ require_relative "../super_slim"
4
6
 
5
7
  module SuperSlim
6
8
  class Linter
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "set" # rubocop:disable Lint/RedundantRequireStatement -- 2026-11: Ruby 3.3 can't autoload Set outside the main Ractor
3
4
  require "strscan"
4
5
  require_relative "parser/ruby_brackets"
5
6
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SuperSlim
4
- VERSION = "3.7.0"
4
+ VERSION = "3.8.0"
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.7.0
4
+ version: 3.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Level UP Solutions
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  - !ruby/object:Gem::Version
85
85
  version: "0"
86
86
  requirements: []
87
- rubygems_version: 4.1.0
87
+ rubygems_version: 4.1.1
88
88
  specification_version: 4
89
89
  summary: "A Slim template engine that compiles and renders faster, with a formatter and a linter"
90
90
  test_files: []