classic_presenter 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,12 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- classic_presenter (0.0.1)
4
+ classic_presenter (1.0.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
+ coderay (1.0.9)
9
10
  diff-lcs (1.1.3)
11
+ method_source (0.8.1)
12
+ pry (0.9.12.1)
13
+ coderay (~> 1.0.5)
14
+ method_source (~> 0.8)
15
+ slop (~> 3.4)
10
16
  rspec (2.10.0)
11
17
  rspec-core (~> 2.10.0)
12
18
  rspec-expectations (~> 2.10.0)
@@ -15,10 +21,12 @@ GEM
15
21
  rspec-expectations (2.10.0)
16
22
  diff-lcs (~> 1.1.3)
17
23
  rspec-mocks (2.10.1)
24
+ slop (3.4.4)
18
25
 
19
26
  PLATFORMS
20
27
  ruby
21
28
 
22
29
  DEPENDENCIES
23
30
  classic_presenter!
31
+ pry
24
32
  rspec
data/README.rdoc CHANGED
@@ -21,11 +21,11 @@ gem install classic_presenter
21
21
 
22
22
  class ProductPresenter < ClassicPresenter::Base
23
23
  def display_name
24
- if user
25
- context.content_tag :strong, name
24
+ if context.user_logged_in?
25
+ name
26
26
  else
27
- context.link_to name, context.product_path
28
- end
27
+ context.link_to name, context.product_path
28
+ end
29
29
  end
30
30
 
31
31
  def display_description
@@ -35,16 +35,31 @@ gem install classic_presenter
35
35
 
36
36
  * In your view, show.html.erb for example, you can present your Product object using this syntax:
37
37
 
38
- <% present ProductPresenter, @product, :user => current_user do |presenter| %>
38
+ <% present ProductPresenter, @product do |presenter| %>
39
39
  <%= presenter.display_name %>
40
40
  <%= presenter.display_description %>
41
41
  <% end %>
42
42
 
43
- == Additional details
43
+ == Cool Features
44
44
 
45
- * We can pass many objects to the presenter. In this example we are using :user => current_user and current_user is a helper that returns a User that is logged in. But we can use this for example:
45
+ * You can decorates a collection of objects with your presenter:
46
46
 
47
- <% present ProductPresenter, @product, :foo => "bar", :bar => "foo" do |presenter| %>
47
+ #products_controller.rb
48
+ @products = ProductPresenter.map(Post.all, view_context)
49
+
50
+ * Inside of the presenter we have an access to the context. In the example above the context is the View(ActionView), then we can access any method like
51
+ link_to, number_to_currency etc directly.
52
+
53
+ * You can also instantiate your presenter in the controller using the view_context and then to access any helper method like number_to_currency:
54
+
55
+ #products_controller.rb
56
+ @product = ProductPresenter.new(Product.find(params[:id]), view_context)
57
+
58
+ class ProductPresenter < ClassicPresenter::Base
59
+ def price
60
+ context.number_to_currency(price, :precision => 3)
61
+ end
62
+ end
48
63
 
49
64
  * Since ClassicPresenter::Base is a Decorator, it implements the “transparent interface” requirements of the Gang of Four’s definition. This means that when we call some method in ProductPresenter, it will be delegated to the decorated object (in this case Product), like this:
50
65
 
@@ -55,7 +70,25 @@ gem install classic_presenter
55
70
  <%= @product.name %>
56
71
  <%= @product.display_name %>
57
72
 
73
+ == License
58
74
 
75
+ (The MIT License)
59
76
 
77
+ Permission is hereby granted, free of charge, to any person obtaining
78
+ a copy of this software and associated documentation files (the
79
+ 'Software'), to deal in the Software without restriction, including
80
+ without limitation the rights to use, copy, modify, merge, publish,
81
+ distribute, sublicense, and/or sell copies of the Software, and to
82
+ permit persons to whom the Software is furnished to do so, subject to
83
+ the following conditions:
60
84
 
85
+ The above copyright notice and this permission notice shall be
86
+ included in all copies or substantial portions of the Software.
61
87
 
88
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
89
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
90
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
91
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
92
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
93
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
94
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -19,4 +19,5 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_development_dependency "rspec"
22
+ s.add_development_dependency "pry"
22
23
  end
@@ -12,6 +12,10 @@ module ClassicPresenter
12
12
  @context = context
13
13
  super model
14
14
  end
15
+
16
+ def self.map(collection, context = nil)
17
+ collection.map {|item| self.new(item, context)}
18
+ end
15
19
  end
16
20
  end
17
21
 
@@ -1,3 +1,3 @@
1
1
  module ClassicPresenter
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -1,23 +1,35 @@
1
1
  require File.dirname(__FILE__) + "/spec_helper"
2
2
 
3
3
  describe ClassicPresenter::Base do
4
- let(:decorated_object) { decorated_object = [] }
5
- let(:context) { double }
6
- let(:objects) { {:foo => :bar, :bar => :foo} }
4
+ describe "instance methods" do
5
+ let(:decorated_object) { decorated_object = [] }
6
+ let(:context) { double }
7
+ let(:objects) { {:foo => :bar, :bar => :foo} }
7
8
 
8
- subject { described_class.new decorated_object, context, objects }
9
+ subject { described_class.new decorated_object, context, objects }
9
10
 
10
- it "delegates all methods to decorated object" do
11
- decorated_object.should_receive(:size)
12
- subject.size
13
- end
11
+ it "delegates all methods to decorated object" do
12
+ decorated_object.should_receive(:size)
13
+ subject.size
14
+ end
15
+
16
+ it "assigns all objects" do
17
+ subject.foo.should == :bar
18
+ subject.bar.should == :foo
19
+ end
14
20
 
15
- it "assigns all objects" do
16
- subject.foo.should == :bar
17
- subject.bar.should == :foo
21
+ it "assigns the context" do
22
+ subject.context.should == context
23
+ end
18
24
  end
19
25
 
20
- it "assigns the context" do
21
- subject.context.should == context
26
+ describe "class methods" do
27
+ let(:collection) { [double] }
28
+ subject { described_class }
29
+
30
+ it "maps a collection with a presenter" do
31
+ decorated_collection = described_class.map collection
32
+ decorated_collection[0].class.should eq ClassicPresenter::Base
33
+ end
22
34
  end
23
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: classic_presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-21 00:00:00.000000000Z
12
+ date: 2013-06-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70257448795260 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,28 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70257448795260
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: pry
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
25
46
  description: A simple Presenter Pattern for Rails Applications
26
47
  email:
27
48
  - rinaldifonseca@gmail.com
@@ -65,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
86
  version: '0'
66
87
  requirements: []
67
88
  rubyforge_project: classic_presenter
68
- rubygems_version: 1.8.15
89
+ rubygems_version: 1.8.23
69
90
  signing_key:
70
91
  specification_version: 3
71
92
  summary: A simple Presenter Pattern for Rails Applications