0.0
No commit activity in last 3 years
No release in over 3 years
The gem adds "Presenter" functionality into Rails application.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 3.0.0
>= 0
 Project Readme

BasePresenter

Gem Version Build Status Code Climate Dependency Status Coverage Status

The gem adds "Presenter" functionality into Rails application.

Installation

Add this line to your application's Gemfile:

gem 'base_presenter'

And then execute:

$ bundle

Or install it yourself as:

$ gem install base_presenter

Getting Started

First step

Usa a generator

rails g base_presenter:install [model_name]

Second step

Add line

  include BasePresenter::ApplicationHelper

to ApplicationHelper module in Rails application.

Third step

For model_name equal 'example' we should get file in director root_rails/app/presenters/example_presenter.rb which we can improve. For example:

class ExamplePresenter < ApplicationPresenter
  presents :example
  delegate :id, to: :example

  def name
    "Name"
  end

  def self.class_name
    "Example"
  end

  def link_to_example
    handle_none example.name do
      link_to(example.name, example_path(example))
    end
  end

end

and in file show.html.erb with:

  • object @example
<% present @example do |presenter| %>
  Id: <%= presenter.id %>
  Name: <%= presenter.name %>
  Url: <%= presenter.link_to_example %>
<% end %>
  • class Example
<% present Example do |presenter| %>
  Class name: <%= presenter.class_name %>
<% end %>

Methods

Methods of BasePresenter

Method returns span with 'None given' when value is blank

#handle_none(value)

License

BasePresenter uses the MIT license. Please check the LICENSE file for more details.