meta_presenter 0.2.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/.tool-versions +1 -0
- data/.travis.yml +8 -14
- data/Appraisals +6 -17
- data/CHANGELOG.md +1 -0
- data/Gemfile +7 -4
- data/Gemfile.lock +142 -74
- data/README.md +83 -122
- data/gemfiles/rails6.gemfile +19 -0
- data/gemfiles/rails7.gemfile +19 -0
- data/lib/meta_presenter/builder.rb +63 -64
- data/lib/meta_presenter/helpers.rb +15 -14
- data/meta_presenter.gemspec +10 -12
- data/spec/meta_presenter/builder_spec.rb +20 -22
- data/spec/spec_helper.rb +5 -9
- data/spec/support/app/controllers/admin/dashboard_controller.rb +6 -2
- data/spec/support/app/presenters/admin/dashboard/inbox_presenter.rb +3 -3
- data/spec/support/app/presenters/admin/dashboard_presenter.rb +3 -2
- data/spec/support/app/presenters/pages/logs_presenter.rb +5 -3
- metadata +22 -38
- data/gemfiles/rails3.gemfile +0 -16
- data/gemfiles/rails4.gemfile +0 -16
- data/gemfiles/rails5.gemfile +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6472c3bd9362c0382d078e139be49b95313689722ef8ee59eb94dd44bf60964c
|
4
|
+
data.tar.gz: 37fa528ed35baa5910a5da3d2984c6be8cf4a301df3a3549d13254a6dd6411b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea6ba9139e5bc5286b9023cbfd59ffff1fcee9744fe7dc0e75e0a09c7540e678fbb15193299ab59f71a41bdc9a172f2ee41f71ca490d5c4978aa0a99ecb7fc90
|
7
|
+
data.tar.gz: 87a4ce8737f8d4a01e1d0b0288bd13c11607261c6fa9e106d0ef9f3b403317fb9e55b6d52923fe3e33a37bfe2fee9029e331432a686ade63616721c0f61fef47
|
data/.rubocop.yml
ADDED
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.2.2
|
data/.travis.yml
CHANGED
@@ -3,26 +3,20 @@ cache: bundler
|
|
3
3
|
matrix:
|
4
4
|
fast_finish: true
|
5
5
|
rvm:
|
6
|
-
- 2.
|
7
|
-
-
|
8
|
-
-
|
9
|
-
- 2.
|
10
|
-
- 2.5.0
|
11
|
-
- 2.6.0
|
6
|
+
- 2.7.5
|
7
|
+
- 3.0.0
|
8
|
+
- 3.1.0
|
9
|
+
- 3.2.0
|
12
10
|
gemfile:
|
13
11
|
- gemfiles/rails3.gemfile
|
14
12
|
- gemfiles/rails4.gemfile
|
15
13
|
- gemfiles/rails5.gemfile
|
14
|
+
- gemfiles/rails6.gemfile
|
15
|
+
- gemfiles/rails7.gemfile
|
16
16
|
matrix:
|
17
17
|
exclude:
|
18
|
-
- rvm: 2.
|
19
|
-
gemfile: gemfiles/rails5.gemfile
|
20
|
-
- rvm: 2.2.0
|
21
|
-
gemfile: gemfiles/rails5.gemfile
|
22
|
-
- rvm: 2.5.0
|
23
|
-
gemfile: gemfiles/rails3.gemfile
|
24
|
-
- rvm: 2.6.0
|
18
|
+
- rvm: 2.7.5
|
25
19
|
gemfile: gemfiles/rails3.gemfile
|
26
20
|
script: bundle exec rspec
|
27
21
|
before_install:
|
28
|
-
- gem install bundler
|
22
|
+
- gem install bundler
|
data/Appraisals
CHANGED
@@ -1,20 +1,9 @@
|
|
1
|
-
appraise
|
2
|
-
gem
|
3
|
-
gem
|
1
|
+
appraise 'rails6' do
|
2
|
+
gem 'actionpack', '6.0.0'
|
3
|
+
gem 'actionmailer', '6.0.0'
|
4
4
|
end
|
5
5
|
|
6
|
-
appraise
|
7
|
-
gem
|
8
|
-
gem
|
6
|
+
appraise 'rails7' do
|
7
|
+
gem 'actionpack', '7.0.1'
|
8
|
+
gem 'actionmailer', '7.0.1'
|
9
9
|
end
|
10
|
-
|
11
|
-
appraise "rails5" do
|
12
|
-
gem "actionpack", "5.0.0"
|
13
|
-
gem "actionmailer", "5.0.0"
|
14
|
-
end
|
15
|
-
|
16
|
-
# TODO: uncomment this once Rails 6 is released on April 30, 2019
|
17
|
-
# appraise "rails6" do
|
18
|
-
# gem "actionpack", "6.0.0"
|
19
|
-
# gem "actionmailer", "6.0.0"
|
20
|
-
# end
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* Add Rails 6 support.
|
data/Gemfile
CHANGED
@@ -5,9 +5,12 @@ gemspec
|
|
5
5
|
# Hinting at development dependencies
|
6
6
|
# Prevents bundler from taking a long-time to resolve
|
7
7
|
group :development, :test do
|
8
|
-
gem 'pry'
|
9
|
-
gem 'rspec'
|
10
8
|
gem 'builder'
|
9
|
+
gem 'byebug', platforms: %i[mri mingw x64_mingw]
|
11
10
|
gem 'rb-readline'
|
12
|
-
gem '
|
13
|
-
end
|
11
|
+
gem 'rspec'
|
12
|
+
end
|
13
|
+
|
14
|
+
group :development do
|
15
|
+
gem 'rubocop', '~> 1.57', require: false
|
16
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,127 +1,195 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
meta_presenter (0.
|
4
|
+
meta_presenter (1.0.0)
|
5
5
|
actionmailer (>= 3.0.12)
|
6
6
|
actionpack (>= 3.0.12)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actionmailer (
|
12
|
-
actionpack (=
|
13
|
-
actionview (=
|
14
|
-
activejob (=
|
11
|
+
actionmailer (7.1.1)
|
12
|
+
actionpack (= 7.1.1)
|
13
|
+
actionview (= 7.1.1)
|
14
|
+
activejob (= 7.1.1)
|
15
|
+
activesupport (= 7.1.1)
|
15
16
|
mail (~> 2.5, >= 2.5.4)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
net-imap
|
18
|
+
net-pop
|
19
|
+
net-smtp
|
20
|
+
rails-dom-testing (~> 2.2)
|
21
|
+
actionpack (7.1.1)
|
22
|
+
actionview (= 7.1.1)
|
23
|
+
activesupport (= 7.1.1)
|
24
|
+
nokogiri (>= 1.8.5)
|
25
|
+
rack (>= 2.2.4)
|
26
|
+
rack-session (>= 1.0.1)
|
21
27
|
rack-test (>= 0.6.3)
|
22
|
-
rails-dom-testing (~> 2.
|
23
|
-
rails-html-sanitizer (~> 1.
|
24
|
-
actionview (
|
25
|
-
activesupport (=
|
28
|
+
rails-dom-testing (~> 2.2)
|
29
|
+
rails-html-sanitizer (~> 1.6)
|
30
|
+
actionview (7.1.1)
|
31
|
+
activesupport (= 7.1.1)
|
26
32
|
builder (~> 3.1)
|
27
|
-
erubi (~> 1.
|
28
|
-
rails-dom-testing (~> 2.
|
29
|
-
rails-html-sanitizer (~> 1.
|
30
|
-
activejob (
|
31
|
-
activesupport (=
|
33
|
+
erubi (~> 1.11)
|
34
|
+
rails-dom-testing (~> 2.2)
|
35
|
+
rails-html-sanitizer (~> 1.6)
|
36
|
+
activejob (7.1.1)
|
37
|
+
activesupport (= 7.1.1)
|
32
38
|
globalid (>= 0.3.6)
|
33
|
-
activesupport (
|
39
|
+
activesupport (7.1.1)
|
40
|
+
base64
|
41
|
+
bigdecimal
|
34
42
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
43
|
+
connection_pool (>= 2.2.5)
|
44
|
+
drb
|
45
|
+
i18n (>= 1.6, < 2)
|
46
|
+
minitest (>= 5.1)
|
47
|
+
mutex_m
|
48
|
+
tzinfo (~> 2.0)
|
49
|
+
appraisal (2.5.0)
|
40
50
|
bundler
|
41
51
|
rake
|
42
52
|
thor (>= 0.14.0)
|
43
|
-
|
44
|
-
|
45
|
-
|
53
|
+
ast (2.4.2)
|
54
|
+
base64 (0.1.1)
|
55
|
+
bigdecimal (3.1.4)
|
56
|
+
builder (3.2.4)
|
57
|
+
byebug (11.1.3)
|
58
|
+
coderay (1.1.3)
|
59
|
+
concurrent-ruby (1.2.2)
|
60
|
+
connection_pool (2.4.1)
|
46
61
|
coveralls (0.8.23)
|
47
62
|
json (>= 1.8, < 3)
|
48
63
|
simplecov (~> 0.16.1)
|
49
64
|
term-ansicolor (~> 1.3)
|
50
65
|
thor (>= 0.19.4, < 2.0)
|
51
66
|
tins (~> 1.6)
|
52
|
-
crass (1.0.
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
67
|
+
crass (1.0.6)
|
68
|
+
date (3.3.3)
|
69
|
+
diff-lcs (1.5.0)
|
70
|
+
docile (1.4.0)
|
71
|
+
drb (2.1.1)
|
72
|
+
ruby2_keywords
|
73
|
+
erubi (1.12.0)
|
74
|
+
globalid (1.2.1)
|
75
|
+
activesupport (>= 6.1)
|
76
|
+
i18n (1.14.1)
|
59
77
|
concurrent-ruby (~> 1.0)
|
60
|
-
json (2.
|
61
|
-
|
78
|
+
json (2.6.3)
|
79
|
+
language_server-protocol (3.17.0.3)
|
80
|
+
loofah (2.21.4)
|
62
81
|
crass (~> 1.0.2)
|
63
|
-
nokogiri (>= 1.
|
64
|
-
mail (2.
|
82
|
+
nokogiri (>= 1.12.0)
|
83
|
+
mail (2.8.1)
|
65
84
|
mini_mime (>= 0.1.1)
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
85
|
+
net-imap
|
86
|
+
net-pop
|
87
|
+
net-smtp
|
88
|
+
method_source (1.0.0)
|
89
|
+
mini_mime (1.1.5)
|
90
|
+
mini_portile2 (2.8.4)
|
91
|
+
minitest (5.20.0)
|
92
|
+
mutex_m (0.1.2)
|
93
|
+
net-imap (0.4.1)
|
94
|
+
date
|
95
|
+
net-protocol
|
96
|
+
net-pop (0.1.2)
|
97
|
+
net-protocol
|
98
|
+
net-protocol (0.2.1)
|
99
|
+
timeout
|
100
|
+
net-smtp (0.4.0)
|
101
|
+
net-protocol
|
102
|
+
nokogiri (1.15.4)
|
103
|
+
mini_portile2 (~> 2.8.2)
|
104
|
+
racc (~> 1.4)
|
105
|
+
nokogiri (1.15.4-arm64-darwin)
|
106
|
+
racc (~> 1.4)
|
107
|
+
parallel (1.23.0)
|
108
|
+
parser (3.2.2.4)
|
109
|
+
ast (~> 2.4.1)
|
110
|
+
racc
|
111
|
+
pry (0.14.2)
|
112
|
+
coderay (~> 1.1)
|
113
|
+
method_source (~> 1.0)
|
114
|
+
racc (1.7.1)
|
115
|
+
rack (3.0.8)
|
116
|
+
rack-session (2.0.0)
|
117
|
+
rack (>= 3.0.0)
|
118
|
+
rack-test (2.1.0)
|
119
|
+
rack (>= 1.3)
|
120
|
+
rails-dom-testing (2.2.0)
|
121
|
+
activesupport (>= 5.0.0)
|
122
|
+
minitest
|
80
123
|
nokogiri (>= 1.6)
|
81
|
-
rails-html-sanitizer (1.
|
82
|
-
loofah (~> 2.
|
83
|
-
|
124
|
+
rails-html-sanitizer (1.6.0)
|
125
|
+
loofah (~> 2.21)
|
126
|
+
nokogiri (~> 1.14)
|
127
|
+
rainbow (3.1.1)
|
128
|
+
rake (13.0.6)
|
84
129
|
rb-readline (0.5.5)
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
rspec-
|
89
|
-
|
90
|
-
rspec-
|
91
|
-
rspec-
|
130
|
+
regexp_parser (2.8.2)
|
131
|
+
rexml (3.2.6)
|
132
|
+
rspec (3.12.0)
|
133
|
+
rspec-core (~> 3.12.0)
|
134
|
+
rspec-expectations (~> 3.12.0)
|
135
|
+
rspec-mocks (~> 3.12.0)
|
136
|
+
rspec-core (3.12.2)
|
137
|
+
rspec-support (~> 3.12.0)
|
138
|
+
rspec-expectations (3.12.3)
|
92
139
|
diff-lcs (>= 1.2.0, < 2.0)
|
93
|
-
rspec-support (~> 3.
|
94
|
-
rspec-mocks (3.
|
140
|
+
rspec-support (~> 3.12.0)
|
141
|
+
rspec-mocks (3.12.6)
|
95
142
|
diff-lcs (>= 1.2.0, < 2.0)
|
96
|
-
rspec-support (~> 3.
|
97
|
-
rspec-support (3.
|
143
|
+
rspec-support (~> 3.12.0)
|
144
|
+
rspec-support (3.12.1)
|
145
|
+
rubocop (1.57.1)
|
146
|
+
base64 (~> 0.1.1)
|
147
|
+
json (~> 2.3)
|
148
|
+
language_server-protocol (>= 3.17.0)
|
149
|
+
parallel (~> 1.10)
|
150
|
+
parser (>= 3.2.2.4)
|
151
|
+
rainbow (>= 2.2.2, < 4.0)
|
152
|
+
regexp_parser (>= 1.8, < 3.0)
|
153
|
+
rexml (>= 3.2.5, < 4.0)
|
154
|
+
rubocop-ast (>= 1.28.1, < 2.0)
|
155
|
+
ruby-progressbar (~> 1.7)
|
156
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
157
|
+
rubocop-ast (1.29.0)
|
158
|
+
parser (>= 3.2.1.0)
|
159
|
+
ruby-progressbar (1.13.0)
|
160
|
+
ruby2_keywords (0.0.5)
|
98
161
|
simplecov (0.16.1)
|
99
162
|
docile (~> 1.1)
|
100
163
|
json (>= 1.8, < 3)
|
101
164
|
simplecov-html (~> 0.10.0)
|
102
165
|
simplecov-html (0.10.2)
|
166
|
+
sync (0.5.0)
|
103
167
|
term-ansicolor (1.7.1)
|
104
168
|
tins (~> 1.0)
|
105
|
-
thor (
|
106
|
-
|
107
|
-
tins (1.
|
108
|
-
|
109
|
-
|
110
|
-
|
169
|
+
thor (1.3.0)
|
170
|
+
timeout (0.4.0)
|
171
|
+
tins (1.32.1)
|
172
|
+
sync
|
173
|
+
tzinfo (2.0.6)
|
174
|
+
concurrent-ruby (~> 1.0)
|
175
|
+
unicode-display_width (2.5.0)
|
111
176
|
|
112
177
|
PLATFORMS
|
178
|
+
arm64-darwin-23
|
113
179
|
ruby
|
114
180
|
|
115
181
|
DEPENDENCIES
|
116
182
|
appraisal
|
117
183
|
builder
|
118
184
|
bundler
|
185
|
+
byebug
|
119
186
|
coveralls
|
120
187
|
meta_presenter!
|
121
188
|
pry
|
122
189
|
rake
|
123
190
|
rb-readline
|
124
191
|
rspec
|
192
|
+
rubocop (~> 1.57)
|
125
193
|
|
126
194
|
BUNDLED WITH
|
127
|
-
|
195
|
+
2.4.21
|
data/README.md
CHANGED
@@ -8,19 +8,19 @@ MetaPresenter is a Ruby gem for writing highly focused and testable Rails view p
|
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
|
-
1. Add this line to your application's Gemfile
|
11
|
+
### 1. Add this line to your application's Gemfile
|
12
12
|
|
13
13
|
```ruby
|
14
14
|
gem 'meta_presenter'
|
15
15
|
```
|
16
16
|
|
17
|
-
2. Bundle from the command line
|
17
|
+
### 2. Bundle from the command line
|
18
18
|
|
19
19
|
```sh
|
20
|
-
|
20
|
+
bundle install
|
21
21
|
```
|
22
22
|
|
23
|
-
3. Include MetaPresenter::Helpers in
|
23
|
+
### 3. Include MetaPresenter::Helpers in ApplicationController
|
24
24
|
|
25
25
|
```ruby
|
26
26
|
class ApplicationController < ActionController::Base
|
@@ -29,157 +29,103 @@ end
|
|
29
29
|
```
|
30
30
|
|
31
31
|
```ruby
|
32
|
+
# mailers are supported too
|
32
33
|
class ApplicationMailer < ActionMailer::Base
|
33
34
|
include MetaPresenter::Helpers
|
34
35
|
end
|
35
36
|
```
|
36
37
|
|
37
|
-
##
|
38
|
+
## Setup
|
38
39
|
|
39
|
-
|
40
|
+
### 1. Create an ApplicationPresenter
|
40
41
|
|
41
|
-
|
42
|
-
app/
|
43
|
-
controllers/
|
44
|
-
application_controller.rb
|
45
|
-
pages_controller.rb
|
46
|
-
presenters/
|
47
|
-
application_presenter.rb
|
48
|
-
pages_presenter.rb
|
49
|
-
pages/
|
50
|
-
home_presenter.rb
|
51
|
-
logs_presenter.rb
|
52
|
-
views
|
53
|
-
pages
|
54
|
-
home.html.erb
|
55
|
-
logs.html.erb
|
56
|
-
spec/ (or test/)
|
57
|
-
presenters/
|
58
|
-
application_presenter_spec.rb
|
59
|
-
pages_presenter_spec.rb
|
60
|
-
pages/
|
61
|
-
home_presenter_spec.rb
|
62
|
-
logs_presenter_spec.rb
|
63
|
-
```
|
64
|
-
|
65
|
-
app/controllers/page_controller.rb
|
66
|
-
|
67
|
-
```ruby
|
68
|
-
class ApplicationController < ActionController::Base
|
69
|
-
include MetaPresenter::Helpers
|
70
|
-
|
71
|
-
# Controller methods automatically become available in views and other presenters.
|
72
|
-
# So this gives you presenter.current_user in views, and you can call `current_user`
|
73
|
-
# within your presenters as well
|
74
|
-
def current_user
|
75
|
-
User.first
|
76
|
-
end
|
77
|
-
end
|
78
|
-
```
|
79
|
-
|
80
|
-
app/controllers/dashboard_controller.rb
|
81
|
-
|
82
|
-
```ruby
|
83
|
-
class ApplicationController < ActionController::Base
|
84
|
-
def home
|
85
|
-
end
|
86
|
-
|
87
|
-
def logs
|
88
|
-
end
|
89
|
-
|
90
|
-
private
|
91
|
-
# presenter.logs in views
|
92
|
-
def logs
|
93
|
-
Log.all
|
94
|
-
end
|
95
|
-
end
|
96
|
-
```
|
97
|
-
|
98
|
-
app/presenters/application_presenter.rb
|
42
|
+
ApplicationPresenter methods can be used anywhere in the app. This example makes `presenter.page_title` and `presenter.last_login` accessible from all views.
|
99
43
|
|
100
44
|
```ruby
|
45
|
+
# app/presenters/application_presenter.rb
|
101
46
|
class ApplicationPresenter < MetaPresenter::BasePresenter
|
102
|
-
# Makes presenter.page_title available in all of your app's views
|
103
47
|
def page_title
|
104
48
|
"My App"
|
105
49
|
end
|
106
50
|
|
107
|
-
|
108
|
-
|
109
|
-
#
|
110
|
-
|
111
|
-
|
51
|
+
def last_login
|
52
|
+
# controller methods are available to
|
53
|
+
# presenters in the same namespace
|
54
|
+
time = current_user.last_login_at
|
55
|
+
distance_of_time_in_words_to_now(time)
|
112
56
|
end
|
113
57
|
end
|
114
58
|
```
|
115
59
|
|
116
|
-
|
60
|
+
#### 2. Create presenters for your controllers
|
61
|
+
|
62
|
+
This example makes `presenter.tooltip(text)` available for all actions on `PagesController`:
|
117
63
|
|
118
64
|
```ruby
|
65
|
+
# app/presenters/pages_presenter.rb
|
119
66
|
class PagesPresenter < ApplicationPresenter
|
120
|
-
|
121
|
-
|
122
|
-
def nav_items
|
123
|
-
[
|
124
|
-
{name: "Home", path: home_path},
|
125
|
-
{name: "Logs", path: logs_path}
|
126
|
-
]
|
67
|
+
def tooltip(text)
|
68
|
+
content_tag(:p, text, class: "font-body1")
|
127
69
|
end
|
128
70
|
end
|
129
71
|
```
|
130
72
|
|
131
|
-
|
73
|
+
```Erb
|
74
|
+
<!-- app/views/pages/about.html.erb -->
|
75
|
+
<h1>About</h1>
|
76
|
+
<p data-tipsy-content="<%= presenter.tooltip("Don't Be Evil") %>">Gloogle</p>
|
77
|
+
```
|
78
|
+
|
79
|
+
#### 3. Create presenters for specific actions
|
80
|
+
|
81
|
+
This example makes `presenter.greeting` accessible from views. It also delegates undefined methods to `current_user`, so `presenter.email` would call `current_user.email`:
|
132
82
|
|
133
83
|
```ruby
|
84
|
+
# app/presenters/pages/home_presenter.rb
|
134
85
|
class Pages::HomePresenter < PagesPresenter
|
135
|
-
#
|
136
|
-
#
|
137
|
-
# the current_user
|
86
|
+
# can also delegate specific methods. ex:
|
87
|
+
# delegate :email, :last, to: :current_user
|
138
88
|
delegate_all_to = :current_user
|
139
89
|
|
140
|
-
# presenter.greeting in views
|
141
90
|
def greeting
|
142
|
-
"Hello, #{
|
91
|
+
"Hello, #{name}"
|
143
92
|
end
|
144
93
|
end
|
145
94
|
```
|
146
95
|
|
147
|
-
app/views/pages/home.html.erb
|
148
|
-
|
149
96
|
```Erb
|
97
|
+
<!-- app/views/pages/home.html.erb -->
|
150
98
|
<h1>Home</h1>
|
151
99
|
<p><%= presenter.greeting %></p>
|
152
|
-
<p>Last login <%=
|
100
|
+
<p>Last login <%= presenter.last_login %></p>
|
153
101
|
```
|
154
102
|
|
155
|
-
|
156
|
-
|
157
|
-
```ruby
|
158
|
-
class Pages::LogsPresenter < PagesPresenter
|
159
|
-
# presenter.size and presenter.last will delegate to
|
160
|
-
# the controller's private `#logs`
|
161
|
-
delegate :size, :last, to: :logs
|
162
|
-
|
163
|
-
# presenter.log_text(log) in view
|
164
|
-
def log_text(log)
|
165
|
-
log.description
|
166
|
-
end
|
167
|
-
end
|
168
|
-
```
|
103
|
+
## Example directory structure
|
169
104
|
|
170
|
-
|
105
|
+
Note that presenters mirror the namespace of controllers.
|
171
106
|
|
172
|
-
```
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
107
|
+
```diagram
|
108
|
+
app/
|
109
|
+
controllers/
|
110
|
+
application_controller.rb
|
111
|
+
pages_controller.rb
|
112
|
+
presenters/
|
113
|
+
application_presenter.rb
|
114
|
+
pages_presenter.rb
|
115
|
+
pages/
|
116
|
+
home_presenter.rb
|
117
|
+
logs_presenter.rb
|
118
|
+
views
|
119
|
+
pages
|
120
|
+
home.html.erb
|
121
|
+
logs.html.erb
|
122
|
+
spec/ (or test/)
|
123
|
+
presenters/
|
124
|
+
application_presenter_spec.rb
|
125
|
+
pages_presenter_spec.rb
|
126
|
+
pages/
|
127
|
+
home_presenter_spec.rb
|
128
|
+
logs_presenter_spec.rb
|
183
129
|
```
|
184
130
|
|
185
131
|
## Aliasing the presenter methods
|
@@ -197,35 +143,50 @@ end
|
|
197
143
|
|
198
144
|
## Requirements
|
199
145
|
|
200
|
-
MetaPresenter supports Ruby >= 2.
|
146
|
+
MetaPresenter supports Ruby >= 2.7.5 and ActionPack/ActionMailer >= 6
|
201
147
|
|
202
148
|
## Links
|
203
149
|
|
204
|
-
|
205
|
-
|
150
|
+
- [Project website](https://metapresenter.com)
|
151
|
+
- [RDocs for the master branch](https://www.rubydoc.info/github/szTheory/meta-presenter/master)
|
206
152
|
|
207
153
|
## Specs
|
154
|
+
|
208
155
|
To run the specs for the currently running Ruby version, run `bundle install` and then `bundle exec rspec`. To run specs for every supported version of ActionPack, run `bundle exec appraisal install` and then `bundle exec appraisal rspec`.
|
209
156
|
|
210
157
|
## Gem release
|
158
|
+
|
211
159
|
Make sure the specs pass, bump the version number in meta_presenter.gemspec, build the gem with `gem build meta_presenter.gemspec`. Commit your changes and push to Github, then tag the commit with the current release number using Github's Releases interface (use the format vx.x.x, where x is the semantic version number). You can pull the latest tags to your local repo with `git pull --tags`. Finally, push the gem with `gem push meta_presenter-version-number-here.gem`.
|
212
160
|
|
161
|
+
## TODO High-Priority
|
162
|
+
|
163
|
+
- Add a `rake meta_presenter:install` that generates the scaffolding for you
|
164
|
+
- Make sure directions are clear for manually creating presenters
|
165
|
+
|
213
166
|
## TODO
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
* add support for layout-level presenters
|
218
|
-
* add Rails 6 support once it comes out (hopefully just have to add a gemfiles/actionpack6.gemfile and it will run with the Appraisal suite)
|
167
|
+
|
168
|
+
- create an example app and link to the repo for it in this README
|
169
|
+
- add support for layout-level presenters
|
219
170
|
|
220
171
|
## Contributing
|
221
172
|
|
222
173
|
1. Fork it
|
223
|
-
2. Create your feature branch (`git checkout -b feature/my-new-feature`) or bugfix branch (`git checkout -b bugfix/my-helpful-bugfix`)
|
174
|
+
2. Create your feature branch (`git checkout -b feature/my-new-feature`) or bugfix branch (`git checkout -b bugfix/my-helpful-bugfix`)
|
224
175
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
225
176
|
4. Push to the branch (`git push origin feature/my-new-feature`)
|
226
177
|
5. Make sure specs are passing (`bundle exec rspec`)
|
227
178
|
6. Create new Pull Request
|
228
179
|
|
180
|
+
## Running the specs
|
181
|
+
|
182
|
+
To run specs against different versions of Rails:
|
183
|
+
|
184
|
+
```bash
|
185
|
+
bundle exec appraisal install #install dependencies for each ruby version
|
186
|
+
bundle exec appraisal rails6 rspec #run rails 6 specs on current Ruby
|
187
|
+
bundle exec appraisal rails7 rspec #run rails 7 specs on current Ruby
|
188
|
+
```
|
189
|
+
|
229
190
|
## License
|
230
191
|
|
231
192
|
See the [LICENSE](https://github.com/szTheory/meta_presenter/blob/master/LICENSE.txt) file.
|