pug-rails
is a gem that allows you to easily integrate Jade / Pug template engine with Rails asset packaging system known as Sprockets.
pug-ruby is used under the hood. Please refer to the gem if you would like to use Jade / Pug compiler API directly.
RubyGems users
- Run
gem install pug-rails --version "~> 3.0.0"
. - Add
require "pug-rails"
to your code.
Bundler users
- Add to your Gemfile:
gem "pug-rails", "~> 3.0.0"
- Run
bundle install
.
See installation steps and notes at pug-ruby. You may not need to do this step.
Put the next line in your asset manifest:
//= require jade-runtime-1.11.0
You may change Jade runtime.js version depending on your scenario.
Use .jst.jade
as extension of your Jade files.
Put the next line in your asset manifest:
//= require pug-runtime-2.0.2
You may change Pug runtime.js version depending on your scenario.
IMPORTANT: You don't need to do this if you have configured Pug compiler to inline runtime functions in template. Please read about inlineRuntimeFunctions
option at official website: pugjs.org.
Use .jst.pug
as extension of your Pug files.
Configuration documentation is available at pug-ruby.
It doesn't matter where to put Jade / Pug files but don't forget to update asset lookup paths.
Personally I prefer to put templates in app/assets/templates
:
# This will add app/assets/templates to asset lookup paths.
#
# Add the next line to your initializers or application.rb:
Rails.application.config.assets.paths << Rails.root.join("app/assets/templates")
- Install both Jade and Pug:
npm install --global jade pug
. - Install gem dependencies:
bundle install
. - Finally, run tests:
bundle exec appraisal rake test
.
Prior to 2.0 the version of the gem was the same as the version of the Jade runtime that it contained.