meta_presenter 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +48 -15
- data/.travis.yml +1 -0
- data/Gemfile.lock +104 -0
- data/README.md +16 -14
- data/lib/meta_presenter/base/delegate_all_to.rb +1 -0
- data/lib/meta_presenter/builder.rb +12 -4
- data/lib/meta_presenter/helpers.rb +1 -17
- data/meta_presenter.gemspec +2 -3
- data/spec/meta_presenter/builder_spec.rb +64 -0
- data/spec/meta_presenter/helpers_spec.rb +23 -0
- data/spec/spec_helper.rb +27 -2
- data/spec/support/app/controllers/admin/dashboard_controller.rb +2 -0
- data/spec/support/app/controllers/application_controller.rb +5 -0
- data/spec/support/app/controllers/pages_controller.rb +4 -0
- data/spec/support/app/presenters/admin/dashboard/inbox_presenter.rb +8 -0
- data/spec/support/app/presenters/admin/dashboard_presenter.rb +4 -0
- data/spec/support/app/presenters/application_presenter.rb +2 -0
- data/spec/support/app/presenters/pages/logs_presenter.rb +4 -0
- data/spec/support/app/presenters/pages/only_file_exists_presenter.rb +0 -0
- data/spec/support/app/presenters/pages_presenter.rb +4 -0
- metadata +28 -24
- data/lib/meta_presenter/layout_builder.rb +0 -54
- data/spec/meta_presenter_spec.rb +0 -5
- data/spec/support/database_cleaner.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b388fb84386a27e07ce765d5c94ddcd0dae5b1389ec071aad36a56854bff665f
|
4
|
+
data.tar.gz: 72ebfb24a3ce5f482b2ff14c85054861f3a5b487d0ab9ef7ffe1d8bec21fbe28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 264c678f7929175821ed1d234c78f0c67dff822611b850c24614b1acc87577369135145f61bf763b4d56c8ac30e2e23fa3b02343aa84110f0b022dd0218647b0
|
7
|
+
data.tar.gz: f30a07ba72292401626101610830b40efc7d7a0f986121c746cf31c5ccd93bb6bfeb2c39b71190aecfbdcc8774963a971cf154d634047d14dabf800453c1b083
|
data/.gitignore
CHANGED
@@ -1,17 +1,50 @@
|
|
1
1
|
*.gem
|
2
2
|
*.rbc
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
.ruby-version
|
47
|
+
.ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
data/.travis.yml
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
meta_presenter (0.1.0)
|
5
|
+
actionpack (>= 3.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionpack (5.2.1)
|
11
|
+
actionview (= 5.2.1)
|
12
|
+
activesupport (= 5.2.1)
|
13
|
+
rack (~> 2.0)
|
14
|
+
rack-test (>= 0.6.3)
|
15
|
+
rails-dom-testing (~> 2.0)
|
16
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
17
|
+
actionview (5.2.1)
|
18
|
+
activesupport (= 5.2.1)
|
19
|
+
builder (~> 3.1)
|
20
|
+
erubi (~> 1.4)
|
21
|
+
rails-dom-testing (~> 2.0)
|
22
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
23
|
+
activesupport (5.2.1)
|
24
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
25
|
+
i18n (>= 0.7, < 2)
|
26
|
+
minitest (~> 5.1)
|
27
|
+
tzinfo (~> 1.1)
|
28
|
+
builder (3.2.3)
|
29
|
+
coderay (1.1.2)
|
30
|
+
concurrent-ruby (1.1.3)
|
31
|
+
coveralls (0.8.22)
|
32
|
+
json (>= 1.8, < 3)
|
33
|
+
simplecov (~> 0.16.1)
|
34
|
+
term-ansicolor (~> 1.3)
|
35
|
+
thor (~> 0.19.4)
|
36
|
+
tins (~> 1.6)
|
37
|
+
crass (1.0.4)
|
38
|
+
diff-lcs (1.3)
|
39
|
+
docile (1.3.1)
|
40
|
+
erubi (1.7.1)
|
41
|
+
i18n (1.1.1)
|
42
|
+
concurrent-ruby (~> 1.0)
|
43
|
+
json (2.1.0)
|
44
|
+
loofah (2.2.3)
|
45
|
+
crass (~> 1.0.2)
|
46
|
+
nokogiri (>= 1.5.9)
|
47
|
+
method_source (0.9.2)
|
48
|
+
mini_portile2 (2.3.0)
|
49
|
+
minitest (5.11.3)
|
50
|
+
nokogiri (1.8.5)
|
51
|
+
mini_portile2 (~> 2.3.0)
|
52
|
+
pry (0.12.2)
|
53
|
+
coderay (~> 1.1.0)
|
54
|
+
method_source (~> 0.9.0)
|
55
|
+
rack (2.0.6)
|
56
|
+
rack-test (1.1.0)
|
57
|
+
rack (>= 1.0, < 3)
|
58
|
+
rails-dom-testing (2.0.3)
|
59
|
+
activesupport (>= 4.2.0)
|
60
|
+
nokogiri (>= 1.6)
|
61
|
+
rails-html-sanitizer (1.0.4)
|
62
|
+
loofah (~> 2.2, >= 2.2.2)
|
63
|
+
rake (12.3.1)
|
64
|
+
rb-readline (0.5.5)
|
65
|
+
rspec (3.8.0)
|
66
|
+
rspec-core (~> 3.8.0)
|
67
|
+
rspec-expectations (~> 3.8.0)
|
68
|
+
rspec-mocks (~> 3.8.0)
|
69
|
+
rspec-core (3.8.0)
|
70
|
+
rspec-support (~> 3.8.0)
|
71
|
+
rspec-expectations (3.8.2)
|
72
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
73
|
+
rspec-support (~> 3.8.0)
|
74
|
+
rspec-mocks (3.8.0)
|
75
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
76
|
+
rspec-support (~> 3.8.0)
|
77
|
+
rspec-support (3.8.0)
|
78
|
+
simplecov (0.16.1)
|
79
|
+
docile (~> 1.1)
|
80
|
+
json (>= 1.8, < 3)
|
81
|
+
simplecov-html (~> 0.10.0)
|
82
|
+
simplecov-html (0.10.2)
|
83
|
+
term-ansicolor (1.7.0)
|
84
|
+
tins (~> 1.0)
|
85
|
+
thor (0.19.4)
|
86
|
+
thread_safe (0.3.6)
|
87
|
+
tins (1.20.2)
|
88
|
+
tzinfo (1.2.5)
|
89
|
+
thread_safe (~> 0.1)
|
90
|
+
|
91
|
+
PLATFORMS
|
92
|
+
ruby
|
93
|
+
|
94
|
+
DEPENDENCIES
|
95
|
+
bundler
|
96
|
+
coveralls
|
97
|
+
meta_presenter!
|
98
|
+
pry
|
99
|
+
rake
|
100
|
+
rb-readline
|
101
|
+
rspec
|
102
|
+
|
103
|
+
BUNDLED WITH
|
104
|
+
1.17.1
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
[![Gem Version](https://badge.fury.io/rb/meta_presenter.svg)](https://badge.fury.io/rb/meta_presenter) [![Build Status](https://travis-ci.org/
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/meta_presenter.svg)](https://badge.fury.io/rb/meta_presenter) [![Build Status](https://travis-ci.org/szTheory/meta_presenter.svg?branch=master)](https://travis-ci.org/szTheory/meta_presenter) [![Coverage Status](https://coveralls.io/repos/github/szTheory/meta_presenter/badge.svg?branch=master)](https://coveralls.io/github/szTheory/meta_presenter?branch=master) [![Inline docs](http://inch-ci.org/github/szTheory/meta_presenter.svg?branch=master)](http://inch-ci.org/github/szTheory/meta_presenter) [![MIT License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/szTheory/meta_presenter/blob/master/LICENSE.txt) [![Gem](https://img.shields.io/gem/dt/meta_presenter.svg)](https://rubygems.org/gems/meta_presenter) [![GitHub stars](https://img.shields.io/github/stars/szTheory/meta_presenter.svg?label=Stars&style=social)](https://github.com/szTheory/meta_presenter)
|
2
2
|
|
3
3
|
# MetaPresenter
|
4
4
|
|
5
|
-
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
|
5
|
+
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 tight, easily testable classes. There's even a DSL for method delegation on objects to reduce boilerplate.
|
6
6
|
|
7
7
|
[Github Project Page](https://github.com/szTheory/meta_presenter)
|
8
8
|
|
@@ -25,14 +25,14 @@ TODO: add an optional task that generates the scaffolding for you. Or, you can m
|
|
25
25
|
Include MetaPresenter::Helpers in your controller or mailer:
|
26
26
|
|
27
27
|
class ApplicationController < ActionController::Base
|
28
|
-
include MetaPresenter::
|
28
|
+
include MetaPresenter::Base
|
29
29
|
end
|
30
30
|
|
31
31
|
class ApplicationMailer < ActionMailer::Base
|
32
|
-
include MetaPresenter::
|
32
|
+
include MetaPresenter::Base
|
33
33
|
end
|
34
34
|
|
35
|
-
##
|
35
|
+
## Example
|
36
36
|
|
37
37
|
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.
|
38
38
|
|
@@ -106,9 +106,9 @@ app/presenters/pages/base_presenter.rb:
|
|
106
106
|
app/presenters/pages/home_presenter.rb
|
107
107
|
|
108
108
|
class Pages::HomePresenter << Pages::BasePresenter
|
109
|
-
# presenter.email, presenter.id
|
110
|
-
#
|
111
|
-
#
|
109
|
+
# presenter.email, presenter.id or any other
|
110
|
+
# method not already defined will delegate to
|
111
|
+
# the current_user
|
112
112
|
delegate_all_to :current_user
|
113
113
|
|
114
114
|
# presenter.greeting in views
|
@@ -121,7 +121,7 @@ app/presenters/pages/logs_presenter.rb
|
|
121
121
|
|
122
122
|
class Pages::LogsPresenter << Pages::BasePresenter
|
123
123
|
# presenter.size and presenter.last will delegate to
|
124
|
-
# the controller's private
|
124
|
+
# the controller's private `#logs`
|
125
125
|
delegate :size, :last, to: :logs
|
126
126
|
|
127
127
|
# presenter.log_text(log) in view
|
@@ -135,20 +135,22 @@ app/presenters/pages/logs_presenter.rb
|
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
138
|
-
TODO: add more documentation around layout presenters
|
139
|
-
|
140
138
|
## Aliasing the presenter methods
|
141
139
|
|
142
|
-
If you want to customize the `presenter`
|
140
|
+
If you want to customize the `presenter` method you can specify a shorthand by adding an alias_method to your controller or mailer:
|
143
141
|
|
144
142
|
class ApplicationController < ActionController::Base
|
145
143
|
including MetaPresenter
|
146
144
|
|
147
145
|
# So convenient!
|
148
|
-
alias_method :presenter, :
|
149
|
-
alias_method :presenter, :lp
|
146
|
+
alias_method :presenter, :pr
|
150
147
|
end
|
151
148
|
|
149
|
+
## TODO
|
150
|
+
|
151
|
+
* add support by lower Ruby versions by replacing yield_self with equivalent compatible code
|
152
|
+
* tests for ActionMailer support
|
153
|
+
|
152
154
|
## Contributing
|
153
155
|
|
154
156
|
1. Fork it
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support/core_ext/object/try'
|
2
|
+
|
1
3
|
module MetaPresenter
|
2
4
|
class Builder
|
3
5
|
attr_reader :controller, :action_name
|
@@ -6,6 +8,14 @@ module MetaPresenter
|
|
6
8
|
@action_name = action_name
|
7
9
|
end
|
8
10
|
|
11
|
+
# If the file exists, but the class isn't defined then something
|
12
|
+
# has gone wrong that the dev really should know about!
|
13
|
+
class FileExistsButPresenterNotDefinedError < NameError
|
14
|
+
def initialize(presenter_class_name, presenter_file_path)
|
15
|
+
super("Presenter class #{presenter_class_name} is not defined but file exists at #{presenter_file_path}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
9
19
|
def presenter_class
|
10
20
|
# Try to find the class (it's not guaranteed)
|
11
21
|
klass_name = ancestors.find do |klass_name|
|
@@ -43,9 +53,7 @@ module MetaPresenter
|
|
43
53
|
filename = "#{presenter_class_name.underscore}.rb"
|
44
54
|
presenter_file_path = File.join(Rails.root, "app", "presenters", filename)
|
45
55
|
if File.exists?(presenter_file_path)
|
46
|
-
|
47
|
-
# has gone wrong that the dev really should know about!
|
48
|
-
raise e
|
56
|
+
raise FileExistsButPresenterNotDefinedError.new(presenter_class_name, presenter_file_path)
|
49
57
|
else
|
50
58
|
false
|
51
59
|
end
|
@@ -56,7 +64,7 @@ module MetaPresenter
|
|
56
64
|
all_ancestors.yield_self do |list|
|
57
65
|
# Different ancestors depending on whether
|
58
66
|
# we're dealing with a mailer or a controller
|
59
|
-
if list.include?(ActionMailer::Base)
|
67
|
+
if list.map(&:to_s).include?("ActionMailer::Base")
|
60
68
|
mailer_ancestors
|
61
69
|
else
|
62
70
|
controller_ancestors
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'meta_presenter/builder'
|
2
|
-
require 'meta_presenter/layout_builder'
|
3
2
|
require 'active_support/concern'
|
4
3
|
|
5
4
|
module MetaPresenter
|
@@ -7,12 +6,8 @@ module MetaPresenter
|
|
7
6
|
extend ActiveSupport::Concern
|
8
7
|
included do
|
9
8
|
# Sets up the `presenter.` method as helper within your views
|
10
|
-
# If you want to customize this for
|
9
|
+
# If you want to customize this for yourself just alias_method it
|
11
10
|
helper_method :presenter
|
12
|
-
|
13
|
-
# Sets up the `layout_presenter.` method as helper within your views
|
14
|
-
# If you want to customize this for yourslef just alias_method it
|
15
|
-
helper_method :layout_presenter
|
16
11
|
end
|
17
12
|
|
18
13
|
private
|
@@ -25,16 +20,5 @@ module MetaPresenter
|
|
25
20
|
end
|
26
21
|
end
|
27
22
|
end
|
28
|
-
|
29
|
-
# Initialize presenter with the current controller
|
30
|
-
def layout_presenter
|
31
|
-
@layout_presenters ||= {}
|
32
|
-
@layout_presenters[current_layout] ||= begin
|
33
|
-
yield_self do |controller|
|
34
|
-
klass = MetaPresenter::LayoutBuilder.new(current_layout, layouts).layout_presenter_class
|
35
|
-
klass.new(controller)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
23
|
end
|
40
24
|
end
|
data/meta_presenter.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'meta_presenter'
|
5
|
-
spec.version = '0.1.
|
5
|
+
spec.version = '0.1.1'
|
6
6
|
spec.authors = ['szTheory']
|
7
7
|
spec.description = %q{Presenter pattern in your Rails controllers and actions}
|
8
8
|
spec.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.}
|
@@ -18,12 +18,11 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
|
20
20
|
spec.add_runtime_dependency 'actionpack', '>= 3.0'
|
21
|
-
spec.add_runtime_dependency 'actionmailer', '>= 3.0'
|
22
21
|
|
23
22
|
spec.add_development_dependency 'rspec'
|
24
|
-
spec.add_development_dependency 'database_cleaner'
|
25
23
|
spec.add_development_dependency 'bundler'
|
26
24
|
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency 'rb-readline'
|
27
26
|
spec.add_development_dependency 'pry'
|
28
27
|
spec.add_development_dependency 'coveralls'
|
29
28
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetaPresenter::Builder do
|
4
|
+
let(:controller_class) { ApplicationController }
|
5
|
+
let(:controller) { controller_class.new }
|
6
|
+
let(:action_name) { 'logs' }
|
7
|
+
let(:object) { described_class.new(controller, action_name) }
|
8
|
+
|
9
|
+
def controller_ancestors
|
10
|
+
controller.class.ancestors
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#new' do
|
14
|
+
subject { object }
|
15
|
+
|
16
|
+
it { expect(subject.controller).to eql(controller) }
|
17
|
+
it { expect(subject.action_name).to eql(action_name) }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#presenter_class' do
|
21
|
+
subject { object.presenter_class }
|
22
|
+
|
23
|
+
before do
|
24
|
+
expect(controller_ancestors.first).to eql(controller_class)
|
25
|
+
end
|
26
|
+
|
27
|
+
context "application controller" do
|
28
|
+
let(:controller_class) { ApplicationController }
|
29
|
+
|
30
|
+
it { is_expected.to be ApplicationPresenter }
|
31
|
+
end
|
32
|
+
|
33
|
+
context "subclass of ApplicationController" do
|
34
|
+
let(:controller_class) { PagesController }
|
35
|
+
let(:action_name) { "logs" }
|
36
|
+
|
37
|
+
it { is_expected.to be Pages::LogsPresenter }
|
38
|
+
|
39
|
+
context "action without a presenter class defined" do
|
40
|
+
# Good luck finding that FairyPresenter, doesn't exist!
|
41
|
+
let(:action_name) { "fairy" }
|
42
|
+
|
43
|
+
it "defers to the parent presenter" do
|
44
|
+
expect(subject).to be PagesPresenter
|
45
|
+
end
|
46
|
+
|
47
|
+
context "but the file exists" do
|
48
|
+
let(:action_name) { "only_file_exists" }
|
49
|
+
|
50
|
+
it do
|
51
|
+
expect { subject }.to raise_error(MetaPresenter::Builder::FileExistsButPresenterNotDefinedError)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "namespaced" do
|
58
|
+
let(:controller_class) { Admin::DashboardController }
|
59
|
+
let(:action_name) { "inbox" }
|
60
|
+
|
61
|
+
it { is_expected.to be Admin::Dashboard::InboxPresenter }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetaPresenter::Helpers do
|
4
|
+
let(:controller_class) { ApplicationController }
|
5
|
+
let(:controller) { controller_class.new }
|
6
|
+
let(:action_name) { 'logs' }
|
7
|
+
|
8
|
+
describe '#presenter' do
|
9
|
+
subject { controller.helpers.presenter }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(controller).to receive(:action_name).and_return(action_name)
|
13
|
+
end
|
14
|
+
|
15
|
+
context "controller with this module included" do
|
16
|
+
before do
|
17
|
+
expect(controller_class.included_modules).to include(described_class)
|
18
|
+
end
|
19
|
+
|
20
|
+
it { is_expected.to be_a(ApplicationPresenter) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,31 @@
|
|
1
|
+
# spec coverage
|
1
2
|
require 'coveralls'
|
2
3
|
Coveralls.wear!
|
3
4
|
|
5
|
+
# debug tool
|
6
|
+
require "pry"
|
7
|
+
|
8
|
+
# main lib module
|
4
9
|
require "meta_presenter"
|
5
|
-
|
6
|
-
|
10
|
+
|
11
|
+
# support files
|
12
|
+
Dir["#{__dir__}/support/*.rb"].each {|file| require file }
|
13
|
+
|
14
|
+
# Simulate the Rails env.
|
15
|
+
# Instead of loading the Rails environment, we stub the bare amount
|
16
|
+
# and load from spec/support/app as if it were a Rails app
|
17
|
+
begin
|
18
|
+
# mount app dir tree
|
19
|
+
Dir["#{__dir__}/support/app/**/*.rb"].each {|file| require file }
|
20
|
+
|
21
|
+
# mock Rails
|
22
|
+
module Rails
|
23
|
+
end
|
24
|
+
|
25
|
+
# stub Rails.root
|
26
|
+
RSpec.configure do |config|
|
27
|
+
config.before do
|
28
|
+
allow(Rails).to receive(:root).and_return(File.join(__dir__, 'support'))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- szTheory
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: actionmailer
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '3.0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '3.0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rspec
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,7 +39,7 @@ dependencies:
|
|
53
39
|
- !ruby/object:Gem::Version
|
54
40
|
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
42
|
+
name: bundler
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
45
|
- - ">="
|
@@ -67,7 +53,7 @@ dependencies:
|
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
56
|
+
name: rake
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
59
|
- - ">="
|
@@ -81,7 +67,7 @@ dependencies:
|
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
70
|
+
name: rb-readline
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - ">="
|
@@ -131,6 +117,7 @@ files:
|
|
131
117
|
- ".gitignore"
|
132
118
|
- ".travis.yml"
|
133
119
|
- Gemfile
|
120
|
+
- Gemfile.lock
|
134
121
|
- LICENSE.txt
|
135
122
|
- README.md
|
136
123
|
- lib/meta_presenter.rb
|
@@ -139,11 +126,19 @@ files:
|
|
139
126
|
- lib/meta_presenter/base/delegate_to_controller.rb
|
140
127
|
- lib/meta_presenter/builder.rb
|
141
128
|
- lib/meta_presenter/helpers.rb
|
142
|
-
- lib/meta_presenter/layout_builder.rb
|
143
129
|
- meta_presenter.gemspec
|
144
|
-
- spec/
|
130
|
+
- spec/meta_presenter/builder_spec.rb
|
131
|
+
- spec/meta_presenter/helpers_spec.rb
|
145
132
|
- spec/spec_helper.rb
|
146
|
-
- spec/support/
|
133
|
+
- spec/support/app/controllers/admin/dashboard_controller.rb
|
134
|
+
- spec/support/app/controllers/application_controller.rb
|
135
|
+
- spec/support/app/controllers/pages_controller.rb
|
136
|
+
- spec/support/app/presenters/admin/dashboard/inbox_presenter.rb
|
137
|
+
- spec/support/app/presenters/admin/dashboard_presenter.rb
|
138
|
+
- spec/support/app/presenters/application_presenter.rb
|
139
|
+
- spec/support/app/presenters/pages/logs_presenter.rb
|
140
|
+
- spec/support/app/presenters/pages/only_file_exists_presenter.rb
|
141
|
+
- spec/support/app/presenters/pages_presenter.rb
|
147
142
|
homepage: https://github.com/szTheory/meta_presenter
|
148
143
|
licenses:
|
149
144
|
- MIT
|
@@ -165,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
160
|
version: '0'
|
166
161
|
requirements: []
|
167
162
|
rubyforge_project:
|
168
|
-
rubygems_version: 2.6
|
163
|
+
rubygems_version: 2.7.6
|
169
164
|
signing_key:
|
170
165
|
specification_version: 4
|
171
166
|
summary: MetaPresenter is a Ruby gem that gives you access to the powerful presenter
|
@@ -174,6 +169,15 @@ summary: MetaPresenter is a Ruby gem that gives you access to the powerful prese
|
|
174
169
|
This helps you decompose your helper logic into small, tight, classes that are easily
|
175
170
|
testable. There's even a DSL for method delegation on objects to reduce boilerplate.
|
176
171
|
test_files:
|
177
|
-
- spec/
|
172
|
+
- spec/meta_presenter/builder_spec.rb
|
173
|
+
- spec/meta_presenter/helpers_spec.rb
|
178
174
|
- spec/spec_helper.rb
|
179
|
-
- spec/support/
|
175
|
+
- spec/support/app/controllers/admin/dashboard_controller.rb
|
176
|
+
- spec/support/app/controllers/application_controller.rb
|
177
|
+
- spec/support/app/controllers/pages_controller.rb
|
178
|
+
- spec/support/app/presenters/admin/dashboard/inbox_presenter.rb
|
179
|
+
- spec/support/app/presenters/admin/dashboard_presenter.rb
|
180
|
+
- spec/support/app/presenters/application_presenter.rb
|
181
|
+
- spec/support/app/presenters/pages/logs_presenter.rb
|
182
|
+
- spec/support/app/presenters/pages/only_file_exists_presenter.rb
|
183
|
+
- spec/support/app/presenters/pages_presenter.rb
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module MetaPresenter
|
2
|
-
class LayoutBuilder
|
3
|
-
class NoLayoutImplemented < NotImplementedError
|
4
|
-
def initialize(current_layout, layouts)
|
5
|
-
super("No layout presenter definition found for #{current_layout} among #{layouts}")
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
attr_reader :layouts, :current_layout
|
10
|
-
def initialize(layouts, current_layout)
|
11
|
-
@layouts = layouts
|
12
|
-
@current_layout = current_layout
|
13
|
-
end
|
14
|
-
|
15
|
-
def layout_presenter_class
|
16
|
-
return nil if layout_index.nil?
|
17
|
-
|
18
|
-
layout_classes(layout_index).find do |klass_name|
|
19
|
-
layout_presenter_class_for(klass_name)
|
20
|
-
end.tap do |klass|
|
21
|
-
if klass.blank?
|
22
|
-
raise NoLayoutImplemented.new(current_layout, layouts)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
def layout_presenter_class_for(klass_name)
|
29
|
-
layout_presenter_class_name = "Layouts::#{klass_name.camelcase}Presenter"
|
30
|
-
begin
|
31
|
-
layout_presenter_class_name.constantize
|
32
|
-
|
33
|
-
# No corresponding presenter class was found
|
34
|
-
rescue NameError => e
|
35
|
-
layout_presenter_file_path = Rails.root.join("app", "presenters", "layouts", "#{layout_presenter_class_name.underscore}.rb")
|
36
|
-
if File.exists?(layout_presenter_file_path)
|
37
|
-
# If the file exists, but the class isn't defined then something
|
38
|
-
# has gone wrong that the dev really should know about!
|
39
|
-
raise e
|
40
|
-
else
|
41
|
-
false
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def layout_index
|
47
|
-
layouts.index(current_layout)
|
48
|
-
end
|
49
|
-
|
50
|
-
def layout_classes
|
51
|
-
layouts[0..layout_index].reverse
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
data/spec/meta_presenter_spec.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
RSpec.configure do |config|
|
2
|
-
config.before(:suite) do
|
3
|
-
DatabaseCleaner.clean_with(:truncation)
|
4
|
-
end
|
5
|
-
|
6
|
-
config.before(:each) do
|
7
|
-
DatabaseCleaner.strategy = :transaction
|
8
|
-
end
|
9
|
-
|
10
|
-
config.before(:each) do
|
11
|
-
DatabaseCleaner.start
|
12
|
-
end
|
13
|
-
|
14
|
-
config.after(:each) do
|
15
|
-
DatabaseCleaner.clean
|
16
|
-
end
|
17
|
-
end
|