Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here

brochure

A Rack application for serving static sites

Subscribe to updates I use brochure


Statistics on brochure

Number of watchers on Github 362
Number of open issues 8
Average time to close an issue 20 days
Main language Ruby
Average time to merge a PR about 6 hours
Open pull requests 4+
Closed pull requests 2+
Last commit almost 8 years ago
Repo Created about 9 years ago
Repo Last Updated over 1 year ago
Size 713 KB
Organization / Authorsstephenson
Contributors4
Page Updated
Do you use brochure? Leave a review!
View open issues (8)
View brochure activity
View on github
Fresh, new opensource launches πŸš€πŸš€πŸš€
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating brochure for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

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
  • /signup β†’ templates/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.

brochure open issues Ask a question     (View All Issues)
  • over 7 years Yielding in layouts seems to fail with a LocalJumpError
  • almost 9 years Windows supported? (or bug)
  • almost 9 years /public/index.html should have priority over /templates/index.html.erb
  • almost 9 years Plugins can have public/ directories
brochure open pull requests (View All Pulls)
  • Allow template location to be elsewhere.
  • Layout option (3rd times a charm)
  • Document how layouts work better.
  • fix issue #12 (second part, see hike)
brochure questions on Stackoverflow (View All Questions)
  • How to check the code from brochure and to access the page
  • Download brochure depends on the hidden field value
  • brochure website name with empty space on both sides
  • Need a form before downloading the brochure for multiple projects [WordPress]
  • CSS media print document as brochure
  • Need to fill a brochure preview in real time with a form
  • Designing a Brochure
  • Image brochure with Jquery
  • How to send mail and insert into database of a request brochure in magento v 1.9.0.1
  • Tri folded online brochure as website, how do I animate?
  • Redirect a facebook/page - Big mistake on brochure
  • Brochure: how to make it?
  • Handling Brochure-style pages in ASP.Net MVC
  • Data Storage for Multilingual Brochure App
  • Building a bespoke PDF brochure via web form or CMS
  • Creating a simple brochure app in android
  • Trying to create an HTML brochure that's cross-browser compatible
  • $(β€œ#request-brochure”).validate is not a function
  • Adding a pages/main controller for 'brochure-site' section of a Rails app
  • Use ASP.NET MVC for html brochure websites?
brochure list of languages used
Other projects in Ruby