frosting 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 337ac58290f8d356a9f291a02ba984c3fa88aa84
4
- data.tar.gz: 01fc27e16355aa7a309b71d08715eba73515ec7a
3
+ metadata.gz: 76768395e1d62320be27c15f98ad620143924346
4
+ data.tar.gz: 80754a95ef7eed2f0921861d43dc2a7fc79f03c9
5
5
  SHA512:
6
- metadata.gz: 396a4401e0921fc497282271bdc3b29cdc6498d2c1e14e5e4c1ee3201720495ecb3fab2781a617d630a039c786787339825af6a162ad04feb1f0564f0cb70c81
7
- data.tar.gz: a08333ed8867e1359669ac136846bc1da93e8ec514431b83200d459080eeb8af06b1a3c371282735f2f5257fa7c7ada2a492851585467bc19c04023437a3c501
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 `options`, so you can specify a presenter:
55
+ The `presents_super` method accepts options, so you can specify a presenter:
56
56
 
57
57
  ```ruby
58
- presents_super :user, options: { presenter: SomeCustomPresenter }
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
-
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'frosting'
3
- s.version = '0.0.9'
4
- s.date = '2016-03-22'
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(*methods, options: {})
9
- methods.each do |method|
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
- present super(), options.merge(context: @context)
14
+ send(present_method, super(), options.merge(context: @context))
12
15
  end
13
16
  end
14
17
  end
@@ -1,3 +1,3 @@
1
1
  module Frosting
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -4,9 +4,9 @@ module Frosting
4
4
  class AssociatedTestPresenter < BasePresenter; end
5
5
 
6
6
  class TestPresenter < BasePresenter
7
- presents_super :associated_test, options: {
8
- presenter: AssociatedTestPresenter
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) { double(root_url: "/home") }
26
- let(:resource) { double(name: "bruce wayne", associated_test: double) }
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.associated_test.should be_a AssociatedTestPresenter
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.9
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-03-22 00:00:00.000000000 Z
12
+ date: 2016-04-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport