simple_presenter 0.1.3 → 0.2.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.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  .DS_Store
2
2
  pkg
3
3
  tmp
4
+ .tags
data/Gemfile.lock CHANGED
@@ -1,33 +1,28 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_presenter (0.1.3)
4
+ simple_presenter (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- coderay (0.9.8)
9
+ coderay (1.0.8)
10
10
  diff-lcs (1.1.3)
11
- method_source (0.6.7)
12
- ruby_parser (>= 2.3.1)
13
- pry (0.9.7.4)
14
- coderay (~> 0.9.8)
15
- method_source (~> 0.6.7)
16
- ruby_parser (>= 2.3.1)
17
- slop (~> 2.1.0)
18
- rake (0.9.2.2)
19
- rspec (2.8.0)
20
- rspec-core (~> 2.8.0)
21
- rspec-expectations (~> 2.8.0)
22
- rspec-mocks (~> 2.8.0)
23
- rspec-core (2.8.0)
24
- rspec-expectations (2.8.0)
25
- diff-lcs (~> 1.1.2)
26
- rspec-mocks (2.8.0)
27
- ruby_parser (2.3.1)
28
- sexp_processor (~> 3.0)
29
- sexp_processor (3.0.10)
30
- slop (2.1.0)
11
+ method_source (0.8.1)
12
+ pry (0.9.11.1)
13
+ coderay (~> 1.0.5)
14
+ method_source (~> 0.8)
15
+ slop (~> 3.4)
16
+ rake (10.0.3)
17
+ rspec (2.12.0)
18
+ rspec-core (~> 2.12.0)
19
+ rspec-expectations (~> 2.12.0)
20
+ rspec-mocks (~> 2.12.0)
21
+ rspec-core (2.12.2)
22
+ rspec-expectations (2.12.1)
23
+ diff-lcs (~> 1.1.3)
24
+ rspec-mocks (2.12.1)
25
+ slop (3.4.3)
31
26
 
32
27
  PLATFORMS
33
28
  ruby
@@ -35,5 +30,5 @@ PLATFORMS
35
30
  DEPENDENCIES
36
31
  pry
37
32
  rake
38
- rspec (~> 2.7)
33
+ rspec
39
34
  simple_presenter!
data/README.rdoc CHANGED
@@ -25,6 +25,10 @@ If you're using Simple Presenter within Rails, presenters also have access to:
25
25
  * view helpers: just use the <tt>helpers</tt> or <tt>h</tt> methods
26
26
  * I18n methods: just use the <tt>translate</tt>, <tt>t</tt>, <tt>localize</tt> or <tt>l</tt> methods
27
27
 
28
+ If you want to to use <tt>*_url</tt> route methods, make sure you set the <tt>default_url_options</tt> option. You can use the <tt>config.simple_presenter.default_url_options</tt> method, which defaults to <tt>config.action_mailer.default_url_options</tt>. You can add something like the following to your <tt>config/environments/development.rb</tt>, for instance:
29
+
30
+ config.simple_presenter.default_url_options = {:host => "localhost:3000"}
31
+
28
32
  For additional usage, check the specs.
29
33
 
30
34
  == TO-DO
@@ -12,9 +12,20 @@ module SimplePresenter
12
12
  # expose :title, :with => :post # will expose post.title through CommentPresenter#post_title
13
13
  # end
14
14
  #
15
+ # Subjects can be accessed by a private name with the same name.
16
+ # So the above subjects can be accessed internally by the methods +comment+ and +post+.
17
+ #
18
+ # If you're not setting any special name, then you can access it using the +subject+ method.
19
+ #
15
20
  def self.subjects(*names)
16
21
  @subjects ||= [:subject]
17
- @subjects = names unless names.empty?
22
+
23
+ unless names.empty?
24
+ @subjects = names
25
+ attr_reader *names
26
+ private *names
27
+ end
28
+
18
29
  @subjects
19
30
  end
20
31
 
@@ -1,6 +1,6 @@
1
1
  module SimplePresenter
2
- autoload :Base, "simple_presenter/base"
3
- autoload :Version, "simple_presenter/version"
4
-
2
+ require "simple_presenter/base"
3
+ require "simple_presenter/version"
4
+ require "simple_presenter/url_methods"
5
5
  require "simple_presenter/rails" if defined?(Rails)
6
6
  end
@@ -1,28 +1,32 @@
1
1
  module SimplePresenter
2
+ class Railtie < Rails::Railtie
3
+ config.simple_presenter = ActiveSupport::OrderedOptions.new
4
+ end
5
+
2
6
  class Base
7
+ delegate :translate, :t, :localize, :l, :to => :helpers
8
+ private :translate, :t, :localize, :l
9
+
3
10
  private
4
- def translate(*args, &block)
5
- I18n.t(*args, &block)
11
+ def self.routes_module
12
+ @routes_module ||= Module.new do
13
+ include Rails.application.routes.url_helpers
14
+ include UrlMethods
15
+ end
6
16
  end
7
17
 
8
- alias_method :t, :translate
9
-
10
- def localize(*args, &block)
11
- I18n.l(*args, &block)
18
+ def self.routes
19
+ @routes ||= Object.new.extend(routes_module)
12
20
  end
13
21
 
14
- alias_method :l, :localize
15
-
16
22
  def routes
17
- Rails.application.routes.url_helpers
23
+ self.class.routes
18
24
  end
19
-
20
25
  alias_method :r, :routes
21
26
 
22
27
  def helpers
23
28
  ApplicationController.helpers
24
29
  end
25
-
26
30
  alias_method :h, :helpers
27
31
  end
28
32
  end
@@ -0,0 +1,9 @@
1
+ module SimplePresenter
2
+ module UrlMethods
3
+ def default_url_options
4
+ Rails.configuration.simple_presenter.default_url_options ||
5
+ Rails.configuration.action_mailer.default_url_options ||
6
+ {}
7
+ end
8
+ end
9
+ end
@@ -1,8 +1,8 @@
1
1
  module SimplePresenter
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 1
5
- PATCH = 3
4
+ MINOR = 2
5
+ PATCH = 1
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -18,6 +18,6 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
 
20
20
  s.add_development_dependency "rake"
21
- s.add_development_dependency "rspec", "~> 2.7"
21
+ s.add_development_dependency "rspec"
22
22
  s.add_development_dependency "pry"
23
23
  end
data/spec/base_spec.rb CHANGED
@@ -25,7 +25,7 @@ describe SimplePresenter::Base do
25
25
  it "uses provided block" do
26
26
  numbers = []
27
27
  subject.each {|n| numbers << n}
28
- numbers.should == [1, 2, 3]
28
+ expect(numbers).to eql([1, 2, 3])
29
29
  end
30
30
  end
31
31
  end
@@ -57,7 +57,7 @@ describe SimplePresenter::Base do
57
57
  presenter_class.subject :thing
58
58
  presenter = presenter_class.new(thing)
59
59
 
60
- presenter.instance_variable_get("@thing").should eql(thing)
60
+ expect(presenter.instance_variable_get("@thing")).to eql(thing)
61
61
  end
62
62
 
63
63
  context "using defaults" do
@@ -66,6 +66,14 @@ describe SimplePresenter::Base do
66
66
 
67
67
  its(:name) { should == "John Doe" }
68
68
  its(:email) { should == "john@doe.com" }
69
+
70
+ it "responds to private subject method" do
71
+ expect(subject.private_methods).to include(:subject)
72
+ end
73
+
74
+ it "returns subject" do
75
+ expect(subject.send(:subject)).to eql(user)
76
+ end
69
77
  end
70
78
 
71
79
  context "specifying several subjects" do
@@ -77,6 +85,22 @@ describe SimplePresenter::Base do
77
85
  its(:body) { should == "Some comment" }
78
86
  its(:post_title) { should == "Some post" }
79
87
  its(:user_name) { should == "John Doe" }
88
+
89
+ it "responds to private comment method" do
90
+ expect(subject.private_methods).to include(:comment)
91
+ end
92
+
93
+ it "responds to private post method" do
94
+ expect(subject.private_methods).to include(:post)
95
+ end
96
+
97
+ it "returns comment subject" do
98
+ expect(subject.send(:comment)).to eql(comment)
99
+ end
100
+
101
+ it "returns post subject" do
102
+ expect(subject.send(:post)).to eql(post)
103
+ end
80
104
  end
81
105
 
82
106
  context "when subjects are nil" do
@@ -113,7 +137,7 @@ describe SimplePresenter::Base do
113
137
  subject { UserPresenter.new(user) }
114
138
 
115
139
  it "assigns the subject" do
116
- subject.instance_variable_get("@subject").should == user
140
+ expect(subject.instance_variable_get("@subject")).to eql(user)
117
141
  end
118
142
  end
119
143
 
@@ -123,9 +147,9 @@ describe SimplePresenter::Base do
123
147
  context "subjects" do
124
148
  subject { presenter.subjects }
125
149
 
126
- specify { subject.should have(2).items }
127
- specify { subject.first.should eql(:comment) }
128
- specify { subject.last.should eql(:post) }
150
+ specify { expect(subject).to have(2).items }
151
+ specify { expect(subject.first).to eql(:comment) }
152
+ specify { expect(subject.last).to eql(:post) }
129
153
  end
130
154
 
131
155
  context "attributes" do
@@ -2,6 +2,6 @@ require "spec_helper"
2
2
 
3
3
  describe SimplePresenter do
4
4
  it "assigns SimplePresenter::Base" do
5
- ::Presenter.should be(SimplePresenter::Base)
5
+ expect(::Presenter).to be(SimplePresenter::Base)
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.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-01-20 00:00:00.000000000 Z
12
+ date: 2013-01-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70320251210820 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,31 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70320251210820
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rspec
27
- requirement: &70320251209440 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
- - - ~>
35
+ - - ! '>='
31
36
  - !ruby/object:Gem::Version
32
- version: '2.7'
37
+ version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70320251209440
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: pry
38
- requirement: &70320251208760 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,7 +53,12 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70320251208760
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  description: A simple presenter/facade/decorator/whatever implementation.
48
63
  email:
49
64
  - fnando.vieira@gmail.com
@@ -61,6 +76,7 @@ files:
61
76
  - lib/simple_presenter/base.rb
62
77
  - lib/simple_presenter/namespace.rb
63
78
  - lib/simple_presenter/rails.rb
79
+ - lib/simple_presenter/url_methods.rb
64
80
  - lib/simple_presenter/version.rb
65
81
  - simple_presenter.gemspec
66
82
  - spec/base_spec.rb
@@ -83,30 +99,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
99
  - - ! '>='
84
100
  - !ruby/object:Gem::Version
85
101
  version: '0'
86
- segments:
87
- - 0
88
- hash: 3392146763706068876
89
102
  required_rubygems_version: !ruby/object:Gem::Requirement
90
103
  none: false
91
104
  requirements:
92
105
  - - ! '>='
93
106
  - !ruby/object:Gem::Version
94
107
  version: '0'
95
- segments:
96
- - 0
97
- hash: 3392146763706068876
98
108
  requirements: []
99
109
  rubyforge_project:
100
- rubygems_version: 1.8.11
110
+ rubygems_version: 1.8.24
101
111
  signing_key:
102
112
  specification_version: 3
103
113
  summary: A simple presenter/facade/decorator/whatever implementation.
104
- test_files:
105
- - spec/base_spec.rb
106
- - spec/simple_presenter_spec.rb
107
- - spec/spec_helper.rb
108
- - spec/support/comment.rb
109
- - spec/support/comment_presenter.rb
110
- - spec/support/iterator_presenter.rb
111
- - spec/support/user.rb
112
- - spec/support/user_presenter.rb
114
+ test_files: []