https://github.com/davyjoneslocker/pages
Easy pages in Rails
https://github.com/davyjoneslocker/pages
Last synced: 4 months ago
JSON representation
Easy pages in Rails
- Host: GitHub
- URL: https://github.com/davyjoneslocker/pages
- Owner: DavyJonesLocker
- Created: 2012-08-09T19:28:12.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2016-08-26T14:34:11.000Z (almost 10 years ago)
- Last Synced: 2025-06-13T20:18:28.689Z (about 1 year ago)
- Language: Ruby
- Size: 56.6 KB
- Stars: 49
- Watchers: 5
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Pages #
[](http://travis-ci.org/dockyard/pages)
[](https://gemnasium.com/dockyard/pages)
[](https://codeclimate.com/github/dockyard/pages)
Simple dynamic yet static pages for a Rails app
## Installation ##
In your Gemfile add the following:
```ruby
gem 'pages'
```
Then you can either create a `app/views/pages` directory
```
mkdir app/views/pages
```
Or run the generator
```
rails g pages:setup
```
## Usage ##
Simply define new pages in your routes
```ruby
Rails.application.routes.draw do
# Define a single page
page :about
# Define multiple pages
pages :contact, :team
end
```
This will expand to:
```ruby
get '/about' => 'pages#about', :as => :about
```
Then just create a new view
```
touch app/views/pages/about.html.erb
```
And create whatever content you want!
If you'd like to modify the routes that Pages generates, you can alter the
page parameter by passing an options hash containing a block. This is
particularly useful for creating SEO-friendly routes:
```ruby
page :press_kit, :transform => lambda { |page| page.dasherize }
```
would expand to:
```ruby
get '/press-kit' => 'pages#press_kit', :as => :press_kit
```
### Namespacing ###
You can easily namespace pages:
```
namespace :work do
pages :client_1, :client_2
end
```
This will create a `Work::PagesController` dynamically if one does not
already exist. If you chose to create your own it should always inherit
from `::PagesController`. Your views should be put into
`app/views/work/pages/`
### Path Helper Overrides ###
You can optionally override the path helpers by passing a hash to `:as`
```
pages '404', '500', as: { '404' => 'not_found', '500', => 'server_error' }
```
Your views will be `app/views/pages/not_found.html` and
`app/views/pages/server_error.html` and path helpers will be `not_found_path`
and `server_error_path` but the urls will be `/400` and `/500`.
## Authors ##
[Brian Cardarella](http://twitter.com/bcardarella)
[We are very thankful for the many contributors](https://github.com/dockyard/pages/graphs/contributors)
## Versioning ##
This gem follows [Semantic Versioning](http://semver.org)
## Want to help? ##
Stable branches are created based upon each minor version. Please make
pull requests to specific branches rather than master.
Please make sure you include tests!
Unles Rails drops support for Ruby 1.8.7 we will continue to use the
hash-rocket syntax. Please respect this.
Don't use tabs to indent, two spaces are the standard.
## Legal ##
[DockYard](http://dockyard.com), LLC © 2012
[@dockyard](http://twitter.com/dockyard)
[Licensed under the MIT license](http://www.opensource.org/licenses/mit-license.php)