Ignition
Ignition is a Rails engine which routes and renders your application's static pages.
Installation
It takes three easy steps to install Ignition:
-
Add
gem 'ignition'to yourGemfileand run thebundlecommand. -
Mount Ignition's engine in your
config/routes.rbfile:mount Ignition::Engine => '/pages' -
Create pages like normal templates in the
app/views/pagesdirectory. 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/pagesdirectory -
Nested pages - e.g.
http://my.app/pages/projects/hellowould load the templateapp/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_pathandignition_engine.page_urlto link to your static pages. -
Works with custom (and multiple)
app/viewspaths.
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 theactionpack-page_cachinggem 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 theactionpack-action_cachinggem 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.