Skip to content

Commit

Permalink
documentations
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsuda committed Dec 2, 2011
1 parent 0582b0c commit 0db9c7b
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 2 deletions.
20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2011 Akira Matsuda

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# ActiveDecorator

A simple and Rubyish view helper for ActiveRecord models. Keep your helpers and views Object-Oriented!


## Features ##

1. automatically mixes decorator module into corresponding model only when:
1. passing a model or collection of models or an instance of ActiveRecord::Relation from controllers to views
2. rendering partials with models (using `:collection` or `:object` or `:locals` explicitly or implicitly)
2. the decorator module runs in the model's context. So, you can directly call any attributes or methods in the decorator module
3. since decorators are considered as sort of helpers, you can also call any ActionView's helper methods such as `content_tag` or `link_to`


## Supported versions ##

Rails 3.0.x, 3.1.x, and 3.2 (edge)


## Usage ##

1. bundle 'active_decorator' gem
2. create a decorator module for each AR model. For example, a decorator for a model `User` should be named `UserDecorator`.
You can use the generator for doing this ( `% rails g decorator user` )
3. Then it's all done. Without altering any single line of the existing code, the decorator modules will be automatically mixed into your models only in the view context.


## Examples ##

# app/models/user.rb
class User < ActiveRecord::Base
# first_name:string last_name:string website:string
end

# app/decorators/user_decorator.rb
module UserDecorator
def full_name
"#{first_name} #{last_name}"
end

def link
link_to full_name, website
end
end

# app/controllers/users_controller.rb
class UsersController < ApplicationController
def index
User.all
end
end

# app/views/users/index.html.erb
<% @users.each do |user| %>
<%= user.link %><br>
<% end %>


## Contributing to ActiveDecorator ##

* Fork, fix, then send me a pull request.


## Copyright ##

Copyright (c) 2011 Akira Matsuda. See MIT-LICENSE for further details.
4 changes: 2 additions & 2 deletions active_decorator.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Gem::Specification.new do |s|
s.authors = ["Akira Matsuda"]
s.email = ["ronnie@dio.jp"]
s.homepage = ""
s.summary = %q{TODO: Write a gem summary}
s.description = %q{TODO: Write a gem description}
s.summary = %q{A simple and Rubyish view helper for ActiveRecord models}
s.description = %q{A simple and Rubyish view helper for ActiveRecord models}

s.rubyforge_project = "active_decorator"

Expand Down

0 comments on commit 0db9c7b

Please sign in to comment.