CatRouter - The most simplistic CMS in the world

CatRouter is a simple router/CMS for displaying dynamic content on your site. Buttons with content are defined in the database (using CatRoute model). A click of a button displays it’s content (yield).

Copyright © 2011 [Kristijan Sedlak], released under the MIT license

Installation (Rails 3 ready)

NOTE: If you are upgrading please recreate the database table!

Add this line to your Gemfile (and run bundle install):

gem 'cat_router'

Generate migration

rails g cat_router
rake db:migrate

Open config/routes.rb and add this to the end

# define custom routes CatRouter::Routes.draw action.
# scope "(/:locale)" do
#   match 'my_slug', :to => "controller#action"
# end

# CatRouter implementation (application controller will handle all requests 
# over a handle_cat_routes action)
CatRouter::Routes.draw('application#handle_cat_routes')

Open app/controllers/application_controller.rb and load it

class ApplicationController < ActionController::Base
  acts_as_cat_router
end

The plugin comes with a CatRoute model. You can append the default model or controller by creating a new app/models/cat_route.rb file with content

class CatRoute
end

Examples


First you create a root button. By default :locale is set to value of I18n.locale and :domain is not set (which means the route is defined for all domains).

rootRoute = CatRoute.create(:slug => ':root', :title => 'Home', :html => 'This is my home content.')
rootRoute = CatRoute.create(:slug => ':root', :title => 'Home', :html => 'This is my home content.', :locale => 'en')
rootRoute = CatRoute.create(:slug => ':root', :title => 'Home', :html => 'This is my home content.', :locale => 'en', :domain => 'mydomain.com')

You can then create a route for the main menu.

myRoute = CatRoute.create(:title => 'About us', :html => '<b>This is the about page.</b>')

The plugin will automatically generate the :slug value but you can set it manually.

myRoute = CatRoute.create(:title => 'Welcome', :html => '<b>welcome</b>', :slug => 'home/first_page')

You can also create a subroute (a sub button of myRoute).

mySubRoute = myRoute.cat_routes.create(:title => 'About', :html => 'about us html')

You can also create a button that redirects to some external website.

myRoute = CatRoute.create(:slug => ':redirect_to', :html => 'http://lotterade.com', :title => 'Home')

You can get a list of subbuttons

mySubRoutes = CatRoute.find(13).cat_routes

To get the list of main buttons for your main menu, you will use

mainButtons = CatRoute.base_routes.with_locale('en').with_or_no_domain('mydomain.com')

You get a root button like this

rootButton = CatRoute.root_routes.with_locale('en').first

You get a button by slug like this

button = CatRoute.with_slug('about/our_business').first

You can reorder the default order of buttons by setting the order column

button = CatRoute.with_slug('about/our_business').first

The @cat_route variable is also available (defined inside CatRoutesController) which holds the current route record.

Using HAML you will define a main-menu like this

.mainmenu
 - CatRoute.base_routes.with_locale(I18n.locale).with_or_no_domain(request.host).ordered.each do |b|
   = link_to b.title, b.url, :class => b.slug == @cat_route.slug || b.id == @cat_route.parent_id ? 'selected' : ''

and a sub-menu like this

.submenu
 - @cat_route.cat_routes_or_neighbours.ordered.each do |b|
   = link_to b.title, b.url, :class => b.slug == @cat_route.slug || b.id == @cat_route.parent_id ? 'selected' : ''