super-slim 3.1.0 → 3.2.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: 4e7f0253bc3700761d1b9a6bf57e24b51766356d4e1e761cfe60961d5c612cf9
4
- data.tar.gz: 82d037bf08dfcf4ddf1ad0a9f0f10a874c29835e1e6b485cb4f8e7a735effcf8
3
+ metadata.gz: 4f7d1e689786582fc22547722bf3b3ef03847b976163b3560c48a9ab06e8178e
4
+ data.tar.gz: 7b422a5d70567feef50061078f19bceb966fb7d6363c9fc48040fae004335f34
5
5
  SHA512:
6
- metadata.gz: 00fb7c76fae6fe6d7c53e5f56dc8650d90b0b88f9c1776810fd22128e86a07299abf45185de83d8f3cfc8c6f8ae92a8d00d037520b4c180f508d6f4d6c856a9e
7
- data.tar.gz: cc96f26b0a002aec9005bb54ce6703c77b7ce291128e1f67668a29f8e31391929802eca7cbc4ad22adb2d41a0c492eca3a457dedbf14c564c377d53a01c70d19
6
+ metadata.gz: e5578534152295f0f13694febb4b5f54fa2c6b72a3e9ce0852f0ea45cbbe200f782bf51d6eb1ec19f3f798d9117351e62d3b2fdd9096d9e4cb016c12da51f198
7
+ data.tar.gz: dcef262dc4ff56c2e908d9a57e55b77818370fe2057685e4084b31e1f1d056e9bf66108487000e2f5ecec4f5a00a0027c4127c311e611cc0f7aa5718a0f5a413
data/CHANGELOG.md CHANGED
@@ -2,6 +2,50 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [3.2.0] — 2026-11-06
6
+
7
+ One layout per line and per tag in `super-slim format`, cache digests that follow Slim partials, and a faster lint.
8
+
9
+ **New**
10
+ - With `max_line_length`, `super-slim format` gives each line one layout: Ruby code spread over several lines is
11
+ joined back when it fits, and a longer call spreads its arguments one per line between parentheses, each followed
12
+ by a comma. Code spread by hand stays as it is when this layout would pass the limit.
13
+ - A tag's attributes stand without delimiters when they fit on its line, and one per line inside
14
+ `attribute_delimiters` when they don't. A literal `id` or `class` becomes a shortcut, a repeated class shortcut
15
+ goes, and attributes follow one order, from `id` and `class` to `aria-*` and `role`. The formatter takes attribute
16
+ values to have no side effects.
17
+
18
+ **Faster**
19
+ - `super-slim lint` is 11 to 22% faster, and finding templates from an app's root skips `node_modules` and `tmp`:
20
+ twice as fast.
21
+
22
+ **Fixed**
23
+ - The digest of a `cache` block in a Slim view now follows the partials it renders, as in ERB: a changed partial
24
+ no longer serves a stale fragment. A partial whose name is computed needs `/# Template Dependency: path`. Each
25
+ such fragment is rebuilt once after the upgrade, and Rails 8.0 processes without eager loading now load Prism
26
+ with Action View.
27
+ - The RuboCop plugin's autocorrect works on templates with CRLF line endings, and `super-slim format` keeps the
28
+ spaces a line renders.
29
+
30
+ ## [3.1.1] — 2026-11-06
31
+
32
+ Two ways for data to inject markup closed, hostile templates read in linear time, and Prism kept out of rendering.
33
+
34
+ **Fixed**
35
+ - Loading SuperSlim no longer loads Prism, which only `super-slim format` needs: since 3.1.0, every process that
36
+ loaded the gem, each Puma worker included, paid Prism's load time and about 7 MB.
37
+ - A tab, line feed, form feed or carriage return in a `*splat` or `data`/`aria` key raises
38
+ `InvalidAttributeNameError` instead of ending the attribute name, and `*{tag: …}` raises the new
39
+ `InvalidTagNameError` when its value is not a tag name: both let data inject markup, as in Slim 5.2.2. No valid
40
+ page changes.
41
+ - Hostile templates no longer hang or crash the compiler, `lint`, `format` or the RuboCop plugin: nested `#{`, long
42
+ continued code and deep nesting are read in linear time, and tags nested more than 500 levels deep are a syntax
43
+ error.
44
+ - On a hostile checkout, the CLI skips symlinks, FIFOs and devices, writes atomically and escapes control
45
+ characters in what it prints; a malformed `.super-slim.yml` is a usage error that names the setting.
46
+ - `super-slim format` refuses a wrap of a template that doesn't compile and a move of `__LINE__`, and its check
47
+ works on Prism 0.19 (Ruby 3.3) and Prism 2.
48
+
5
49
  ## [3.1.0] — 2026-11-06
6
50
 
7
51
  A Bootstrap 5 preset for the linter, Ruby code that continues after an open bracket, and a faster formatter.
@@ -128,7 +172,9 @@ renders what Slim 5 renders with `format: :html, sort_attrs: false`, byte for by
128
172
  - 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,
129
173
  newer than the one Ruby 3.3 ships.
130
174
 
131
- [Unreleased]: https://github.com/levups/super-slim/compare/v3.1.0...HEAD
175
+ [Unreleased]: https://github.com/levups/super-slim/compare/v3.2.0...HEAD
176
+ [3.2.0]: https://github.com/levups/super-slim/compare/v3.1.1...v3.2.0
177
+ [3.1.1]: https://github.com/levups/super-slim/compare/v3.1.0...v3.1.1
132
178
  [3.1.0]: https://github.com/levups/super-slim/compare/v3.0.0...v3.1.0
133
179
  [3.0.0]: https://github.com/levups/super-slim/compare/v2.2.0...v3.0.0
134
180
  [2.2.0]: https://github.com/levups/super-slim/compare/v2.1.0...v2.2.0
data/README.md CHANGED
@@ -1,134 +1,200 @@
1
1
  # SuperSlim
2
2
 
3
- A Slim template engine rewritten from scratch: no Temple, no filter pipeline, a single-pass compiler and a
4
- render-time runtime of a few methods. Templates written for [Slim](https://github.com/slim-template/slim) 5
5
- render byte for byte the same, faster, with fewer allocations.
3
+ SuperSlim renders [Slim](https://github.com/slim-template/slim) templates in Ruby and Rails apps. Slim is a template
4
+ language that writes HTML with indentation instead of closing tags, and SuperSlim is a new engine for it, written
5
+ from scratch: your existing `.slim` files produce the same HTML, but they compile about nine times faster and
6
+ render about twice as fast.
6
7
 
7
- https://levups.github.io/super-slim/
8
+ It also comes with a formatter, a linter and a RuboCop plugin. All three read templates with the engine's own
9
+ parser, so they never disagree with it about what a template means.
10
+
11
+ Website and guide: https://levups.github.io/super-slim/
12
+
13
+ ## Why SuperSlim
14
+
15
+ A template engine does two jobs. It compiles each template into Ruby code, which Rails does the first time a
16
+ template renders and again after you edit it in development. Then it runs that code on every request. SuperSlim
17
+ makes both cheaper.
18
+
19
+ `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:
22
+
23
+ | Engine | Compiles per second | Renders per second | Objects allocated per render |
24
+ |---|---:|---:|---:|
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
33
+ time slim-lint takes on the same templates. The [benchmarks page](https://levups.github.io/super-slim/benchmarks.html)
34
+ has the charts and the steps to reproduce them.
8
35
 
9
36
  ## Installation
10
37
 
38
+ SuperSlim needs Ruby 3.3 or later. In a Rails app, add it to your Gemfile, and remove `slim-rails` if you have it:
39
+ SuperSlim replaces it.
40
+
11
41
  ```ruby
12
- # Gemfile
13
- gem "super-slim" # instead of slim-rails
42
+ gem "super-slim"
14
43
  ```
15
44
 
16
- ## Usage
45
+ Rails then renders every `.slim` view with SuperSlim, and the digest of a `cache` block changes when a partial it
46
+ renders changes. A partial whose name is computed needs a `/# Template Dependency: orders/line` comment, as in ERB.
47
+ There is nothing to configure. Rails itself is optional, and SuperSlim is tested on Rails 8.0 and later.
17
48
 
18
- Rails picks it up through its railtie. Outside Rails, `SuperSlim.compile(source)` returns the Ruby code.
49
+ Without Rails, `SuperSlim.compile` turns a template into Ruby code, which you evaluate where the template's
50
+ variables and methods are defined:
19
51
 
20
- ## What SuperSlim renders
52
+ ```ruby
53
+ require "super_slim"
21
54
 
22
- HTML5, with attributes in the order you write them — what Slim renders with
23
- `format: :html, sort_attrs: false`. Templates whose format is XML (`.xml`, `.rss`, `.atom`) render as XML
24
- (`<link />`, `doctype xml`) from their format alone.
55
+ ruby_code = SuperSlim.compile(File.read("page.slim"), file: "page.slim") # file: is shown in errors and backtraces
56
+ html = eval(ruby_code, binding)
57
+ ```
25
58
 
26
- The whole Slim 5 grammar is supported: tags and `#id`/`.class` shortcuts, attributes with
27
- any delimiter, boolean attributes, `*splat`, `data`/`aria` hashes, `class` merging, `<`/`>` whitespace
28
- markers, `|` and `'` text, inline HTML, `/` and `/!` comments, `-` control code, `=`/`==` output, `#{}` and
29
- `#{{}}` interpolation, Slim's doctypes (`html`, `transitional` for email clients, their XHTML versions in XML
30
- templates), and the `ruby:`, `javascript:`, `css:` and `markdown:` (through
31
- [Markly](https://github.com/ioquatix/markly)) embedded engines.
59
+ ## A first template
32
60
 
33
- ## Ruby code over several lines
61
+ ```slim
62
+ ul.posts
63
+ - posts.each do |post|
64
+ li
65
+ a href=post.url = post.title
66
+ - if post.draft?
67
+ span.badge Draft
68
+ ```
34
69
 
35
- Slim continues a line of Ruby code after a comma or a backslash. SuperSlim also continues it after a `(`, `[` or `{`
36
- that ends the line, until that bracket closes, so calls, arrays and hashes can open on one line and close on their
37
- own:
70
+ With two posts, the second one a draft, this renders:
38
71
 
39
- ```slim
40
- = render ProductCardComponent.new(
41
- product:,
42
- variant: :compact,
43
- )
44
- - columns = %w[
45
- name
46
- price
47
- ]
72
+ ```html
73
+ <ul class="posts"><li><a href="/posts/1">Hello &amp; welcome</a></li><li><a href="/posts/2">Next steps</a><span class="badge">Draft</span></li></ul>
48
74
  ```
49
75
 
50
- Slim refuses these lines, so no template that works with Slim changes. A bracket opened mid-line, as in
51
- `- items.each { |item|`, still leaves the lines below it as children.
76
+ Lines starting with `-` run Ruby, `=` outputs the result of Ruby code (escaped for HTML), and everything else is a
77
+ tag, text or an attribute. The [Slim documentation](https://github.com/slim-template/slim#readme) describes the whole
78
+ language. SuperSlim reads all of it, except the few parts listed in [What SuperSlim leaves out](#what-superslim-leaves-out).
52
79
 
53
- ## Tailwind class names
80
+ ## Switching from Slim
54
81
 
55
- Slim cuts `.rounded-b-[3px]` at the bracket, and refuses `.lg:[&:nth-child(3)]:hover:underline`. Turn on
56
- `tailwind_classes` and the `.` shortcut takes any Tailwind class name:
82
+ SuperSlim renders what Slim renders with the options `format: :html, sort_attrs: false`, byte for byte. Slim's
83
+ defaults are different (`format: :xhtml, sort_attrs: true`), so if you never changed them, switch in two steps:
84
+
85
+ 1. Set those two options on Slim and run your test suite. Fix anything that depended on XHTML output or on
86
+ sorted attributes.
87
+ 2. Replace `slim-rails` with `super-slim` in your Gemfile and remove any `Slim::Engine.set_options` or
88
+ `with_options` call.
89
+
90
+ Templates for XML formats (`.xml`, `.rss`, `.atom`) render as XML automatically, with `<link />` and
91
+ `doctype xml`.
92
+
93
+ ## Formatter
94
+
95
+ `super-slim format` rewrites templates in one layout: two spaces per level, a space after `-` and `=`, no `div`
96
+ where a `.class` or `#id` is enough, no trailing whitespace unless it renders, single blank lines and a final
97
+ newline. This template:
57
98
 
58
99
  ```slim
59
- .p-1.rounded-b-[3px].lg:[&:nth-child(3)]:hover:underline
60
- .font-['Open_Sans'].bg-(--brand).mx-0.5.w-1/2.!font-bold.@lg:flex
61
- ul.*:p-2
100
+ div.card
101
+ -if post.draft?
102
+ span.badge Draft
103
+ =link_to post.title, post
104
+
105
+
106
+ img src=post.image_url
62
107
  ```
63
108
 
64
- ```ruby
65
- SuperSlim.tailwind_classes = true # config/initializers/super_slim.rb, or tailwind_classes: true per compile
109
+ comes out as:
110
+
111
+ ```slim
112
+ .card
113
+ - if post.draft?
114
+ span.badge Draft
115
+ = link_to post.title, post
116
+
117
+ img src=post.image_url
66
118
  ```
67
119
 
68
- ```yaml
69
- # .super-slim.yml, for super-slim lint and super-slim format
70
- tailwind_classes: true
120
+ ```sh
121
+ super-slim format # every .slim file under the current directory (except .git, node_modules, tmp, vendor)
122
+ super-slim format --check # list the files that would change, and fail if there are any
123
+ super-slim format app/views/posts
71
124
  ```
72
125
 
73
- Attribute lists keep their meaning: Tailwind never puts a bracket right after a letter or a digit, so
74
- `a.btn[href="/"]` is still a link with a class and an `href`. A colon followed by a space still nests a tag
75
- (`li.item: a`), and a final `/` still closes one. What changes is what Slim mangles: it renders `.size-2.5` as
76
- `class="size-2 5"`, the option as `class="size-2.5"`. On 7,505 templates from 31 apps, 16 compile differently
77
- with the option, all of them Tailwind classes Slim breaks. It stays off by default all the same, so that
78
- turning SuperSlim on changes nothing.
126
+ `fmt` is an alias of `format`.
79
127
 
80
- The option only changes how templates are read: compiling 1,408 templates takes the same time (+0.5%, within
81
- noise), and the compiled Ruby, so the time it takes to render, is the same.
128
+ The formatter can't change what a page renders. Before writing a file, it compiles the old and the new version and
129
+ compares the Ruby code they produce, using [Prism](https://github.com/ruby/prism). Line breaks, spaces, a trailing
130
+ comma or the parentheses of a call may differ. If anything else does, it leaves the file alone and reports it. Text
131
+ blocks move together with their whitespace for the same reason.
82
132
 
83
- ## What SuperSlim leaves out
133
+ To also wrap long lines, set a maximum length in `.super-slim.yml`:
84
134
 
85
- Each fails at compile time with a clear error instead of being silently ignored:
135
+ ```yaml
136
+ format:
137
+ max_line_length: 120
138
+ attribute_delimiters: "()" # or "[]" or "{}"
139
+ ```
86
140
 
87
- - the XHTML format, `sort_attrs`, `attr_quote`, `pretty`, `js_wrapper` and every Temple option;
88
- - the `coffee:`, `sass:`, `scss:`, `less:`, `erb:`, `builder:`, `textile:`, `rdoc:`, `asciidoc:` and wiki
89
- engines, and `/[if IE]` conditional comments;
90
- - the `logic_less`, `translator`, `include` and `smart` plugins, and custom shortcuts: only `#id` and `.class`.
141
+ The formatter then gives each line one layout, whatever its author chose. Ruby code spread over several lines is
142
+ joined back when it fits. A longer line spreads the arguments of its call, or the elements of its array or hash, one
143
+ per line between brackets that close on a line of their own, each followed by a comma:
91
144
 
92
- They can come back if people ask, as long as they cost nothing at render time.
145
+ ```slim
146
+ = render Card.new(
147
+ title: post.title,
148
+ body: post.body,
149
+ )
150
+ ```
93
151
 
94
- ## Migrating from Slim
152
+ A call whose only argument is a call spreads that one, as `Card.new` above. Arguments go four spaces deep and the
153
+ closing bracket two, two more when the line opens a block. Code spread by hand stays as it is when this layout
154
+ would leave a line longer than the limit, and arguments to `new` go in parentheses.
95
155
 
96
- Slim's defaults are `format: :xhtml` and `sort_attrs: true`. If you never changed them, first switch Slim
97
- to `format: :html, sort_attrs: false` and check your test suite: that is the output SuperSlim gives. Then swap
98
- `slim-rails` for `super-slim`, and drop any `Slim::Engine.set_options`/`with_options` call.
156
+ A tag's attributes stand without delimiters when they fit on its line, and one per line inside the delimiters when
157
+ they don't, unless its shortcuts alone pass the limit. A literal `id` or `class` becomes a shortcut, a class shortcut
158
+ named twice goes, and the other attributes follow one order: `id`, `class`, what the element is (`type`, `name`,
159
+ `href`, `src`, `value`, `for`, `action`, `method`), the rest, `data-controller`, `data-action` and targets, other
160
+ `data-*`, then `aria-*` and `role`. Delimiters stay around a boolean attribute and before text that would read as
161
+ an attribute, and a tag with a `*splat` keeps its order. The formatter takes attribute values to have no side
162
+ effects: reordering two Ruby values changes the order they run in.
99
163
 
100
- ## Formatter and linter
164
+ ## Linter
101
165
 
102
- One parser serves the compiler, the formatter and the linter, so all three read templates the same way.
166
+ ```sh
167
+ super-slim lint # every .slim file under the current directory
168
+ super-slim lint app/views/posts
169
+ ```
103
170
 
104
- `super-slim format [--check] [PATH…]` (or `fmt`) rewrites templates in their canonical layout: two spaces per level, `- code`,
105
- `= output` and `p = output` spacing, no redundant `div`, no trailing whitespace, single blank lines, one final
106
- newline. Text blocks move as a whole, so the whitespace they render stays put — and before writing anything,
107
- the formatter compiles both versions and refuses unless Prism reads the same Ruby in both, positions aside: line
108
- breaks, spaces, a trailing comma or the parentheses of a call may differ, nothing else. Formatting cannot change a
109
- page.
171
+ On the formatted template above, it still finds the image without a text alternative:
110
172
 
111
- With `format: max_line_length: 120` in `.super-slim.yml`, `format` also wraps longer lines: a tag's attributes one
112
- per line inside `attribute_delimiters` (`"()"` by default, `"[]"` or `"{}"`), then the arguments of its Ruby code after each comma, four spaces deep when the line opens a block. It keeps a wrap only
113
- when Prism reads the same compiled Ruby, and leaves lines already spread over several lines alone.
173
+ ```
174
+ _card.html.slim:6: [ImageAlt] Describe the image with `alt`, or mark it decorative with `alt=""`
175
+ ```
114
176
 
115
- `super-slim lint [PATH…]` reads `.super-slim.yml` and checks, with about a third of the CPU time slim-lint takes:
177
+ The linter reads its settings from `.super-slim.yml`, in the directory you run it from. Its rules come from other
178
+ linters, so most will look familiar:
116
179
 
117
- | Rule | From | Default |
180
+ | Rule | Comes from | Default |
118
181
  |---|---|---|
119
- | Indentation, Tab, TrailingWhitespace, EmptyLines, TrailingBlankLines, ControlStatementSpacing, RedundantDiv | slim-lint, fixed by `super-slim format` | on |
182
+ | Indentation, Tab, TrailingWhitespace, EmptyLines, TrailingBlankLines, ControlStatementSpacing, RedundantDiv | slim-lint (`super-slim format` fixes them) | on |
120
183
  | LineLength (`max: 120`), CommentControlStatement, EmptyControlStatement, ConsecutiveControlStatements (`max: 2`), TagCase | slim-lint | on |
121
184
  | InstanceVariables (in partials) | haml-lint, Rails conventions | on |
122
185
  | StrictLocals (partials declare `/# locals:`) | Rails 7.1 strict locals | off |
123
186
  | DuplicateId, ImageAlt, IframeTitle, AnchorHref, NestedLinks, PositiveTabindex, BooleanAttributeValue, AriaRole, AriaAttribute | Herb, eslint-plugin-jsx-a11y | on |
124
187
  | ButtonType, InlineStyles | eslint-plugin-react, haml-lint | off |
125
- | DeprecatedClasses (`classes: {old: new}`, `old-*: new-*` for a prefix), DeprecatedAttributes (`attributes: {old: new}`), both with `preset: bootstrap5` | erb_lint | on, empty |
188
+ | DeprecatedClasses (`classes: {old: new}`, `old-*: new-*` for a prefix), DeprecatedAttributes (`attributes: {old: new}`), both with `preset: bootstrap5` | erb_lint | on, but empty |
126
189
  | UnescapedOutput (`==`, `html_safe`, `raw`, `#{{}}`) | Brakeman, erb_lint | off |
127
190
  | EmbeddedEngines (`forbidden_engines: [javascript, css]`) | slim-lint | off |
128
- | HardcodedText (text to translate) | erb_lint | off |
191
+ | HardcodedText (text that should be translated) | erb_lint | off |
129
192
  | UnnecessaryInterpolation, UnnecessaryStringOutput | haml-lint | on |
130
193
  | Zwsp (invisible characters) | slim-lint | on |
131
194
 
195
+ The website shows [each rule with an example](https://levups.github.io/super-slim/tools.html). A configuration
196
+ file looks like this:
197
+
132
198
  ```yaml
133
199
  # .super-slim.yml
134
200
  linters:
@@ -137,9 +203,9 @@ linters:
137
203
  ButtonType:
138
204
  enabled: true
139
205
  DeprecatedClasses:
140
- preset: bootstrap5 # Bootstrap 4 classes Bootstrap 5.3 renamed or dropped
206
+ preset: bootstrap5 # Bootstrap 4 classes that Bootstrap 5.3 renamed or dropped
141
207
  classes:
142
- media: ~ # drops an entry of the preset
208
+ media: ~ # removes this entry from the preset
143
209
  legacy-*: modern-*
144
210
  DeprecatedAttributes:
145
211
  preset: bootstrap5 # data-toggle becomes data-bs-toggle, and so on
@@ -151,21 +217,23 @@ linters:
151
217
  include: ["app/views/shop/**/*.slim"]
152
218
  ```
153
219
 
154
- `preset: bootstrap5` lists the Bootstrap 4 classes and data attributes Bootstrap 5.3 renamed, breakpoints included
155
- (`text-md-right`). Its data attributes are only those of Bootstrap's components (`data-toggle`, `data-target`…):
156
- generic ones like `data-content` or `data-delay` go in `attributes:` if your app needs them, and `~` drops an entry of
157
- the preset your own JavaScript reads.
220
+ Every rule accepts `include:` and `exclude:`, lists of glob patterns matched against paths relative to
221
+ `.super-slim.yml` (`**/` matches any number of directories).
222
+
223
+ The `bootstrap5` preset lists the classes and data attributes that Bootstrap 5.3 renamed, including the ones with
224
+ breakpoints such as `text-md-right`. Its data attributes are only those of Bootstrap's own components
225
+ (`data-toggle`, `data-target` and the like). If your app also uses generic ones such as `data-content`, add them
226
+ under `attributes:`. If your own JavaScript still reads an attribute the preset renames, remove that entry with `~`.
158
227
 
159
- Every rule takes `include:` and `exclude:`, lists of globs matched against paths relative to `.super-slim.yml`
160
- (`**/` spans directories).
228
+ ## RuboCop plugin
161
229
 
162
- The Ruby inside templates is RuboCop's job: SuperSlim ships a RuboCop plugin that hands it each `-` and `=` line,
163
- code attribute, splat, `#{}` interpolation and `ruby:` block, read by SuperSlim's own parser. Offenses point at their
164
- line and column in the `.slim` file, and autocorrection writes back into it. It replaces rubocop-slim, and with
165
- it slimi and Temple:
230
+ The linter checks the Slim side of a template. For the Ruby inside it, SuperSlim has a RuboCop plugin, which
231
+ replaces rubocop-slim (and with it slimi and Temple). It passes every `-` and `=` line, Ruby attribute, splat,
232
+ `#{}` interpolation and `ruby:` block to RuboCop. Offenses point at the right line and column of the `.slim` file,
233
+ and `rubocop -a` writes its corrections back into it.
166
234
 
167
235
  ```yaml
168
- # .rubocop-slim.yml, run with rubocop -c .rubocop-slim.yml
236
+ # .rubocop-slim.yml, run with: rubocop -c .rubocop-slim.yml
169
237
  inherit_from: .rubocop.yml
170
238
  plugins:
171
239
  - super-slim
@@ -174,74 +242,170 @@ AllCops:
174
242
  - "**/*.slim"
175
243
  ```
176
244
 
177
- The cops that cannot hold in a template — indentation and alignment across lines, frozen string comments,
178
- `Lint/UselessAssignment` on a variable a later line reads — are turned off for `.slim` files, as rubocop-slim
179
- does. Unlike slimi, SuperSlim also reads the output of a tag with whitespace markers and attributes
180
- (`span> title="x" = name`), so a few offenses appear when switching.
245
+ Some cops make no sense inside a template, such as indentation and alignment across lines, the frozen string
246
+ comment, or `Lint/UselessAssignment` on a variable that a later line uses. The plugin turns them off for `.slim`
247
+ files, as rubocop-slim does. SuperSlim also reads code that slimi skips, for example the output of a tag with
248
+ attributes and whitespace markers (`span> title="x" = name`), so you may see a few new offenses after switching.
181
249
 
182
- ## How it is tested
250
+ ## Additions to Slim
183
251
 
184
- - Slim's own test suite and its literate specification (`TESTS.md`) run against SuperSlim: every template renders
185
- through Slim and SuperSlim, and both outputs must match.
186
- - A seeded fuzzer generates thousands of random templates from the grammar and compares both engines; CI adds
187
- 10,000 from a new seed on every run.
188
- - Golden snapshots (`test/golden`) hold the rendered HTML, compiled Ruby, formatting and lint offenses of
189
- templates covering the grammar, its errors and Tailwind class names: `UPDATE_GOLDEN=1` rewrites them.
190
- - `bench/compiled_digests.rb` proves a refactoring leaves the compiled Ruby of a whole corpus unchanged.
252
+ Two additions read templates that Slim refuses or misreads. Neither changes a template that already works with
253
+ Slim.
191
254
 
192
- Real templates come from 30 public apps pinned in `corpus/manifest.yml`: `rake corpus:fetch` downloads only
193
- their `.slim` files into the ignored `corpus/cache`, `rake corpus:check` compiles, formats and lints each one
194
- against Slim, and `rake corpus:diff BASE=rev` reports what changes between a revision and the working tree:
195
- compiled Ruby, formatting, lint offenses. Downloaded templates are never rendered, as rendering runs their
196
- Ruby; directories you trust, such as your own app, render too when passed in `SUPER_SLIM_CORPUS`.
255
+ ### Ruby code over several lines
197
256
 
198
- ## Benchmarks
257
+ Slim lets a line of Ruby continue on the next line after a comma or a backslash. SuperSlim also continues it after
258
+ an opening `(`, `[` or `{` at the end of a line, until the bracket is closed:
199
259
 
200
- `bench/compare.rb` renders the same blog page with SuperSlim, Slim, Haml, Erubi and Herb, checks that they all
201
- produce the same HTML, and writes compile and render speed and allocations to `docs/benchmarks.json`, which
202
- the website reads. Run it before each release, on a quiet machine:
260
+ ```slim
261
+ = render ProductCardComponent.new(
262
+ product:,
263
+ variant: :compact,
264
+ )
265
+ - columns = %w[
266
+ name
267
+ price
268
+ ]
269
+ ```
203
270
 
204
- ```sh
205
- bundle exec rake bench # YJIT, 5 seconds per measurement
206
- SUPER_SLIM_CORPUS=path/to/app/views bundle exec rake bench # adds the compile time of a whole app against Slim
207
- BENCH_LOCK=path/to/.bench.lock bundle exec rake bench # waits for other benchmarks holding that lock
271
+ A bracket opened in the middle of a line, as in `- items.each { |item|`, works as before: the lines below it are
272
+ its children.
273
+
274
+ ### Tailwind class names
275
+
276
+ Slim stops a `.class` shortcut at characters such as `[`, `:` or `/`, which Tailwind uses all the time. It renders
277
+ `.size-2.5` as `class="size-2 5"`, and refuses `.lg:[&:nth-child(3)]:hover:underline`. With `tailwind_classes` on,
278
+ the shortcut takes any Tailwind class name:
279
+
280
+ ```slim
281
+ .p-1.rounded-b-[3px].lg:[&:nth-child(3)]:hover:underline
282
+ .font-['Open_Sans'].bg-(--brand).mx-0.5.w-1/2.!font-bold.@lg:flex
283
+ ul.*:p-2
208
284
  ```
209
285
 
210
- With `corpus/cache` fetched, it also times the open-source corpus, and `super-slim lint` and `format` there against
211
- slim-lint when it is installed. `bundle exec rake docs` rewrites the linter rules on the website
212
- (`docs/tools.html`), after checking every example against the linter.
286
+ Turn it on for the engine, in `config/initializers/super_slim.rb` for example (or per call with
287
+ `SuperSlim.compile(source, tailwind_classes: true)`):
288
+
289
+ ```ruby
290
+ SuperSlim.tailwind_classes = true
291
+ ```
292
+
293
+ And for the formatter and the linter, in `.super-slim.yml`:
294
+
295
+ ```yaml
296
+ tailwind_classes: true
297
+ ```
298
+
299
+ Everything else reads as before. Tailwind never puts a bracket right after a letter or a digit, so in
300
+ `a.btn[href="/"]` the brackets are still an attribute list. `li.item: a` still nests a tag, and a final `/` still
301
+ closes one. On 7,505 templates from 31 apps, 16 compiled differently with the option on, and each time it was a
302
+ Tailwind class that Slim broke. The option is off by default anyway, so that switching to SuperSlim changes
303
+ nothing. It costs nothing measurable: compile time on 1,408 templates moved by 0.5%, within noise, and the
304
+ compiled code is the same, so render time is too.
305
+
306
+ ## Escaping
307
+
308
+ Like Slim, SuperSlim escapes for HTML everything that `=`, `#{}` and attribute values output. `==` and `#{{}}`
309
+ output raw HTML, so only use them on content you trust. In Rails, strings marked `html_safe` aren't escaped again.
310
+
311
+ Some names are only known when the page renders: the keys of a `*splat` hash, of a `data:` or `aria:` hash, and
312
+ the tag of `*{tag: …}`. SuperSlim checks those names and raises an error instead of rendering one that would break
313
+ the HTML. Slim does not check them. With Slim, `data: {"x\tonclick" => code}` renders an `onclick` attribute, and
314
+ `*{tag: "img src=x onerror=…"}` renders an image with an `onerror` handler. SuperSlim raises
315
+ `SuperSlim::InvalidAttributeNameError` and `SuperSlim::InvalidTagNameError` instead.
316
+
317
+ HTML escaping protects HTML, and nothing else. A `#{}` of user input inside `javascript:` or `css:`, inside an
318
+ unquoted attribute of inline HTML, or in the URL of a `markdown:` link can still inject code. In scripts, write
319
+ `#{{json_escape(value.to_json)}}` (Rails), always quote attributes, and check URLs before they reach a template.
320
+
321
+ ## What SuperSlim leaves out
322
+
323
+ These parts of Slim aren't supported. Each one fails when the template compiles, with an error that names it:
324
+
325
+ - the XHTML format, the `sort_attrs`, `attr_quote`, `pretty` and `js_wrapper` options, and every Temple option;
326
+ - the `coffee:`, `sass:`, `scss:`, `less:`, `erb:`, `builder:`, `textile:`, `rdoc:`, `asciidoc:` and wiki
327
+ engines, and `/[if IE]` conditional comments;
328
+ - the `logic_less`, `translator`, `include` and `smart` plugins, and custom shortcuts (only `#id` and `.class`
329
+ exist).
330
+
331
+ The embedded engines that do work are `ruby:`, `javascript:`, `css:` and `markdown:`. `markdown:` uses
332
+ [Markly](https://github.com/ioquatix/markly), so add `gem "markly"` to your Gemfile if you use it. The rest can
333
+ come back if people ask for them, as long as they don't slow down rendering.
334
+
335
+ ## Learn more
336
+
337
+ The website has a [guide](https://levups.github.io/super-slim/guide.html) with every option, a page on the
338
+ [formatter and linter](https://levups.github.io/super-slim/tools.html) with an example for each rule, the
339
+ [benchmarks](https://levups.github.io/super-slim/benchmarks.html) and the
340
+ [test setup](https://levups.github.io/super-slim/testing.html). [CHANGELOG.md](CHANGELOG.md) lists the changes in
341
+ each version.
342
+
343
+ ## How it is tested
344
+
345
+ Slim is the reference. Its own test suite, including the examples of its specification (`TESTS.md`), runs against
346
+ SuperSlim: every template is rendered by both engines, and the HTML has to match.
347
+
348
+ On top of that:
349
+
350
+ - A fuzzer builds thousands of random templates from the grammar and compares the output of both engines. CI runs
351
+ 10,000 new ones on every build.
352
+ - Snapshots in `test/golden` record the HTML, the compiled Ruby, the formatted template and the lint offenses for
353
+ templates covering the whole grammar, its errors and Tailwind class names. `UPDATE_GOLDEN=1` rewrites them after
354
+ a deliberate change.
355
+ - `bench/compiled_digests.rb` checks that a refactoring leaves the compiled Ruby of a whole set of templates
356
+ unchanged.
357
+
358
+ Real templates come from 30 open-source apps, pinned to a commit in `corpus/manifest.yml`. `rake corpus:fetch`
359
+ downloads only their `.slim` files, into `corpus/cache` (ignored by Git). `rake corpus:check` compiles, formats
360
+ and lints each of them and compares the result with Slim. `rake corpus:diff BASE=rev` shows what a change does to
361
+ them: compiled Ruby, formatting and lint offenses. These templates are never rendered, because rendering would run
362
+ their Ruby code. Your own templates can be rendered too: pass their directories in `SUPER_SLIM_CORPUS`.
213
363
 
214
364
  ## Development
215
365
 
216
366
  ```sh
217
367
  bundle install
218
- bundle exec rake test # SuperSlim's tests, then Slim's own suites
368
+ bundle exec rake test # SuperSlim's tests, then Slim's own suites
219
369
  BUNDLE_GEMFILE=gemfiles/rails_8_0.gemfile bundle exec rake test # the same on Rails 8.0
220
370
  bundle exec rubocop
221
- FUZZ_SEED=42 FUZZ_CASES=20000 bundle exec ruby -Ilib test/fuzz_test.rb
222
- bundle exec ruby -Ilib bench/corpus.rb path/to/app # compile time and allocations against Slim
223
- bundle exec ruby --yjit -Ilib bench/render.rb # render speed and allocations against Slim
371
+ FUZZ_SEED=42 FUZZ_CASES=20000 bundle exec ruby -Ilib -Itest test/fuzz_test.rb
372
+ bundle exec ruby -Ilib bench/corpus.rb path/to/app # compile time and allocations against Slim
373
+ bundle exec ruby --yjit -Ilib bench/render.rb # render speed and allocations against Slim
374
+ bundle exec rake docs # rebuild the linter rules page of the website
375
+ ```
376
+
377
+ The website's numbers come from `docs/benchmarks.json`, which `rake bench` rewrites by running `bench/compare.rb`.
378
+ If `corpus/cache` is there, it also times the open-source templates, and compares `super-slim lint` and `format`
379
+ with slim-lint when slim-lint is installed. Run it on a quiet machine:
380
+
381
+ ```sh
382
+ bundle exec rake bench # with YJIT, 5 seconds per measurement
383
+ SUPER_SLIM_CORPUS=path/to/app/views bundle exec rake bench # also times compiling a whole app against Slim
384
+ BENCH_LOCK=path/to/.bench.lock bundle exec rake bench # waits while another benchmark holds the lock
224
385
  ```
225
386
 
387
+ [CONTRIBUTING.md](CONTRIBUTING.md) explains how to propose a change. Please report security issues privately, as
388
+ [SECURITY.md](SECURITY.md) describes.
389
+
226
390
  ### Releasing
227
391
 
228
- Pull requests leave `CHANGELOG.md` alone: a release starts by writing its notes under `## [Unreleased]`, from the
229
- pull requests merged since the last tag, without committing them. Refresh the website's numbers on a quiet machine
230
- (`SUPER_SLIM_CORPUS=path/to/app/views bundle exec rake bench`) and merge them through a pull request, then, from an
231
- up-to-date `main` whose CI is green:
392
+ Pull requests don't touch `CHANGELOG.md`. A release starts by writing its notes under `## [Unreleased]`, from the
393
+ pull requests merged since the last tag, without committing them. Refresh the numbers on the website first, on a
394
+ quiet machine (`SUPER_SLIM_CORPUS=path/to/app/views bundle exec rake bench`), and merge them in their own pull
395
+ request. Then, from an up-to-date `main` with green CI:
232
396
 
233
397
  ```sh
234
- bin/release minor --dry-run # the notes and the changes, nothing written
398
+ bin/release minor --dry-run # shows the notes and the changes, writes nothing
235
399
  bin/release minor # or patch, major, or an exact version such as 1.2.0
236
400
  ```
237
401
 
238
- `main` takes no direct push, so `bin/release` dates the Unreleased section and bumps the version on a branch
239
- `release/vX.Y.Z`, opens its pull request, which merges itself once CI is green, and waits for it. It then pushes a
240
- signed tag `vX.Y.Z` on the merge commit (`bin/release --tag X.Y.Z` does it if you stopped waiting). The tag starts
241
- the Release workflow, which publishes the gem to RubyGems through trusted publishing and creates the GitHub release
242
- with the version's notes and the `.gem`.
402
+ Nobody pushes to `main` directly, so `bin/release` dates the Unreleased section and bumps the version on a
403
+ `release/vX.Y.Z` branch, opens a pull request that merges itself once CI passes, and waits for it. It then pushes
404
+ 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
405
+ step). The tag starts the Release workflow, which publishes the gem to RubyGems through trusted publishing and
406
+ creates the GitHub release with the notes and the `.gem` file.
243
407
 
244
408
  ## License
245
409
 
246
- MIT, by [Level UP Solutions](https://github.com/levups). The parser follows the
247
- grammar and parsing algorithm of [Slim](https://github.com/slim-template/slim), by the Slim Team (MIT).
410
+ MIT, by [Level UP Solutions](https://github.com/levups). The parser follows the grammar and the parsing algorithm
411
+ of [Slim](https://github.com/slim-template/slim), by the Slim Team (MIT).