Ruby
Switch branches/tags
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app/controllers/ignition
config
doc
lib
test
.gitignore
.mailmap
Gemfile
Gemfile.lock
LICENSE
README.markdown
Rakefile
ignition.gemspec

README.markdown

Ignition

Ignition is a Rails engine which routes and renders your application's static pages.

Installation

It takes three easy steps to install Ignition:

  1. Add gem 'ignition' to your Gemfile and run the bundle command.

  2. Mount Ignition's engine in your config/routes.rb file:

    mount Ignition::Engine => '/pages'
    
  3. Create pages like normal templates in the app/views/pages directory. Use any format and template handler you like. They'll be available at /pages/name.

Features

  • Caching

  • Secure - users cannot fetch pages outside of the app/views/pages directory

  • Nested pages - e.g. http://my.app/pages/projects/hello would load the template app/views/projects/hello.html.erb

  • Mountable at any path - e.g. you could mount to / if you wanted pages like /about, this will not conflict with your existing routes even if Ignition is mounted before you define the routes

  • URL helpers - use ignition_engine.page_path and ignition_engine.page_url to link to your static pages.

  • Works with custom (and multiple) app/views paths.

Configuration

Caching

By default Ignition does not perform any caching, as this can interfere with the application's layout if it is dynamic.

There are three types of caching:

  • :none - does not perform any caching (default).

  • :page - caches the entire page using Rails' page caching. As page caching was removed form Rails 4, you'll need to install the actionpack-page_caching gem for this option to work.

  • :page_without_layout - caches the page using Rails' action caching. The layout is not included in the cache, therefore this option is suitable if your layout is dynamic. However, it's probably also not very useful, unless you do some long-running computation in your static page templates. As action caching was removed from Rails 4, you'll need to install the actionpack-action_caching gem for this option to work.

These can be set in the config/application.rb file or any of the config/environments/*.rb files, like so:

config.ignition.cache = :page

Layout

By default Ignition will make your static pages use the application layout. This is also the Rails default. It can be changed like so in the config/application.rb file:

config.ignition.layout = 'my_page_layout'

View Prefix

By default Ignition will try to include pages in a folder named pages inside your app/views folder. You can change this pages prefix by changing the following setting inside the config/application.rb file:

config.ignition.view_prefix = 'static_pages'

The only reason you would probably want to do this is if pages conflicts with a controller and set of views you already have.

Tips

Avoid typing ignition_engine. in front of URL helpers

This can be accomplished by placing the following code in your ApplicationHelper module, found in the app/helpers/application_helper.rb file:

[:page_path, :page_url].each do |method|
  define_method(method) do |*args|
    ignition_engine.send(method, *args)
  end
end

License

Ignition is available under the MIT license, see the LICENSE file.