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 +4 -4
- data/CHANGELOG.md +18 -1
- data/README.md +24 -12
- data/lib/super-slim.rb +2 -0
- data/lib/super_slim/cli.rb +1 -0
- data/lib/super_slim/compiler.rb +1 -0
- data/lib/super_slim/formatter.rb +21 -4
- data/lib/super_slim/linter/presets.rb +1 -0
- data/lib/super_slim/linter/rules.rb +3 -1
- data/lib/super_slim/linter.rb +2 -0
- data/lib/super_slim/parser.rb +1 -0
- data/lib/super_slim/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c62c06c47157da25a9d318b8f1b29d044f3354034eb96321c6b884532866301f
|
|
4
|
+
data.tar.gz: 6587e5102eff9f73b36351dbbdec7cf419a85785dbb7ba4dc6fd85620f828aaf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
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
|
|
21
|
-
than Slim and rendered it 2.
|
|
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
|
|
26
|
-
| Slim 5.2.2 | 1,
|
|
27
|
-
| Haml 7.5.2 | 1,
|
|
28
|
-
| Herb 0.11.
|
|
29
|
-
| Erubi 1.13.1 (ERB) |
|
|
30
|
-
|
|
31
|
-
On whole apps, the 1,
|
|
32
|
-
templates from 30 open-source projects in
|
|
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)
|
data/lib/super_slim/cli.rb
CHANGED
data/lib/super_slim/compiler.rb
CHANGED
data/lib/super_slim/formatter.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
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
|
-
|
|
23
|
+
name.split("::").last
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
def initialize(options)
|
data/lib/super_slim/linter.rb
CHANGED
data/lib/super_slim/parser.rb
CHANGED
data/lib/super_slim/version.rb
CHANGED
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.
|
|
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.
|
|
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: []
|