Skip to content

Commit

Permalink
Added support and documentation for decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
kunalchaudhari authored and parndt committed Jul 13, 2012
1 parent e8fc464 commit 646c3e0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,40 @@ If you would like to add auto discovery links for the built in forum Atom feeds,

<%= forem_atom_auto_discovery_link_tag %>

## Customisation
## View Customisation

If you want to customise Forem, you can copy over the views using the (Devise-inspired) `forem:views` generator:

rails g forem:views

You will then be able to edit the forem views inside the `app/views/forem` of your application. These views will take precedence over those in the engine.

## Extending Classes

All of Forem’s business logic (models, controllers, helpers, etc) can easily be extended / overridden to meet your exact requirements using standard Ruby idioms.

Standard practice for including such changes in your application or extension is to create a file within the relevant app/models or app/controllers directory with the original class name with _decorator appended.

### Adding a custom method to the Post model:
# app/decorators/models/forem/post_decorator.rb

Forem::Post.class_eval do
def some_method
...
end
end

### Adding a custom method to the PostsController:
# app/decorators/controllers/forem/posts_controller_decorator.rb

Forem::PostsController.class_eval do
def some_action
...
end
end

The exact same format can be used to redefine an existing method.

## Translations

We currently have support for the following languages:
Expand Down
11 changes: 9 additions & 2 deletions lib/forem/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ def root
end
end

# Fix for #88
config.to_prepare do
def self.activate

Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end

# Fix for #88
if Forem.user_class
Forem.user_class.send :extend, Forem::Autocomplete

Expand All @@ -25,6 +30,8 @@ def root
# add forem helpers to main application
::ApplicationController.send :helper, Forem::Engine.helpers
end

config.to_prepare &method(:activate).to_proc
end
end

Expand Down

0 comments on commit 646c3e0

Please sign in to comment.