Slim Rails templating

Public
Provides the generator settings required for Rails 3+ to use Slim
Icons/chart bar
Used 76 times
Created by
V Viktor Schmidt

Usage

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/X8Bska"
Template Source

Review the code before running this template on your machine.

def do_bundle
  Bundler.with_original_env { run "bundle install" }
end

def do_commit
  git :init
  git add: "."
  git commit: " -m 'Switch to Slim templating' "
end

say "\nApplying Slim templating..."
inject_into_file 'Gemfile', after: "gem \"cssbundling-rails\"\n" do
  <<~RUBY 

  # Provides the generator settings required for Rails 3+ to use Slim
  gem "slim-rails", "~> 3.5"
  RUBY
end
inject_into_file 'Gemfile', after: 'group :development do' do
  <<-RUBY 

  # Convert HTML to Slim templates. Because HTML sux and Slim rules. That's why.
  gem "html2slim", "~> 0.2", require: false
  RUBY
end

do_bundle

run "erb2slim app/views -d"
run "git checkout app/views/layouts/application.html.erb"
run "rm app/views/layouts/application.html.slim"

do_commit

say "\nSwitched to Slim templating successfully!"
Comments

Sign up or Login to leave a comment.

© 2023 GoRails, LLC