Skip to content

trailblazer/cells-slim

Repository files navigation

Cells::Slim

Support for Slim templates with Cells.

Installation

Add this line to your application's Gemfile:

gem 'cells-slim'

Usage

class CommentCell < Cell::ViewModelSlim

Important

Cells Slim change default settings for Slim and disables escaping in templates. To re-enable it, you can use below snippet:

It can be changed easy by override template_options_for from Cells::Slim:

module Cell
  module Slim
    def template_options_for(options)
      {
          template_class: ::Slim::Template,
          suffix: 'slim',
          disable_escape: false,
          escape_code: false,
          use_html_safe: false, # set true for Rails
          buffer: '@output_buffer'
      }
    end
  end
end

This can be put in config/application.rb.

Remember that you need to use '==' instead of '=' (reference in Slim docs) in your templates for code which should not be escaped, for example form_builder (notice that only from_for line require '=='):

== form_for model, url: users_path, method: method do |f|
  = f.text_field :first_name
  = f.text_field :last_name

Documentation

More documentation can be found on the Trailblazer page.