A Rails engine which adds a simple cms to your rails project.
Add the following to your Gemfile:
gem 'cms', git: '[email protected]:sewa/cms.git', branch: 'master'
Copy and run migrations:
rake cms:install:migrations
rake db:migrate
Mount the engine:
mount Cms::Engine, at: '/cms'
Start the rails server and access the cms with:
http://localhost:3000/cms
The cms consists of three different types of entities.
- Cms::ContentNode
- Cms::ContentComponent
- Cms::ContentAttribute
In the following section i will give an overview over each of these entities.
The engine expects all content nodes to be placed in app/models/content_nodes. Here is an example:
class ExampleNode < Cms::ContentNode
template 'page'
child_nodes :all
use_components :all
content_group :content do
content_attribute :heading, :string
content_attribute :body, :text
content_attribute :rotator, :image_list
end
end
Let's discuss the class methods:
template
is used to tell the client which template should be rendered.
child_nodes :all
tells the engine that this page can have all page types as subnodes. Other possible values are:
child_nodes except: ['ExampleNode', ...]
child_nodes only: ['ExampleNode', ...]
If child_nodes is not defined the page can't have any childpages.
The same options you have with use_components:
use_components :all
use_components except: ['ExampleComponent', ...]
use_components only: ['ExampleComponent', ...]
To define a grouping of attributes use:
content_group :content
And finally the actual content is defined with:
content_attribute :name, :type
class ExampleComponent < Cms::ContentComponent
content_attribute :heading, :string
content_attribute :body, :text
content_attribute :rotator, :image_list
end
class ExampleAttribute < Cms::ContentComponent
content_type :string
end
The cms has no built in authentication.
It uses cancan for authorization, the rest is up to you.
To hook your user into the cms you have to create the initializer config/initializers/cms.rb and add the following code to it:
Cms.user_class = 'Your user class'
Cms.user_roles_attribute = 'your roles method on user'