All Projects → alphagov → slimmer

alphagov / slimmer

Licence: MIT license
Templating Rack middleware, injects standard header/footer and GOV.UK Components

Programming Languages

ruby
36898 projects - #4 most used programming language
HTML
75241 projects

Labels

Projects that are alternatives of or similar to slimmer

Fabric Scripts
GOV.UK Fabric scripts
Stars: ✭ 56 (+86.67%)
Mutual labels:  govuk
Router
Router in front on GOV.UK to proxy to backend servers on the single domain
Stars: ✭ 181 (+503.33%)
Mutual labels:  govuk
smokey
Smoke tests for GOV.UK
Stars: ✭ 42 (+40%)
Mutual labels:  govuk
Govspeak
Markdown extension library for Government editors
Stars: ✭ 65 (+116.67%)
Mutual labels:  govuk
Magna Charta
Accessible, useful, beautiful barcharts from HTML tables.
Stars: ✭ 151 (+403.33%)
Mutual labels:  govuk
Govuk React
An implementation of the GOV.UK Design System in React using CSSinJS
Stars: ✭ 219 (+630%)
Mutual labels:  govuk
Cdn Acceptance Tests
CDN Acceptance Tests
Stars: ✭ 46 (+53.33%)
Mutual labels:  govuk
collections
Serves GOV.UK navigation pages, browse, topic, step-by-steps & services and information pages.
Stars: ✭ 32 (+6.67%)
Mutual labels:  govuk
Styleguides
GOV.UK coding standards and guidelines for other tools we use
Stars: ✭ 179 (+496.67%)
Mutual labels:  govuk
gds-nodejs-boilerplate
A Node.js project boilerplate for production apps
Stars: ✭ 18 (-40%)
Mutual labels:  govuk
Static
GOV.UK static files and resources
Stars: ✭ 100 (+233.33%)
Mutual labels:  govuk
Smart Answers
Serves smart answers on GOV.UK
Stars: ✭ 148 (+393.33%)
Mutual labels:  govuk
Frontend
Serves the homepage, transactions and some index pages on GOV.UK
Stars: ✭ 234 (+680%)
Mutual labels:  govuk
Govuk Guix
Package, service and system definitions using GNU Guix for software and systems related to GOV.UK.
Stars: ✭ 58 (+93.33%)
Mutual labels:  govuk
search-api
Search API for GOV.UK
Stars: ✭ 21 (-30%)
Mutual labels:  govuk
Design Principles
Serves /design-principles on GOV.UK
Stars: ✭ 55 (+83.33%)
Mutual labels:  govuk
Government Service Design Manual
Government Service Design Manual
Stars: ✭ 186 (+520%)
Mutual labels:  govuk
publishing-api
API to publish content on GOV.UK
Stars: ✭ 29 (-3.33%)
Mutual labels:  govuk
govuk-terraform-provisioning
**DEPRECATED** Terraform configuration and utilities to provision parts of the GOV.UK AWS Infrastructure
Stars: ✭ 17 (-43.33%)
Mutual labels:  govuk
govuk-components
Lightweight components for developing with the GOV.UK Design System
Stars: ✭ 84 (+180%)
Mutual labels:  govuk

Slimmer

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 a 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 meta, script, and style tags.

View documentation

Use in a Rails app

Slimmer provides a Railtie so no configuration is necessary.

Caching

Slimmer makes HTTP requests to static for templates. These are cached using Rails.cache.

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"

to application.rb.

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 slimmer_template.

class MyController < ApplicationController
  def index
    slimmer_template 'homepage'
  end
end

There's also a macro style method which will affect all actions:

class YourController < ApplicationController
  slimmer_template :admin
end

To get this, include Slimmer::Template in your ApplicationController:

class ApplicationController < ActionController::Base
  include Slimmer::Template
end

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).

Logging

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:

YourApp::Application.configure do
  config.slimmer.logger = Rails.logger
end

Note: This can't be in application.rb because the Rails logger hasn't been initialized by then.

Debug logging

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:

YourApp::Application.configure do
  config.slimmer.enable_debugging = true
end

Cucumber

Add the following code to features/support:

require 'slimmer/cucumber'

RSpec

Add the following code to spec/spec_helper:

require 'slimmer/rspec'

Licence

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].