README.md in boring_presenters-0.1.0 vs README.md in boring_presenters-0.1.1
- old
+ new
@@ -1,29 +1,60 @@
# Boring
+## Because your presentation layer shouldn't be interesting
-Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/boring`. To experiment with that code, run `bin/console` for an interactive prompt.
+[![Gem Version](https://badge.fury.io/rb/boring_presenters.svg)](https://badge.fury.io/rb/boring_presenters) [![Build Status](https://travis-ci.org/apsislabs/boring.svg?branch=master)](https://travis-ci.org/apsislabs/boring) [![Inline docs](http://inch-ci.org/github/apsislabs/boring.svg?branch=master)](http://inch-ci.org/github/apsislabs/boring)
-TODO: Delete this and the text above, and describe your gem
+**Note:** while we're actively using `boring` in production, it is still actively under development, and you should expect breaking changes.
-## Installation
+## Usage
-Add this line to your application's Gemfile:
+Below is an example of usage for a classic Rails controller/view pattern.
```ruby
-gem 'boring'
-```
+# presenters/user_presenter.rb
-And then execute:
+class UserPresenter < Boring::Presenter
+ # Declare the arguments needed to bind to presenter and their type
+ arguments user: User
- $ bundle
+ # Declare pass-through methods
+ delegate :birth_date, to: :user
-Or install it yourself as:
+ # Methods to be handled by the presenter
+ def name
+ "#{user.first_name} #{user.last_name}".strip
+ end
+end
- $ gem install boring
+# controllers/users_controller.rb
-## Usage
+class UsersController < ApplicationController
+ def index
+ @users = User.all
+ @user_presenter = UsersPresenter.new
+ end
+end
+```
-TODO: Write usage instructions here
+```erb
+# views/users/index.html.erb
+
+<ul>
+ <% @users.each do |user| %>
+ <% @user_presenter.bind(user: user) %>
+ <li>
+ <p>Full Name: <%= @user_presenter.name %></p>
+ <p>Birthday: <%= @user_presenter.birth_date %></p>
+ </li>
+ <% end %>
+</ul>
+```
+
+Some things worth noting that set `boring` apart from other presentation layers:
+
+1. **Explicit Delegation**: only methods intended for presentation layer should be allowed in the presenter. `boring` will never pass `super_dangerous_method!` through to your bound object unless you _want_ it to.
+2. **Type-Safe Bindings**: the `arguments` method in the `Boring::Presenter` class lets you set up type checking for the arguments passed to the `bind` method. If you try to bind a `Foo` to your `BarPresenter`, we'll raise an exception.
+3. **Separate Objects**: The presenter doesn't take over for your bound object; whether that bound object is available to your view is up to you, but you should never be unsure if you're dealing with a `Foo` or a `FooPresenter`.
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.