Git Product home page Git Product logo

brochure's Introduction

Brochure

Brochure is a Rack application for serving static sites with ERB templates (or any of the many template languages supported by Tilt). It's the good parts of PHP wrapped up in a little Ruby package — perfect for serving the marketing site for your Rails app.

Sample application structure:

templates/
  help/
    index.html.erb
  index.html.erb
  shared/
    _header.html.erb
    _footer.html.erb
  signup.html.erb
config.ru
public/
  ...

Sample config.ru:

require "brochure"
root = File.dirname(__FILE__)
run Brochure.app(root)

Automatic URL mapping

URLs are automatically mapped to template names:

  • /templates/index.html.erb
  • /signuptemplates/signup.html.erb
  • /help/templates/help/index.html.erb

Partials and helpers

Templates can render partials. A partial is denoted by a leading underscore in its filename. So <%= render "shared/header" %> will render templates/shared/_header.html.erb inline.

Partials can <%= yield %> back to the templates that render them. You can use this technique to extract common header and footer markup into a single layout file, for example.

Templates have access to the Rack environment via the env method and to the Brochure application via the application method. Additionally, a Rack::Request wrapper around the Rack environment is available via the request method.

You can print HTML-escaped strings in your templates with the h helper.

Custom helper methods and instance variables

You can make additional helper methods and instance variables available to your templates. Helper methods live in Ruby modules and can be included with the :helpers option to Brochure.app:

module AssetHelper
  def asset_path(filename)
    local_path = File.join(application.asset_root, filename)
    digest = Digest::MD5.hexdigest(IO.read(local_path))
    "/#{filename}?#{digest}"
  end
end

run Brochure.app(root, :helpers => [AssetHelper])

Similarly, instance variables can be defined with the :assigns option:

run Brochure.app(root, :assigns => { :domain => "37signals.com" })

Tilt template options

You can specify global Tilt template options on a per-engine basis with :template_options:

run Brochure.app(root, :template_options => {
  ".haml" => { :format => :html5 },
  ".md"   => { :smart  => true }
})

Installation

$ gem install brochure

Requires Hike, Rack, and Tilt.

License

Copyright (c) 2010 Sam Stephenson and Josh Peek.

Released under the MIT license. See LICENSE for details.

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.