frosting 0.0.9 → 0.0.10
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 +8 -3
- data/frosting.gemspec +2 -2
- data/lib/frosting/base_presenter.rb +6 -3
- data/lib/frosting/version.rb +1 -1
- data/spec/frosting/base_presenter_spec.rb +24 -6
- 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: 76768395e1d62320be27c15f98ad620143924346
|
4
|
+
data.tar.gz: 80754a95ef7eed2f0921861d43dc2a7fc79f03c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a7effca8e8dbf480874e7497e0e5286b2cb7411895ea06bfd7a29b95e228cce943205a348e0be53fb745a11144ddac179746d2e66bb0cfb907e25618be1461e
|
7
|
+
data.tar.gz: 0529387efcb23a139819bb1da19c9838a58bcd705299233458b705da161d0ba844d21700ecc07d822eb012017c2735b2da7663eb07c915fd863c27f8dea700e1
|
data/README.md
CHANGED
@@ -52,10 +52,16 @@ in order to have your presented `Post` return a presenter for the associated `Us
|
|
52
52
|
presents_super :user
|
53
53
|
```
|
54
54
|
|
55
|
-
The `presents_super` method accepts
|
55
|
+
The `presents_super` method accepts options, so you can specify a presenter:
|
56
56
|
|
57
57
|
```ruby
|
58
|
-
presents_super :user,
|
58
|
+
presents_super :user, presenter: SomeCustomPresenter
|
59
|
+
```
|
60
|
+
|
61
|
+
You can also use `presents_super` for collections, by passing the `collection` option:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
presents_super :users, collection: true
|
59
65
|
```
|
60
66
|
|
61
67
|
## About Foraker Labs
|
@@ -65,4 +71,3 @@ presents_super :user, options: { presenter: SomeCustomPresenter }
|
|
65
71
|
Foraker Labs builds exciting web and mobile apps in Boulder, CO. Our work powers a wide variety of businesses with many different needs. We love open source software, and we're proud to contribute where we can. Interested to learn more? [Contact us today](https://www.foraker.com/contact-us).
|
66
72
|
|
67
73
|
This project is maintained by Foraker Labs. The names and logos of Foraker Labs are fully owned and copyright Foraker Design, LLC.
|
68
|
-
|
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-
|
3
|
+
s.version = '0.0.10'
|
4
|
+
s.date = '2016-04-06'
|
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,10 +5,13 @@ module Frosting
|
|
5
5
|
class BasePresenter < SimpleDelegator
|
6
6
|
include Presentation
|
7
7
|
|
8
|
-
def self.presents_super(*
|
9
|
-
|
8
|
+
def self.presents_super(*arguments)
|
9
|
+
options = arguments.last.is_a?(Hash) ? arguments.pop : {}
|
10
|
+
present_method = options.delete(:collection) ? :present_collection : :present
|
11
|
+
|
12
|
+
arguments.each do |method|
|
10
13
|
define_method(method) do
|
11
|
-
|
14
|
+
send(present_method, super(), options.merge(context: @context))
|
12
15
|
end
|
13
16
|
end
|
14
17
|
end
|
data/lib/frosting/version.rb
CHANGED
@@ -4,9 +4,9 @@ module Frosting
|
|
4
4
|
class AssociatedTestPresenter < BasePresenter; end
|
5
5
|
|
6
6
|
class TestPresenter < BasePresenter
|
7
|
-
presents_super :
|
8
|
-
|
9
|
-
|
7
|
+
presents_super :associated_test_1
|
8
|
+
presents_super :associated_test_2, presenter: AssociatedTestPresenter
|
9
|
+
presents_super :associated_collection, collection: true
|
10
10
|
|
11
11
|
def page_title
|
12
12
|
"Page Title"
|
@@ -22,11 +22,21 @@ module Frosting
|
|
22
22
|
end
|
23
23
|
|
24
24
|
describe TestPresenter do
|
25
|
-
let(:context)
|
26
|
-
let(:
|
25
|
+
let(:context) { double(root_url: "/home") }
|
26
|
+
let(:associated_class) { double(name: "AssociatedTest") }
|
27
|
+
let(:resource) do
|
28
|
+
double(
|
29
|
+
name: "bruce wayne",
|
30
|
+
associated_test_1: double(class: associated_class),
|
31
|
+
associated_test_2: double,
|
32
|
+
associated_collection: [double(class: associated_class)]
|
33
|
+
)
|
34
|
+
end
|
27
35
|
|
28
36
|
subject { described_class.new(resource, context) }
|
29
37
|
|
38
|
+
before { stub_const('Presenters::AssociatedTest', AssociatedTestPresenter) }
|
39
|
+
|
30
40
|
it "responds to defined methods" do
|
31
41
|
subject.page_title.should == "Page Title"
|
32
42
|
end
|
@@ -40,7 +50,15 @@ module Frosting
|
|
40
50
|
end
|
41
51
|
|
42
52
|
it "presents result of resource methods with `presents_super`" do
|
43
|
-
subject.
|
53
|
+
subject.associated_test_1.should be_a Presenters::AssociatedTest
|
54
|
+
end
|
55
|
+
|
56
|
+
it "correctly accepts presentation options with `presents_super`" do
|
57
|
+
subject.associated_test_2.should be_a AssociatedTestPresenter
|
58
|
+
end
|
59
|
+
|
60
|
+
it "presents a collection of resources with `presents_super`" do
|
61
|
+
subject.associated_collection.first.should be_a Presenters::AssociatedTest
|
44
62
|
end
|
45
63
|
end
|
46
64
|
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.10
|
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-
|
12
|
+
date: 2016-04-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|