frosting 0.0.8 → 0.0.9
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/README.md +22 -0
- data/frosting.gemspec +2 -2
- data/lib/frosting/base_presenter.rb +8 -0
- data/lib/frosting/version.rb +1 -1
- data/spec/frosting/base_presenter_spec.rb +12 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 337ac58290f8d356a9f291a02ba984c3fa88aa84
|
4
|
+
data.tar.gz: 01fc27e16355aa7a309b71d08715eba73515ec7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 396a4401e0921fc497282271bdc3b29cdc6498d2c1e14e5e4c1ee3201720495ecb3fab2781a617d630a039c786787339825af6a162ad04feb1f0564f0cb70c81
|
7
|
+
data.tar.gz: a08333ed8867e1359669ac136846bc1da93e8ec514431b83200d459080eeb8af06b1a3c371282735f2f5257fa7c7ada2a492851585467bc19c04023437a3c501
|
data/README.md
CHANGED
@@ -36,6 +36,28 @@ You defined `#old?` in your model because it's not a presentation concern. Good
|
|
36
36
|
|
37
37
|
You can also call `present_collection @posts` should you be dealing with a collection of posts and want them all to be presented.
|
38
38
|
|
39
|
+
## Presenting Associations
|
40
|
+
|
41
|
+
As an additional trick, if you find yourself writing code like:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
def user
|
45
|
+
present super(), context: @context
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
in order to have your presented `Post` return a presenter for the associated `User`, then you can save some typing with:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
presents_super :user
|
53
|
+
```
|
54
|
+
|
55
|
+
The `presents_super` method accepts `options`, so you can specify a presenter:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
presents_super :user, options: { presenter: SomeCustomPresenter }
|
59
|
+
```
|
60
|
+
|
39
61
|
## About Foraker Labs
|
40
62
|
|
41
63
|

|
data/frosting.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'frosting'
|
3
|
-
s.version = '0.0.
|
4
|
-
s.date = '2016-03-
|
3
|
+
s.version = '0.0.9'
|
4
|
+
s.date = '2016-03-22'
|
5
5
|
s.summary = "Let's make presenters easy."
|
6
6
|
s.description = "Adds some methods to your controllers and a base presenter. Get that presentation logic out of your models."
|
7
7
|
s.authors = ["Ben Eddy", "Jon Evans"]
|
@@ -5,6 +5,14 @@ module Frosting
|
|
5
5
|
class BasePresenter < SimpleDelegator
|
6
6
|
include Presentation
|
7
7
|
|
8
|
+
def self.presents_super(*methods, options: {})
|
9
|
+
methods.each do |method|
|
10
|
+
define_method(method) do
|
11
|
+
present super(), options.merge(context: @context)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
8
16
|
def initialize(resource, context = nil)
|
9
17
|
@context = context
|
10
18
|
@wrapped = resource
|
data/lib/frosting/version.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
require File.expand_path("../../../lib/frosting/base_presenter", __FILE__)
|
2
2
|
|
3
3
|
module Frosting
|
4
|
+
class AssociatedTestPresenter < BasePresenter; end
|
5
|
+
|
4
6
|
class TestPresenter < BasePresenter
|
7
|
+
presents_super :associated_test, options: {
|
8
|
+
presenter: AssociatedTestPresenter
|
9
|
+
}
|
10
|
+
|
5
11
|
def page_title
|
6
12
|
"Page Title"
|
7
13
|
end
|
@@ -17,7 +23,7 @@ module Frosting
|
|
17
23
|
|
18
24
|
describe TestPresenter do
|
19
25
|
let(:context) { double(root_url: "/home") }
|
20
|
-
let(:resource) { double(name: "bruce wayne") }
|
26
|
+
let(:resource) { double(name: "bruce wayne", associated_test: double) }
|
21
27
|
|
22
28
|
subject { described_class.new(resource, context) }
|
23
29
|
|
@@ -32,5 +38,9 @@ module Frosting
|
|
32
38
|
it "delegates to the context" do
|
33
39
|
subject.root_url.should == "/home"
|
34
40
|
end
|
41
|
+
|
42
|
+
it "presents result of resource methods with `presents_super`" do
|
43
|
+
subject.associated_test.should be_a AssociatedTestPresenter
|
44
|
+
end
|
35
45
|
end
|
36
|
-
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frosting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Eddy
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-03-
|
12
|
+
date: 2016-03-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|