Sha256: f87abf5c7bc863ecac7000b0e0507f26854bb09436d3cc20e7342c76742c67b4

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

# BasePresenter

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

## Usage

In director root_rails/app/presenters create file example_presenter.rb with content

```ruby
class ExamplePresenter < BasePresenter
  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`

```erb
<% present @example do |presenter| %>
  Id: <%= presenter.id %>
  Name: <%= presenter.name %>
  Url: <%= presenter.link_to_example %>
<% end %>
```

* class `Example`

```erb
<% present Example do |presenter| %>
  Class name: <%= presenter.class_name %>
<% end %>
```
## Methods

Methods of BasePresenter

Method returns span with 'None given' when value is blank
```erb
#handle_none(value)
```

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
base_presenter-0.0.8 README.md
base_presenter-0.0.7 README.md