meta_presenter 0.1.2 → 0.1.3
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/.gitignore +5 -1
- data/.travis.yml +9 -0
- data/Appraisals +12 -0
- data/Gemfile +11 -1
- data/Gemfile.lock +7 -1
- data/README.md +7 -3
- data/Rakefile +5 -0
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/actionpack4.gemfile +15 -0
- data/gemfiles/actionpack5.gemfile +15 -0
- data/lib/meta_presenter/builder.rb +11 -13
- data/lib/meta_presenter/helpers.rb +3 -4
- data/meta_presenter.gemspec +24 -21
- data/spec/meta_presenter/builder_spec.rb +7 -3
- data/spec/meta_presenter/helpers_spec.rb +1 -1
- data/spec/support/app/controllers/pages_controller.rb +0 -2
- metadata +22 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6f42b2b3dce01fdf2f0acb8588fe6377af542ac0b28ecf2a40d76b951a4f8cf
|
4
|
+
data.tar.gz: 9dc1717fe89a41bf9d99c1095d88117255dffa34a9485ed0ebd4742466005361
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 789b9c804d600a9a715851e9fd77345acb7f11ba930c6e09c05d729b743792b6ceabba74b6dd28e6756eda7ef39dfa089f4b9d1ae261ac32398fde54da967b99
|
7
|
+
data.tar.gz: 45401a3342a6e079605a863c9ce0f505182834263fbee7233cf94c72055774b619b78e4e14b91383406a3d5c324ec082c14e7c3b5566bc5a6ce183c253837316
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -10,4 +10,13 @@ rvm:
|
|
10
10
|
- 2.3.0
|
11
11
|
- 2.4.0
|
12
12
|
- 2.5.0
|
13
|
+
gemfile:
|
14
|
+
- gemfiles/actionpack4.gemfile
|
15
|
+
- gemfiles/actionpack5.gemfile
|
16
|
+
matrix:
|
17
|
+
exclude:
|
18
|
+
- rvm: 2.1.0
|
19
|
+
gemfile: gemfiles/actionpack5.gemfile
|
20
|
+
- rvm: 2.2.0
|
21
|
+
gemfile: gemfiles/actionpack5.gemfile
|
13
22
|
script: bundle exec rspec
|
data/Appraisals
ADDED
data/Gemfile
CHANGED
@@ -1,4 +1,14 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
# Specify your gem's dependencies in meta_presenter.gemspec
|
4
3
|
gemspec
|
4
|
+
|
5
|
+
gem 'pry'
|
6
|
+
|
7
|
+
# Hinting at development dependencies
|
8
|
+
# Prevents bundler from taking a long-time to resolve
|
9
|
+
group :development, :test do
|
10
|
+
gem 'rspec'
|
11
|
+
gem 'builder'
|
12
|
+
gem 'rb-readline'
|
13
|
+
gem 'coveralls'
|
14
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
meta_presenter (0.1.
|
4
|
+
meta_presenter (0.1.3)
|
5
5
|
actionpack (>= 3.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -25,6 +25,10 @@ GEM
|
|
25
25
|
i18n (>= 0.7, < 2)
|
26
26
|
minitest (~> 5.1)
|
27
27
|
tzinfo (~> 1.1)
|
28
|
+
appraisal (2.2.0)
|
29
|
+
bundler
|
30
|
+
rake
|
31
|
+
thor (>= 0.14.0)
|
28
32
|
builder (3.2.3)
|
29
33
|
coderay (1.1.2)
|
30
34
|
concurrent-ruby (1.1.3)
|
@@ -92,6 +96,8 @@ PLATFORMS
|
|
92
96
|
ruby
|
93
97
|
|
94
98
|
DEPENDENCIES
|
99
|
+
appraisal
|
100
|
+
builder
|
95
101
|
bundler
|
96
102
|
coveralls
|
97
103
|
meta_presenter!
|
data/README.md
CHANGED
@@ -20,8 +20,6 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
$ gem install meta_presenter
|
22
22
|
|
23
|
-
TODO: add an optional task that generates the scaffolding for you. Or, you can manually create the files you want.
|
24
|
-
|
25
23
|
Include MetaPresenter::Helpers in your controller or mailer:
|
26
24
|
|
27
25
|
class ApplicationController < ActionController::Base
|
@@ -32,6 +30,10 @@ Include MetaPresenter::Helpers in your controller or mailer:
|
|
32
30
|
include MetaPresenter::Base
|
33
31
|
end
|
34
32
|
|
33
|
+
## Requirements
|
34
|
+
|
35
|
+
MetaPresenter supports Ruby >= 2.1 and ActionPack >= 4.0. If you'd like to help adding support for older versions please submit a pull request with passing specs.
|
36
|
+
|
35
37
|
## Example
|
36
38
|
|
37
39
|
Say you have a PagesController with an action for home and logs. Underneath `app/presenters` you can add a class for each action. In this example we'll also create an application and base presenter we'll inherit from to re-use code in the per-action presenters.
|
@@ -148,8 +150,10 @@ If you want to customize the `presenter` method you can specify a shorthand by a
|
|
148
150
|
|
149
151
|
## TODO
|
150
152
|
|
151
|
-
* add support
|
153
|
+
* add support for actionsupport3, will require enabling it in the Appraisal file and then fixing any bugs in the build
|
152
154
|
* tests for ActionMailer support
|
155
|
+
* add an optional task that generates the scaffolding for you. Or, you can manually create the files you want
|
156
|
+
* add support for layouts
|
153
157
|
|
154
158
|
## Contributing
|
155
159
|
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "pry"
|
6
|
+
gem "actionpack", "4.0.0"
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem "rspec"
|
10
|
+
gem "builder"
|
11
|
+
gem "rb-readline"
|
12
|
+
gem "coveralls"
|
13
|
+
end
|
14
|
+
|
15
|
+
gemspec path: "../"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "pry"
|
6
|
+
gem "actionpack", "5.0.0"
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem "rspec"
|
10
|
+
gem "builder"
|
11
|
+
gem "rb-readline"
|
12
|
+
gem "coveralls"
|
13
|
+
end
|
14
|
+
|
15
|
+
gemspec path: "../"
|
@@ -61,20 +61,18 @@ module MetaPresenter
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def ancestors
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
controller_ancestors
|
71
|
-
end
|
72
|
-
end.yield_self do |list|
|
73
|
-
# add a presenter class for our current action
|
74
|
-
# to the front of the list
|
75
|
-
presenter_class_name_for_current_action = "#{list.first}::#{action_name.camelcase}"
|
76
|
-
list.unshift(presenter_class_name_for_current_action)
|
64
|
+
# Different ancestors depending on whether
|
65
|
+
# we're dealing with a mailer or a controller
|
66
|
+
list = if all_ancestors.map(&:to_s).include?("ActionMailer::Base")
|
67
|
+
mailer_ancestors
|
68
|
+
else
|
69
|
+
controller_ancestors
|
77
70
|
end
|
71
|
+
|
72
|
+
# add a presenter class for our current action
|
73
|
+
# to the front of the list
|
74
|
+
presenter_class_name_for_current_action = "#{list.first}::#{action_name.camelcase}"
|
75
|
+
list.unshift(presenter_class_name_for_current_action)
|
78
76
|
end
|
79
77
|
|
80
78
|
# The list of ancestors is very long.
|
@@ -14,10 +14,9 @@ module MetaPresenter
|
|
14
14
|
# Initialize presenter with the current controller
|
15
15
|
def presenter
|
16
16
|
@presenter ||= begin
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
17
|
+
controller = self
|
18
|
+
klass = MetaPresenter::Builder.new(controller, action_name).presenter_class
|
19
|
+
klass.new(controller)
|
21
20
|
end
|
22
21
|
end
|
23
22
|
end
|
data/meta_presenter.gemspec
CHANGED
@@ -1,28 +1,31 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'meta_presenter'
|
5
|
+
s.version = '0.1.3'
|
6
|
+
s.platform = Gem::Platform::RUBY
|
7
|
+
s.authors = ['szTheory']
|
8
|
+
s.description = %q{Presenter pattern in your Rails controllers and actions}
|
9
|
+
s.summary = %q{MetaPresenter is a Ruby gem that gives you access to the powerful presenter pattern in your Rails controllers. For each controller/action pair you get a presenter class in `app/presenters` that you can use in your views with with `presenter.method_name`. This helps you decompose your helper logic into small, tight, classes that are easily testable. There's even a DSL for method delegation on objects to reduce boilerplate.}
|
10
|
+
s.homepage = 'https://github.com/szTheory/meta_presenter'
|
11
|
+
s.license = 'MIT'
|
12
|
+
s.metadata = {
|
12
13
|
"source_code_uri" => "https://github.com/szTheory/meta_presenter",
|
13
14
|
}
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
s.files = `git ls-files`.split($/)
|
17
|
+
s.test_files = s.files.grep(%r{^(test|spec)/})
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
|
20
|
+
s.required_ruby_version = '>= 2.1.0'
|
19
21
|
|
20
|
-
|
22
|
+
s.add_dependency 'actionpack', '>= 3.0'
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
s.add_development_dependency 'rspec'
|
25
|
+
s.add_development_dependency 'bundler'
|
26
|
+
s.add_development_dependency 'rake'
|
27
|
+
s.add_development_dependency 'rb-readline'
|
28
|
+
s.add_development_dependency 'pry'
|
29
|
+
s.add_development_dependency 'coveralls'
|
30
|
+
s.add_development_dependency 'appraisal'
|
28
31
|
end
|
@@ -32,13 +32,17 @@ describe MetaPresenter::Builder do
|
|
32
32
|
|
33
33
|
context "subclass of ApplicationController" do
|
34
34
|
let(:controller_class) { PagesController }
|
35
|
-
let(:action_name) { "logs" }
|
36
35
|
|
37
|
-
|
36
|
+
context "action with a presenter class defined" do
|
37
|
+
let(:action_name) { "logs" }
|
38
|
+
before { expect(Object).to_not be_const_defined('LogsPresenter') }
|
39
|
+
|
40
|
+
it { is_expected.to be Pages::LogsPresenter }
|
41
|
+
end
|
38
42
|
|
39
43
|
context "action without a presenter class defined" do
|
40
|
-
# Good luck finding that FairyPresenter, doesn't exist!
|
41
44
|
let(:action_name) { "fairy" }
|
45
|
+
before { expect(Object).to_not be_const_defined('FairyPresenter') }
|
42
46
|
|
43
47
|
it "defers to the parent presenter" do
|
44
48
|
expect(subject).to be PagesPresenter
|
@@ -6,7 +6,7 @@ describe MetaPresenter::Helpers do
|
|
6
6
|
let(:action_name) { 'logs' }
|
7
7
|
|
8
8
|
describe '#presenter' do
|
9
|
-
subject { controller.
|
9
|
+
subject { controller.view_context.presenter }
|
10
10
|
|
11
11
|
before do
|
12
12
|
allow(controller).to receive(:action_name).and_return(action_name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meta_presenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- szTheory
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: appraisal
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
description: Presenter pattern in your Rails controllers and actions
|
112
126
|
email:
|
113
127
|
executables: []
|
@@ -116,10 +130,15 @@ extra_rdoc_files: []
|
|
116
130
|
files:
|
117
131
|
- ".gitignore"
|
118
132
|
- ".travis.yml"
|
133
|
+
- Appraisals
|
119
134
|
- Gemfile
|
120
135
|
- Gemfile.lock
|
121
136
|
- LICENSE.txt
|
122
137
|
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- gemfiles/.bundle/config
|
140
|
+
- gemfiles/actionpack4.gemfile
|
141
|
+
- gemfiles/actionpack5.gemfile
|
123
142
|
- lib/meta_presenter.rb
|
124
143
|
- lib/meta_presenter/base.rb
|
125
144
|
- lib/meta_presenter/base/delegate_all_to.rb
|
@@ -152,7 +171,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
171
|
requirements:
|
153
172
|
- - ">="
|
154
173
|
- !ruby/object:Gem::Version
|
155
|
-
version:
|
174
|
+
version: 2.1.0
|
156
175
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
176
|
requirements:
|
158
177
|
- - ">="
|