0.0
No commit activity in last 3 years
No release in over 3 years
AutoPresenter uses convention over configuration to remove the bolierplate code to use presenters in your rails app
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

>= 3.2.0
 Project Readme

AutoPresenter

Build Status Code Climate

AutoPresenter uses convention over configuration to remove the bolierplate code to use presenters in your rails app. That allows you to cleanly remove the presentation logic from your controllers.

Usage

Let's say you have a controller:

class ProjectsController < ApplicationController

  def show
    @project = Project.find(params[:id])

    @completed_tasks   = @project.tasks.completed
    @uncompleted_tasks = @project.tasks.uncompleted
  end
end

To decorate @completed_tasks just create a presenter in app/presenters/projects/completed_tasks_presenter.rb. If you want to decorate any Task instance variable in your views just create a TaskPresenter in app/presenters/task_presenter.rb. There is no need to change your controller code.

Presenters

Autopresenter doesn't ship with any base presenter class you can inherit from. A presenter can be any object that accepts the decorated object in the initializer and adds presentation methods to it. The ruby standard library is SimpleDelegator usually a good and simple option to implement your delegators. Drapper decorators work well too.

class TaskPresenter < SimpleDelegator

  # This method will be added to Task objects in the views.
  def status
    completed_at.present? ? 'Completed' : 'Uncompleted'
  end
end

Installation

Add AutoPresenter to your Gemfile

  gem 'auto_presenter'

License

Autopresenter is released under the MIT License.