Templating Rack middleware, injects standard header/footer and GOV.UK Components
Relevant manual pages
Slimmer provides Rack middleware for applying a standard header and footer around pages returned by a Ruby (Rack) application.
It does this by taking the page rendered by the application, extracting the contents of
div with id ‘wrapper’ and inserting that into a
div with the same id in one of its
templates. It also transfers various other details, such as
Use in a Rails app
Slimmer provides a Railtie so no configuration is necessary.
Slimmer makes HTTP requests to
static for templates. These are cached using
Asset tag helpers
To get asset tag helpers to point to your external asset server, add
config.action_controller.asset_host = "http://my.alternative.host"
Specifying a template
A specific template can be requested by giving its name in the
X-Slimmer-Template HTTP header.
In a controller action, you can do this by calling
class MyController < ApplicationController
There’s also a macro style method which will affect all actions:
class YourController < ApplicationController
To get this, include Slimmer::Template in your ApplicationController:
class ApplicationController < ActionController::Base
Use in before_action renders
If you have a non-default layout and want to render in a before_action method, note that you may have to explicitly call
slimmer_template(:your_template_name) in the action before rendering. Rendering in a before_action immediately stops the action chain, and since slimmer usually calls slimmer_template as an after_action, it would be skipped over (and you’d get the default layout).
Slimmer can be configured with a logger by passing in a logger instance
(anything that quacks like an instance of
Logger). For example, to log
to the Rails log, put the following in an initializer:
config.slimmer.logger = Rails.logger
Note: This can’t be in
application.rb because the Rails logger hasn’t been initialized by then.
By default if you pass in a logger with its log level set to
debug, slimmer will dup this logger and reduce the level to
info. (Slimmer’s debug logging is very noisy). To prevent this, set the
enable_debugging option to true. e.g. for Rails:
config.slimmer.enable_debugging = true
Add the following code to features/support:
Add the following code to spec/spec_helper: