A markdown pages system for Selectra's apps
Ruby JavaScript CSS
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
lib
test
.gitignore
Gemfile
MIT-LICENSE
README.md
Rakefile
selectra_pages.gemspec

README.md

SelectraPages

A markdown pages system for Selectra's apps.

Installation

Add the following line in your Gemfile :

gem 'selectra_pages', '>= 0.0.3'

Then call bundle install in the root folder of your app.

Once that's done, use this rake task to copy the migration file to your app and the run it.

rake selectra_pages_engine:install:migrations
rake db:migrate

Routing

To add the pages system, add the following in your config/routes.rb file :

pages_at('/pages/*url')

This will tell your app to load a page found by it's url field when you visit http://example.com/pages/url-of-the-page.

Alternatively, it is possible to use pages as default component of the app :

pages_at('/*url')

This will allow to visit pages using http://example.com/url-of-the-page.

Page fields

title             string(100) # Title of the page
body              text        # Body of the page
url               string(100) # URL used to find the page
classes           string(100) # CSS Classes that apply to the page
description       string(170) # Meta Description of the page

Views

There is only one view provided by SelectraPages, it's the pages/show view. You can override it by creating a file named app/views/pages/show.html.{erb|slim|haml} :

# app/views/pages/show.html.erb

<h1><%= @page.title %></h1>

<%= markdown @page.body %>

The pages use by default a Markdown syntax, that why this gem depends on selectra_mustdown.

If you override the view, you can use anything you want instead of markdown.

Here you can choose to use textile if you prefer it. Just be sure to install required libraries, RedCloth in that case.

# app/views/pages/show.html.erb

<h1><%= @page.title %></h1>

<%= textilize @page.body %>

Caching

Pages are cached automaticaly when caching is enabled.

SelectraPages provides a cache sweeper called PageSweeper. You can use it in your ActiveAdmin configuration:

ActiveAdmin.register Page do
  controller do
    cache_sweeper :page_sweeper
  end
end

Admin

SelectraPages provides a generator to create ActiveAdmin resource for the Page model.

rails generate selectra_pages:admin