No commit activity in last 3 years
No release in over 3 years
A simple decorator for Rails.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
~> 2.16.1
~> 1.1.1
~> 10.0
~> 3.6.0
~> 1.3

Runtime

< 6.0, >= 4.0.0
 Project Readme

TrivialDecorator Build Status

A simple decorator for Rails.

Installation

Add this line to your application's Gemfile:

gem 'trivial_decorator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install trivial_decorator

Usage

Writing Decorators

Decorators inherit from TrivialDecorator::Base, live in your app/decorators directory, and are named for the model that they decorate:

# app/decorators/user_decorator.rb

class UserDecorator < TrivialDecorator::Base
  def full_name
    first_name + " " + last_name
  end
end

Accessing helpers

# app/decorators/user_decorator.rb

class UserDecorator < TrivialDecorator::Base
  def full_name
    h.content_tag(:strong, first_name + " " + last_name)
  end
end

Decorating Objects

# app/controllers/users_controller.rb

class UsersController < ApplicationController
  def index
    @users = decorate(User.all)
  end
end

This will use UserDecorator, if you want to use other decorator, just pass his class name as second param to decorate.

# app/controllers/users_controller.rb

class UsersController < ApplicationController
  def index
    @users = decorate(User.all, OtherDecorator)
  end
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/dbackowski/trivial_decorator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the TrivialDecorator project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.