A Rails3 content management engine
Ruby JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
app/models
db/migrate
lib
script
spec
.gitignore
.rspec
.travis.yml
CHANGELOG.rdoc
Gemfile
Guardfile
MIT-LICENSE
README.rdoc
Rakefile
manageable_content.gemspec

README.rdoc

ManageableContent Build Status

Manageable Content is a Rails 3.1 Engine that provides a simple framework for content management. It works by providing a Page instance for each of your configured controllers, so that each controller can have it's own contents that will be available to the views. You can also have shared contents.

Contributing

This engine is a work in progress and open for contributions! Please don't forget to add tests if you plan on contributing.

Installation

This gem is compatible with Rails 3.1. To install it, add the following to your Gemfile:

gem 'manageable_content'

After that, run the 'bundle' command to install the gem.

The next step is to import the engine migrations to your application. Just run this:

bundle exec rake manageable_content_engine:install:migrations

Then migrate your database with the usual command:

bundle exec rake db:migrate

The last step is to include the Dsl in where you want to make the ManageableContent engine available. For example, you might want to add the following code to your ApplicationController:

include ManageableContent::Controllers::Dsl

Getting Started

ManageableContent supports two types of contents: a controller content, and a layout content. A controller content is a content that each controller will have by its own. For example, you might want to have a 'body' content, in which each controller will have a different value for it. A layout content is a content that will be shared between controllers. For example, you might want to have a 'footer' content that will be shared accross all of your controllers.

Controller contents

Supposing that you have a controller named ContactController and you want it to have its own 'body' content. You will need to add this to the controller code:

manageable_content_for :body

After that, run the following rake task:

bundle exec rake manageable_content:generate

This rake task will check your controllers configurations and will generate the corresponding pages for each controller with their contents. This should be run everytime a new controller or page content is added. This rake task just calls the ManageableContent::Manager.generate! method. You might want to add some kind of hook so that when you deploy your application the generator will run.

You might also want to have an administration interface to edit you pages contents. Currently, this engine does not provide that, but you can check an admin example here: github.com/fabiokr/manageable_content_example_app/

Now, to use this in your views, you have to use the manageable_content_for helper:

manageable_content_for :body

This will print the content 'body' for the current controller, if it exists. This will print the content with html_safe.

If you need a content that all your controllers will have (for example, a 'title' content), you can add the configuration to your parent controller and all controllers that inherit from it will also have that content. For example, you could add this to your ApplicationController:

manageable_content_for :title

Custom contents

If you need custom pages that are not directly controller related, you can configure them using an initializer:

ManageableContent::Engine.config.custom_pages = {
  "static/page1" => {:body => :text},
  "static/page2" => {:body => :text, :footer => :string}
}

This work in the same way as controller pages. The example above would create two pages with the keys “static/page1” and “static/page2” respectivelly.

To be able to use the helpers to retrieve the content, the controller responsible for the static pages has to tell manageable_content what page key it will be looking for. You can do that with the following code:

manageable_content_custom_key do
  params[:page]
end

This will use the params as the page key to be used by the manageable_content_for helper.

Layout contents

Supposing that your application will have a 'footer' content that should be the same in all of your controllers, you would add this to your ApplicationController:

manageable_layout_content_for :footer

In the views, to print it you need to use the manageable_layout_content_for helper:

manageable_layout_content_for :footer

Different layouts

In the previous example, the 'footer' content is available under the 'application' page. By default, manageable_layout_content_for uses the current controller default layout, which in the ApplicationController case is 'application'. If you need to add a content to a different layout, you could use this:

manageable_layout_content_for :footer, :layout => 'my_custom_layout'

I18n

If you need different contents for multiple locales, you can generate multiple pages for each available locale. You just need to set the available locales for ManageableContent, and then when you run the generator task it will generate contents for all available locales. To do that, just add an initializer with this content:

ManageableContent::Engine.config.locales = [:en, :pt]

By default, this will be set as the same as your application config.i18n.default_locale.

In your views, the helper calls will remain the same. The helpers use I18n.locale to get the current locale and than will use the content available for that locale.

Specs

To run the specs, first you need to setup the dummy application database and clone it for the test environment:

rake app:db:schema:load
rake app:db:test:clone

Now you can run the specs with this:

rake spec

Contributors

github.com/fabiokr/manageable_content/contributors

Maintainers

License

MIT License. Copyright 2011 Fabio Kreusch www.kreusch.com.br