Switching from Slim

There is no need to switch all at once. The steps below each stand on their own: stop after any of them and you still have something useful, and nothing you cannot undo.

Before you start

A quick look at these saves surprises later:

  • Ruby 3.3 or later, the C Ruby (SuperSlim relies on erb/escape, a C extension, so not JRuby or TruffleRuby). Rails is optional; SuperSlim is tested on Rails 8.0 and later.
  • A test suite that renders your views, even a modest one. It is what tells you, at each step, that nothing moved.
  • The few parts of Slim that SuperSlim leaves out: the XHTML format, custom shortcuts, a handful of embedded engines and plugins. They are listed in the guide, and most fail loudly when the template compiles. One doesn’t: a custom shortcut after a tag (input&text) renders as text, so search for those by hand.

1. Try the tools, keep Slim

The gentlest start: keep Slim as your engine and only borrow SuperSlim’s formatter and linter. With require: false, Rails never loads SuperSlim and goes on rendering with Slim, while the commands still find it.

# Gemfile
gem "super-slim", require: false
bundle exec super-slim lint            # what it would point out
bundle exec super-slim format --check  # which files it would tidy

Nothing about your pages changes here. Have a look at what the linter finds, turn off the rules you don’t want in .super-slim.yml, and run super-slim format once when you like what it does: the formatter refuses any change that would alter the compiled Ruby. Coming from slim-lint or rubocop-slim? The rules page says where each rule comes from, and the RuboCop plugin takes over from rubocop-slim.

One thing to know: SuperSlim also reads a few things Slim can’t, such as Ruby continued after an opening bracket. While Slim renders your pages, keep them out of your templates: the SlimSyntax rule, on by default, points them out.

2. Line up Slim’s options

SuperSlim renders exactly what Slim renders with format: :html, sort_attrs: false. Slim’s own defaults are format: :xhtml, sort_attrs: true, so if you never changed them, set the two options first, still on Slim:

# config/initializers/slim.rb
Slim::Engine.set_options(format: :html, sort_attrs: false)

Run your tests. What might change: void tags lose their slash (<br> instead of <br />), boolean attributes lose their ="" (checked instead of checked=""), and attributes keep the order you wrote them in. Browsers don’t mind either; a test or a cached fragment comparing raw HTML might. Fix those, deploy if you like, and this step is done. It is the only one that changes your HTML, and it does so on Slim, where you know your way around.

While you are there, look for Slim::Engine.set_options and with_options calls that set anything else, and for the parts SuperSlim leaves out. Rewrite those in plain Slim now: an attribute instead of a custom shortcut, a partial instead of include.

3. Swap the engine

Replace Slim with SuperSlim in your Gemfile. It also replaces slim-rails: a railtie registers the .slim handler, with nothing to configure.

# Gemfile
gem "super-slim"   # instead of slim-rails or slim
gem "markly"       # only if a template uses markdown:

Delete the Slim initializer from step 2. Then compile every template once, without rendering it: this runs none of your Ruby, and a syntax error shows up with its file and line before any test does.

bundle exec ruby -rsuper_slim -e 'Dir["app/**/*.slim"].each { |f| SuperSlim.compile(File.read(f), file: f, format: f.match?(/\.(xml|rss|atom)\.slim\z/) ? :xml : :html) }'

Then run your tests. They should pass without a change: same HTML, byte for byte. Templates for XML formats (.xml, .rss, .atom) render as XML on their own.

Once you are on SuperSlim, the extras are yours if you want them: Tailwind class names and Ruby spread over several lines. They stay off, or unused, until you choose them.

Going back

If SuperSlim isn’t for you, put slim-rails back in your Gemfile, with the options from step 2: your pages render as they did. Formatted templates stay readable by Slim too, since the formatter only writes what Slim reads.

The one thing that ties you to SuperSlim is what Slim can’t read: Ruby continued after an opening bracket, a comment after code, and Tailwind class names in .class shortcuts. super-slim lint flags the first two; for the third, compiling alone won’t tell you, since Slim reads most Tailwind names without an error, only wrongly (.size-2.5 becomes two classes). Compare each template compiled with and without the option instead:

bundle exec ruby -rsuper_slim -e 'Dir["app/**/*.slim"].each { |f| s = File.read(f); puts f if SuperSlim.compile(s, tailwind_classes: true) != SuperSlim.compile(s, tailwind_classes: false) }'

We would rather you knew this before you start than after.

With an AI agent

A coding agent (Claude Code, Codex, Cursor…) can take the steps above in one sitting. Give it this prompt from the root of your app: each step lands in its own commit, and it stops rather than change the rendered HTML without a reason. Read its commits as you would a colleague’s.

Migrate this app's templates from Slim to SuperSlim (https://github.com/levups/super-slim). SuperSlim renders the HTML Slim renders with `format: :html, sort_attrs: false`, byte for byte. Read https://levups.github.io/super-slim/migrate.html, https://levups.github.io/super-slim/guide.html and the gem's README before you start.

Rules: one commit per step below, the full test suite green after each one. The migration must not change the rendered HTML, except in step 1, where each change gets its reason in the commit message. If a test fails and you cannot explain why, stop and report.

1. Slim options. Find every Slim setting (Slim::Engine.set_options, with_options, Slim::Engine.options, slim-rails configuration). If the app keeps Slim's defaults (format: :xhtml, sort_attrs: true), set `Slim::Engine.set_options(format: :html, sort_attrs: false)` while still on Slim, run the tests, and fix whatever relied on XHTML output (`<br />`) or on sorted attributes.
2. Unsupported features. List every use of what SuperSlim leaves out: custom shortcuts, embedded engines other than ruby:, javascript:, css: and markdown:, `/[if IE]` comments, the logic_less, translator, include and smart plugins, and Temple options (attr_quote, pretty, js_wrapper…). Show me the list, then rewrite each use in plain Slim, still on Slim: an attribute instead of a shortcut, a partial instead of include.
3. Swap the gem. Replace slim-rails and slim with `gem "super-slim"` (plus `gem "markly"` if a template uses markdown:) and delete the Slim configuration. Compile every template without rendering it (XML formats compile as XML), then run the tests:
   bundle exec ruby -rsuper_slim -e 'Dir["app/**/*.slim"].each { |f| SuperSlim.compile(File.read(f), file: f, format: f.match?(/\.(xml|rss|atom)\.slim\z/) ? :xml : :html) }'
4. Linting. Replace slim-lint with `super-slim lint`: move the .slim-lint.yml settings that have an equivalent into .super-slim.yml and name the ones that have none. Replace rubocop-slim with SuperSlim's RuboCop plugin, as the README shows. Fix new offenses.
5. Formatting. Run `super-slim format` alone in its own commit, and check that the diff only moves whitespace and layout. Then add `super-slim lint` and `super-slim format --check` to CI.

Finish with a summary: what you rewrote by hand, the HTML that changed in step 1, and anything left to decide. If the app uses Tailwind, suggest `SuperSlim.tailwind_classes = true` as a follow-up, without turning it on.

The agent swaps the engine before the tools, the reverse of the order above: in one sitting, with the tests as a safety net, that order makes fewer commits. Either way ends in the same place.

If something looks wrong

If a template renders differently on SuperSlim than on Slim with the options of step 2, that is a bug, and we would really like to hear about it. Open an issue with the smallest template that shows it and the HTML each engine renders. The same goes for a formatter change you didn’t expect, a lint rule that gets it wrong, or a step on this page that left you stuck.