Git Product home page Git Product logo

slimmer's Introduction

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 one of its templates. It also transfers various other details, such as meta, script, and style tags.

Use in a Rails app

Slimmer provides a Railtie so no configuration is necessary. By default it will use the Plek gem to look for the 'assets' host for the current environment.

If you want to use your own set of templates you will need to specify the appropriate host eg.

YourApp::Application.configure do
  config.slimmer.asset_host = 'http://your.server.somewhere'
end

it expects to find templates in a folder called 'templates' on that host.

Use elsewhere

Slimmer will work as standard rack middleware:

use Slimmer::App

or

use Slimmer::App, :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

eg in a rails app

class MyController < ApplicationController
  def index
    headers['X-Slimmer-Template'] = 'homepage'
  end
end

There's also a macro style method:

class YourController < ApplicationController
  slimmer_template :admin
end

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

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

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

The name

Slimmer was extracted from a much larger project called 'skinner'. 'slimmer' referred to the size of its code compared to skinner (which also acted as an HTTP proxy and mixed in a few other concerns). Over time the codebase has grown a little, but the name stuck.

slimmer's People

Contributors

alext avatar craigw avatar lazyatom avatar techbelly avatar jystewart avatar heathd avatar tomafro avatar jamiecobbett avatar threedaymonk avatar jordanhatch avatar bradwright avatar chrisroos avatar edds avatar dhwthompson avatar fidothe avatar garethr avatar daibach avatar phae avatar floehopper avatar jabley avatar blaine avatar kushalp avatar robyoung avatar richardjpope avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.