boring_presenters 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +11 -1
- data/Gemfile.lock +2 -2
- data/README.md +43 -12
- data/lib/boring/version.rb +1 -1
- data/lib/{boring.rb → boring_presenters.rb} +0 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6100cc5db1af654bd699a54ffcfc6ebad97ed31e
|
4
|
+
data.tar.gz: c038f3d7f3c3ce2deb1196340c2beb7e722986d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81873f9ecddc312e815a3b488691daad0d72795ec373db8e8aa08bd051ac3b8c4bc43204f891ab9b73061ecfba35eaaa5d933f945da064122d8f0e6cdc3ae177
|
7
|
+
data.tar.gz: 1c6b9baef17ca579a7297d9645f3fb589d67922174b3281ec5094711218bea088603eff8ffce15882d4aceb16670e7cf5bf9bb74d79a013c981553d280430011
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
|
4
|
+
boring_presenters (0.1.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -26,7 +26,7 @@ PLATFORMS
|
|
26
26
|
ruby
|
27
27
|
|
28
28
|
DEPENDENCIES
|
29
|
-
|
29
|
+
boring_presenters!
|
30
30
|
bundler (~> 1.16)
|
31
31
|
rake (~> 10.0)
|
32
32
|
rspec (~> 3.0)
|
data/README.md
CHANGED
@@ -1,28 +1,59 @@
|
|
1
1
|
# Boring
|
2
|
+
## Because your presentation layer shouldn't be interesting
|
2
3
|
|
3
|
-
|
4
|
+
[](https://badge.fury.io/rb/boring_presenters) [](https://travis-ci.org/apsislabs/boring) [](http://inch-ci.org/github/apsislabs/boring)
|
4
5
|
|
5
|
-
|
6
|
+
**Note:** while we're actively using `boring` in production, it is still actively under development, and you should expect breaking changes.
|
6
7
|
|
7
|
-
##
|
8
|
+
## Usage
|
8
9
|
|
9
|
-
|
10
|
+
Below is an example of usage for a classic Rails controller/view pattern.
|
10
11
|
|
11
12
|
```ruby
|
12
|
-
|
13
|
-
```
|
13
|
+
# presenters/user_presenter.rb
|
14
14
|
|
15
|
-
|
15
|
+
class UserPresenter < Boring::Presenter
|
16
|
+
# Declare the arguments needed to bind to presenter and their type
|
17
|
+
arguments user: User
|
16
18
|
|
17
|
-
|
19
|
+
# Declare pass-through methods
|
20
|
+
delegate :birth_date, to: :user
|
18
21
|
|
19
|
-
|
22
|
+
# Methods to be handled by the presenter
|
23
|
+
def name
|
24
|
+
"#{user.first_name} #{user.last_name}".strip
|
25
|
+
end
|
26
|
+
end
|
20
27
|
|
21
|
-
|
28
|
+
# controllers/users_controller.rb
|
22
29
|
|
23
|
-
|
30
|
+
class UsersController < ApplicationController
|
31
|
+
def index
|
32
|
+
@users = User.all
|
33
|
+
@user_presenter = UsersPresenter.new
|
34
|
+
end
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
```erb
|
39
|
+
# views/users/index.html.erb
|
40
|
+
|
41
|
+
<ul>
|
42
|
+
<% @users.each do |user| %>
|
43
|
+
<% @user_presenter.bind(user: user) %>
|
44
|
+
<li>
|
45
|
+
<p>Full Name: <%= @user_presenter.name %></p>
|
46
|
+
<p>Birthday: <%= @user_presenter.birth_date %></p>
|
47
|
+
</li>
|
48
|
+
<% end %>
|
49
|
+
</ul>
|
50
|
+
```
|
51
|
+
|
52
|
+
Some things worth noting that set `boring` apart from other presentation layers:
|
24
53
|
|
25
|
-
|
54
|
+
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.
|
55
|
+
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.
|
56
|
+
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`.
|
26
57
|
|
27
58
|
## Development
|
28
59
|
|
data/lib/boring/version.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boring_presenters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wyatt Kirby
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -72,10 +72,10 @@ files:
|
|
72
72
|
- bin/console
|
73
73
|
- bin/setup
|
74
74
|
- boring.gemspec
|
75
|
-
- lib/boring.rb
|
76
75
|
- lib/boring/exceptions.rb
|
77
76
|
- lib/boring/presenter.rb
|
78
77
|
- lib/boring/version.rb
|
78
|
+
- lib/boring_presenters.rb
|
79
79
|
homepage: http://www.apsis.io
|
80
80
|
licenses:
|
81
81
|
- MIT
|