Gakubuchi
Gakubuchi provides a simple way to manage static pages (e.g. error pages) with Asset Pipeline.
Installation
Put this in your Gemfile:
gem 'gakubuchi'
Run the installation generator with:
rails generate gakubuchi:install
Or specify the name of directory for static pages:
rails generate gakubuchi:install -d html
They will install the initializer into config/initializers/gakubuchi.rb and create the directory in app/assets.
If you don't specify the -d option, templates will be used as default.
Usage
In app/assets/templates/404.html.slim:
doctype html
html
head
title The page you were looking for doesn't exist (404)
meta name='viewport' content='width=device-width,initial-scale=1'
= stylesheet_link_tag 'application', media: 'all'
body
.dialog
div
h1 The page you were looking for doesn't exist.
p You may have mistyped the address or the page may have moved.
p If you are the application owner check the logs for more information.
Open the following URL in your browser to check the templeate:
http://localhost:3000/assets/404.html
Compile the templeate with:
rake assets:precompile
This will generate public/404.html.
Template engines
Gakubuchi supports some template engines: ERB, Haml and Slim.
If you want to use Haml or Slim, you need to put them in your Gemfile:
# Use Haml
gem 'haml-rails'
# Use Slim
gem 'slim-rails'
Using assets
Gakubuchi enables you to use assets (e.g. CSS or JavaScript files) in static pages.
Note that you may need to add them to the precompile array in config/initializers/assets.rb:
Rails.application.config.assets.precompile += %w(error.css error.js)
Using helpers
You can also use helpers provided by Sprockets::Rails::Helper in static pages.
Examples of them are given below.
asset_pathcontent_tagfavicon_link_tagimage_tagjavascript_include_tag
If you want to get the list of all available helpers, please execute the following code.
Sprockets::Rails::Helper.instance_methods
Configuration
In config/initializers/gakubuchi.rb, you can configure the following values.
leave_digest_named_templates # false by default
template_directory # 'templates' by default
Contributing
You should follow the steps below.
- Fork the repository
- Create a feature branch:
git checkout -b add-new-feature - Commit your changes:
git commit -am 'add new feature' - Push the branch:
git push origin add-new-feature - Send us a pull request
We use Appraisal to test with different versions of Rails.
bundle install
appraisal install
# Run rspec with a specific version of Rails
appraisal rails42x rspec
# Run rspec with all versions of Rails
appraisal rspec
License
MIT License. Copyright 2015 Yuichi Goto.