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