notification-renderer 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +43 -249
- data/lib/notifications-rails.rb +6 -0
- metadata +9 -21
- data/app/helpers/notification_renderer_helper.rb +0 -80
- data/lib/generators/notification_renderer/install_generator.rb +0 -46
- data/lib/generators/notification_renderer/type_generator.rb +0 -30
- data/lib/generators/templates/install/initializer.rb +0 -12
- data/lib/generators/templates/install/notifications_migration.rb.erb +0 -7
- data/lib/generators/templates/type/_template.html +0 -7
- data/lib/notification-renderer.rb +0 -10
- data/lib/notification_renderer/configuration.rb +0 -27
- data/lib/notification_renderer/engine.rb +0 -9
- data/lib/notification_renderer/notification_lib.rb +0 -49
- data/lib/notification_renderer/notification_scopes.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36bf41fe2085e87d8719b4bf164cfd9620b65a048f3c784274f912abafb86853
|
4
|
+
data.tar.gz: cf6006fb927acdea8edaf91fc3b0c1c65efc9d60b3ac24cb643f0b4e23a5af3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b91805d98abf2485e2d41548196f1aa7244d627b238a4935833b6a0365ed7625062fd0752c6892f9b5bfe14af73c6c688735c1690182016bccc3c4003c6e998
|
7
|
+
data.tar.gz: c0d168c97b8570c04a56c8bc6e8a47aecff54ca051c47da3472128251aec578aee32387c1136076043d6bdff42a509dbac87a3875e7b6f10c185e258165082d4
|
data/README.md
CHANGED
@@ -1,290 +1,84 @@
|
|
1
|
-
#
|
1
|
+
# notifications-rails
|
2
2
|
|
3
|
-
|
3
|
+
notifications-rails is the most powerful notification library for Rails. It offers not only simple APIs to create and render notifications but also supports user-integration and cross-platform delivery of notifications.
|
4
4
|
|
5
|
-
|
5
|
+
## Philosophy
|
6
6
|
|
7
|
-
|
7
|
+
notifications-rails has been built with modularity in mind. It currently consists of four components each of which bringing one essential functionality to the integration of notifications in your Rails app.
|
8
8
|
|
9
|
-
|
9
|
+
**[notification-handler](notification-handler):** Create and modify your notifications through a simple API.
|
10
10
|
|
11
|
-
|
12
|
-
* [Usage](#usage)
|
13
|
-
* [Types](#types)
|
14
|
-
* [Generating a new type](#generating-a-new-type)
|
15
|
-
* [Using a type](#using-a-type)
|
16
|
-
* [Renderers](#renderers)
|
17
|
-
* [View helpers](#view-helpers)
|
18
|
-
* [`render_notification`](#render_notification)
|
19
|
-
* [`render_notifications`](#render_notifications)
|
20
|
-
* [Grouping](#grouping)
|
21
|
-
* [Grouping by notification types](#grouping-by-notification-types)
|
22
|
-
* [Grouping by notification dates](#grouping-by-notification-dates)
|
23
|
-
* [Configuration](#configuration)
|
24
|
-
* [To Do](#to-do)
|
25
|
-
* [Contributing](#contributing)
|
26
|
-
* [Semantic versioning](#semantic-versioning)
|
11
|
+
**[notification-renderer](notification-renderer):** Render your notifications in various contexts.
|
27
12
|
|
28
|
-
|
13
|
+
**[notification-pusher](notification-pusher):** Deliver your notifications to various services, including [Email](notification-pusher/notification-pusher-actionmailer) and [OneSignal](notification-pusher/notification-pusher-onesignal).
|
29
14
|
|
30
|
-
|
31
|
-
|
32
|
-
NotificationRenderer works with Rails 5 onwards. You can add it to your `Gemfile` with:
|
33
|
-
|
34
|
-
```ruby
|
35
|
-
gem 'notification-renderer'
|
36
|
-
```
|
37
|
-
|
38
|
-
And then execute:
|
39
|
-
|
40
|
-
$ bundle
|
41
|
-
|
42
|
-
Or install it yourself as:
|
43
|
-
|
44
|
-
$ gem install notification-renderer
|
45
|
-
|
46
|
-
Now run the generator:
|
47
|
-
|
48
|
-
$ rails g notification_renderer:install
|
49
|
-
|
50
|
-
To wrap things up, migrate the changes to your database:
|
51
|
-
|
52
|
-
$ rails db:migrate
|
53
|
-
|
54
|
-
---
|
55
|
-
|
56
|
-
## Usage
|
57
|
-
|
58
|
-
### Types
|
59
|
-
|
60
|
-
NotificationRenderer uses templates to render your notifications.
|
61
|
-
|
62
|
-
The `type` of a notification determines which template gets utilized for rendering. Each notification type has multiple templates each of which responsible for rendering a notification in another scenario. The default template for a given type is `index`.
|
63
|
-
|
64
|
-
#### Generating a new type
|
65
|
-
|
66
|
-
This gem comes with a generator to make adding new types a whole lot easier. Run in your terminal:
|
67
|
-
|
68
|
-
$ rails g notification_renderer:type -t notification
|
69
|
-
|
70
|
-
This will create the following structure in your application:
|
71
|
-
|
72
|
-
* `views`
|
73
|
-
* `notifications`
|
74
|
-
* `notification`
|
75
|
-
* `_index.html.erb`
|
15
|
+
**[notification-settings](notification-settings):** Integrates with your authentication solution to craft a personalized user notification platform.
|
76
16
|
|
77
|
-
You
|
17
|
+
You may just use the components you actually need, or instead use this gem to bundle everything for a complete notification solution.
|
78
18
|
|
79
|
-
|
80
|
-
|
81
|
-
This command will also create a custom renderer called `feed` for the notification type `notification`:
|
82
|
-
|
83
|
-
* `views`
|
84
|
-
* `notifications`
|
85
|
-
* `notification`
|
86
|
-
* `_feed.html.erb`
|
87
|
-
* `_index.html.erb`
|
88
|
-
|
89
|
-
#### Using a type
|
90
|
-
|
91
|
-
You are able to specify the `type` of a `Notification` record:
|
92
|
-
|
93
|
-
```ruby
|
94
|
-
notification = Notification.create(target: User.first, object: Recipe.first, type: 'notification')
|
95
|
-
```
|
96
|
-
|
97
|
-
**Note:** The `type` attribute of any new `Notification` record will default to the [`default_type` configuration](#configuration).
|
19
|
+
## Installation
|
98
20
|
|
99
|
-
You can
|
21
|
+
You can add notifications-rails to your `Gemfile` with:
|
100
22
|
|
101
23
|
```ruby
|
102
|
-
|
103
|
-
Notification.notification_type
|
104
|
-
|
105
|
-
# Return records with `'follow'` as type
|
106
|
-
Notification.follow_type
|
107
|
-
```
|
108
|
-
|
109
|
-
### Renderers
|
110
|
-
|
111
|
-
In your renderers you can access the `Notification` record through the `notification` variable. This is how a renderer could look like:
|
112
|
-
|
113
|
-
```erb
|
114
|
-
<%= notification.target.name %> commented on <%= notification.object.article.title %>.
|
115
|
-
```
|
116
|
-
|
117
|
-
### View helpers
|
118
|
-
|
119
|
-
NotificationRenderer introduces some view helpers to assist you in embedding notifications.
|
120
|
-
|
121
|
-
#### `render_notification`
|
122
|
-
|
123
|
-
`render_notification` renders a single `Notification` record:
|
124
|
-
|
125
|
-
```erb
|
126
|
-
<%= render_notification Notification.first %>
|
127
|
-
```
|
128
|
-
|
129
|
-
Rendering a notification will set its `read` attribute to `true`. This behavior can be [configured](#configuration).
|
130
|
-
|
131
|
-
You can also specify a renderer. It defaults to `'index'`.
|
132
|
-
|
133
|
-
```erb
|
134
|
-
<%= render_notification Notification.first, 'feed' %>
|
24
|
+
gem 'notifications-rails'
|
135
25
|
```
|
136
26
|
|
137
|
-
|
27
|
+
And then run:
|
138
28
|
|
139
|
-
|
29
|
+
$ bundle install
|
140
30
|
|
141
|
-
|
142
|
-
<%= render_notifications Notification.all %>
|
143
|
-
```
|
144
|
-
|
145
|
-
You can also specify a renderer. It defaults to `'index'`.
|
146
|
-
|
147
|
-
```erb
|
148
|
-
<%= render_notifications Notification.all, 'feed' %>
|
149
|
-
```
|
150
|
-
|
151
|
-
It wraps the rendered notifications in a `div`:
|
152
|
-
|
153
|
-
```html
|
154
|
-
<div class="notification-renderer notifications">
|
155
|
-
<!-- ... -->
|
156
|
-
</div>
|
157
|
-
```
|
31
|
+
Or install it yourself as:
|
158
32
|
|
159
|
-
|
33
|
+
$ gem install notifications-rails
|
160
34
|
|
161
|
-
|
35
|
+
If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
|
162
36
|
|
163
37
|
```ruby
|
164
|
-
|
165
|
-
Notification.all.grouping(['object.article', 'metadata[:title]'])
|
166
|
-
```
|
167
|
-
|
168
|
-
**Note:** Notifications will be grouped in order.
|
169
|
-
|
170
|
-
When rendering notifications you often want to group them by the object they belong to. This is how to group notifications by the associated object:
|
171
|
-
|
172
|
-
```erb
|
173
|
-
<%= render_notifications_grouped Notification.all, ['object'], renderer: 'feed' %>
|
174
|
-
```
|
175
|
-
|
176
|
-
You can also group notifications by nested attributes:
|
177
|
-
|
178
|
-
```erb
|
179
|
-
<%= render_notifications_grouped Notification.all, ['object.article'] %>
|
180
|
-
<%= render_notifications_grouped Notification.all, ['metadata[:title]'] %>
|
181
|
-
```
|
182
|
-
|
183
|
-
It is also possible to group notifications for just one object:
|
184
|
-
|
185
|
-
```erb
|
186
|
-
<%= render_notifications_grouped Notification.where(object_id: 1, object_type: 'Comment'), ['object'] %>
|
187
|
-
```
|
188
|
-
|
189
|
-
This will render the last notification for every group and pass the attributes value grouped by to your renderer:
|
190
|
-
|
191
|
-
```erb
|
192
|
-
<!-- View -->
|
193
|
-
|
194
|
-
<%= render_notifications_grouped Notification.notification_type, ['object.article'] %>
|
195
|
-
```
|
196
|
-
|
197
|
-
```erb
|
198
|
-
<!-- Renderer -->
|
199
|
-
|
200
|
-
<% if notification_grouped? %>
|
201
|
-
<%= notification.target.name %> and <%= (notifications.size - 1).to_s %> others commented on <%= attributes['object.article'].title %>.
|
202
|
-
<% else %>
|
203
|
-
<%= notification.target.name %> commented on <%= notification.object.article.title %>.
|
204
|
-
<% end %>
|
205
|
-
```
|
206
|
-
|
207
|
-
Grouping makes the following two methods available in your renderer:
|
208
|
-
|
209
|
-
**`attributes`** Hash of attributes grouped by and their values.
|
210
|
-
|
211
|
-
**`notifications`** The ActiveRecord array of notifications including the currently rendered notification.
|
212
|
-
|
213
|
-
You may check whether a template is being used for grouping by using the `notification_grouped?` helper method.
|
214
|
-
|
215
|
-
#### Grouping by notification types
|
216
|
-
|
217
|
-
It is common, if rendering multiple notification types at once, to group the notifications by their type:
|
218
|
-
|
219
|
-
```erb
|
220
|
-
<%= render_notifications_grouped Notification.all, ['object.article'], group_by_type: true %>
|
221
|
-
```
|
222
|
-
|
223
|
-
This is identical to the following:
|
224
|
-
|
225
|
-
```erb
|
226
|
-
<%= render_notifications_grouped Notification.all, [:type, 'object.article'] %>
|
38
|
+
gem 'notifications-rails', github: 'jonhue/notifications-rails'
|
227
39
|
```
|
228
40
|
|
229
|
-
|
230
|
-
|
231
|
-
It is also often required to group notifications by their date of creation:
|
232
|
-
|
233
|
-
```erb
|
234
|
-
<%= render_notifications_grouped Notification.all, ['object.article'], group_by_date: :month %>
|
235
|
-
```
|
236
|
-
|
237
|
-
This is identical to the following:
|
238
|
-
|
239
|
-
```erb
|
240
|
-
<%= render_notifications_grouped Notification.all, ['created_at.beginning_of_month', 'object.article'] %>
|
241
|
-
```
|
242
|
-
|
243
|
-
Accepted values are:
|
41
|
+
## Usage
|
244
42
|
|
245
|
-
|
246
|
-
* `:hour`
|
247
|
-
* `:day`
|
248
|
-
* `:week`
|
249
|
-
* `:month`
|
250
|
-
* `:year`
|
43
|
+
Details on usage are provided in the [documentation](#philosophy) of the specific modules.
|
251
44
|
|
252
|
-
|
45
|
+
## Development
|
253
46
|
|
254
|
-
|
47
|
+
To start development you first have to fork this repository and locally clone your fork.
|
255
48
|
|
256
|
-
|
49
|
+
Install the projects dependencies by running:
|
257
50
|
|
258
|
-
|
51
|
+
$ bundle install
|
259
52
|
|
260
|
-
|
261
|
-
NotificationRenderer.configure do |config|
|
262
|
-
config.default_type = 'notification'
|
263
|
-
end
|
264
|
-
```
|
53
|
+
### Testing
|
265
54
|
|
266
|
-
|
55
|
+
Tests are written with RSpec. Integration tests are located in `/spec`, unit tests can be found in `<module>/spec`.
|
267
56
|
|
268
|
-
|
57
|
+
To run all tests:
|
269
58
|
|
270
|
-
|
59
|
+
$ ./rspec
|
271
60
|
|
272
|
-
|
61
|
+
To run RuboCop:
|
273
62
|
|
274
|
-
|
63
|
+
$ bundle exec rubocop
|
275
64
|
|
276
|
-
|
65
|
+
You can find all commands run by the CI workflow in `.github/workflows/ci.yml`.
|
277
66
|
|
278
|
-
|
67
|
+
## Contributing
|
279
68
|
|
280
|
-
|
69
|
+
We warmly welcome everyone who is intersted in contributing. Please reference our [contributing guidelines](CONTRIBUTING.md) and our [Code of Conduct](CODE_OF_CONDUCT.md).
|
281
70
|
|
282
|
-
##
|
71
|
+
## Releases
|
283
72
|
|
284
|
-
|
73
|
+
[Here](https://github.com/jonhue/notifications-rails/releases) you can find details on all past releases. Unreleased breaking changes that are on the current master can be found [here](CHANGELOG.md).
|
285
74
|
|
286
|
-
|
75
|
+
notifications-rails follows Semantic Versioning 2.0 as defined at http://semver.org. Reference our [security policy](SECURITY.md).
|
287
76
|
|
288
|
-
###
|
77
|
+
### Publishing
|
289
78
|
|
290
|
-
|
79
|
+
1. Review breaking changes and deprecations in `CHANGELOG.md`.
|
80
|
+
1. Change the gem version in `VERSION`.
|
81
|
+
1. Reset `CHANGELOG.md`.
|
82
|
+
1. Create a pull request to merge the changes into `master`.
|
83
|
+
1. After the pull request was merged, create a new release listing the breaking changes and commits on `master` since the last release.
|
84
|
+
1. The release workflow will publish the gems to RubyGems.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notification-renderer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Hübotter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3.0.
|
47
|
+
version: 3.0.3
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 3.0.
|
54
|
+
version: 3.0.3
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: railties
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,26 +164,15 @@ dependencies:
|
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
-
description: Render your notifications
|
168
|
-
|
169
|
-
email: me@jonhue.me
|
167
|
+
description: Render your notifications in various contexts.
|
168
|
+
email: jonas.huebotter@gmail.com
|
170
169
|
executables: []
|
171
170
|
extensions: []
|
172
171
|
extra_rdoc_files: []
|
173
172
|
files:
|
174
173
|
- LICENSE
|
175
174
|
- README.md
|
176
|
-
-
|
177
|
-
- lib/generators/notification_renderer/install_generator.rb
|
178
|
-
- lib/generators/notification_renderer/type_generator.rb
|
179
|
-
- lib/generators/templates/install/initializer.rb
|
180
|
-
- lib/generators/templates/install/notifications_migration.rb.erb
|
181
|
-
- lib/generators/templates/type/_template.html
|
182
|
-
- lib/notification-renderer.rb
|
183
|
-
- lib/notification_renderer/configuration.rb
|
184
|
-
- lib/notification_renderer/engine.rb
|
185
|
-
- lib/notification_renderer/notification_lib.rb
|
186
|
-
- lib/notification_renderer/notification_scopes.rb
|
175
|
+
- lib/notifications-rails.rb
|
187
176
|
homepage: https://github.com/jonhue/notifications-rails/tree/master/notification-renderer
|
188
177
|
licenses:
|
189
178
|
- MIT
|
@@ -204,9 +193,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
193
|
- !ruby/object:Gem::Version
|
205
194
|
version: '0'
|
206
195
|
requirements: []
|
207
|
-
rubygems_version: 3.
|
196
|
+
rubygems_version: 3.1.4
|
208
197
|
signing_key:
|
209
198
|
specification_version: 4
|
210
|
-
summary: Render your notifications
|
211
|
-
types
|
199
|
+
summary: Render your notifications in various contexts
|
212
200
|
test_files: []
|
@@ -1,80 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module NotificationRendererHelper
|
4
|
-
def render_notification(notification,
|
5
|
-
renderer: default_renderer,
|
6
|
-
attributes: nil,
|
7
|
-
notifications: nil)
|
8
|
-
notification.update(read: true) if auto_read
|
9
|
-
render(
|
10
|
-
partial: "notifications/#{notification.type}/#{renderer}",
|
11
|
-
locals: {
|
12
|
-
notification: notification,
|
13
|
-
attributes: attributes,
|
14
|
-
notifications: notifications
|
15
|
-
}
|
16
|
-
)
|
17
|
-
end
|
18
|
-
|
19
|
-
def render_notifications(notifications, renderer: default_renderer)
|
20
|
-
content_tag :div, class: 'notification-renderer notifications' do
|
21
|
-
notifications&.map do |notification|
|
22
|
-
render_notification(notification, renderer: renderer)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def render_notifications_grouped(notifications, group_by,
|
28
|
-
renderer: default_renderer,
|
29
|
-
group_by_date: false,
|
30
|
-
group_by_type: false)
|
31
|
-
group_by.unshift(:type) if group_by_type
|
32
|
-
if group_by_date
|
33
|
-
group_by.unshift("created_at.beginning_of_#{group_by_date}")
|
34
|
-
end
|
35
|
-
|
36
|
-
content_tag :div, class: 'notification-renderer notifications' do
|
37
|
-
recursive_notification_grouping(
|
38
|
-
notifications.grouping(group_by), group_by, renderer
|
39
|
-
)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def notification_grouped?
|
44
|
-
local_assigns[:attributes] && local_assigns[:notifications]
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def recursive_notification_grouping(notifications, group_by, renderer,
|
50
|
-
attributes)
|
51
|
-
i = 0
|
52
|
-
notifications.each do |k, v|
|
53
|
-
attributes[group_by[i]] = k
|
54
|
-
i += 1
|
55
|
-
recursive_render_notifications_grouped(v, renderer, attributes)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def recursive_render_notifications_grouped(notifications, renderer,
|
60
|
-
attributes)
|
61
|
-
if notifications.is_a?(Hash)
|
62
|
-
recursive_notification_grouping(
|
63
|
-
notifications, group_by, renderer, attributes
|
64
|
-
)
|
65
|
-
else
|
66
|
-
render_notification(notifications.last,
|
67
|
-
renderer: renderer,
|
68
|
-
attributes: attributes,
|
69
|
-
notifications: notifications)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def auto_read
|
74
|
-
NotificationRenderer.configuration.auto_read
|
75
|
-
end
|
76
|
-
|
77
|
-
def default_renderer
|
78
|
-
NotificationRenderer.configuration.default_renderer
|
79
|
-
end
|
80
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails/generators'
|
4
|
-
require 'rails/generators/migration'
|
5
|
-
|
6
|
-
module NotificationRenderer
|
7
|
-
class InstallGenerator < Rails::Generators::Base
|
8
|
-
include Rails::Generators::Migration
|
9
|
-
|
10
|
-
source_root(File.join(File.dirname(__FILE__), '../templates/install'))
|
11
|
-
desc 'Install NotificationRenderer'
|
12
|
-
|
13
|
-
def self.next_migration_number(dirname)
|
14
|
-
if ActiveRecord::Base.timestamped_migrations
|
15
|
-
Time.now.utc.strftime('%Y%m%d%H%M%S')
|
16
|
-
else
|
17
|
-
format('%<migration_number>.3d',
|
18
|
-
migration_number: current_migration_number(dirname) + 1)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def create_initializer
|
23
|
-
template 'initializer.rb', 'config/initializers/notification_renderer.rb'
|
24
|
-
end
|
25
|
-
|
26
|
-
def create_notifications_migration_file
|
27
|
-
migration_template(
|
28
|
-
'notifications_migration.rb.erb',
|
29
|
-
'db/migrate/notification_renderer_migration.rb',
|
30
|
-
migration_version: migration_version
|
31
|
-
)
|
32
|
-
end
|
33
|
-
|
34
|
-
def create_templates
|
35
|
-
system 'rails g notification_renderer:type -t notification'
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def migration_version
|
41
|
-
return unless Rails.version >= '5.0.0'
|
42
|
-
|
43
|
-
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails/generators'
|
4
|
-
require 'rails/generators/migration'
|
5
|
-
|
6
|
-
module NotificationRenderer
|
7
|
-
class TypeGenerator < Rails::Generators::Base
|
8
|
-
source_root(File.join(File.dirname(__FILE__), '../templates/type'))
|
9
|
-
desc 'Create a new notification type'
|
10
|
-
class_option :type,
|
11
|
-
desc: 'Specify the notification type',
|
12
|
-
type: :string,
|
13
|
-
default: NotificationRenderer.configuration.default_type,
|
14
|
-
aliases: '-t'
|
15
|
-
class_option :renderers,
|
16
|
-
desc: 'Specify the renderer templates',
|
17
|
-
type: :string,
|
18
|
-
default: NotificationRenderer.configuration.default_renderer,
|
19
|
-
aliases: '-r'
|
20
|
-
|
21
|
-
def create_templates
|
22
|
-
options[:renderers].split(' ')&.each do |template|
|
23
|
-
template(
|
24
|
-
'_template.html',
|
25
|
-
"app/views/notifications/#{options[:type]}/_#{template}.html.erb"
|
26
|
-
)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
NotificationRenderer.configure do |config|
|
4
|
-
# Choose your default notification type. Takes a string.
|
5
|
-
# config.default_type = 'notification'
|
6
|
-
|
7
|
-
# Choose your default renderer. Takes a string.
|
8
|
-
# config.default_renderer = 'index'
|
9
|
-
|
10
|
-
# Automatically mark rendered notifications as read. Takes a boolean.
|
11
|
-
# config.auto_read = true
|
12
|
-
end
|
@@ -1,7 +0,0 @@
|
|
1
|
-
<!--
|
2
|
-
In your renderers you can access the `Notification` record through the `notification` variable. This is how a renderer could look like:
|
3
|
-
|
4
|
-
<%%= notification.target.name %> commented on <%%= notification.object.article.title %>
|
5
|
-
|
6
|
-
Learn more: https://github.com/jonhue/notifications-rails/tree/master/notification-renderer#renderers
|
7
|
-
-->
|
@@ -1,10 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module NotificationRenderer
|
4
|
-
require_relative 'notification_renderer/configuration'
|
5
|
-
|
6
|
-
require_relative 'notification_renderer/engine'
|
7
|
-
|
8
|
-
autoload :NotificationLib, 'notification_renderer/notification_lib'
|
9
|
-
autoload :NotificationScopes, 'notification_renderer/notification_scopes'
|
10
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module NotificationRenderer
|
4
|
-
class << self
|
5
|
-
attr_writer :configuration
|
6
|
-
|
7
|
-
def configuration
|
8
|
-
@configuration ||= Configuration.new
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.configure
|
13
|
-
yield configuration
|
14
|
-
end
|
15
|
-
|
16
|
-
class Configuration
|
17
|
-
attr_accessor :default_type
|
18
|
-
attr_accessor :default_renderer
|
19
|
-
attr_accessor :auto_read
|
20
|
-
|
21
|
-
def initialize
|
22
|
-
@default_type = 'notification'
|
23
|
-
@default_renderer = 'index'
|
24
|
-
@auto_read = true
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'notification-handler'
|
4
|
-
require 'active_support'
|
5
|
-
|
6
|
-
module NotificationRenderer
|
7
|
-
module NotificationLib
|
8
|
-
extend ActiveSupport::Concern
|
9
|
-
|
10
|
-
module ClassMethods
|
11
|
-
def grouping(group_by)
|
12
|
-
notifications = all
|
13
|
-
group_by.each do |method|
|
14
|
-
notifications = recursive_grouping(notifications, method)
|
15
|
-
end
|
16
|
-
notifications
|
17
|
-
end
|
18
|
-
|
19
|
-
def grouping_by(group_by)
|
20
|
-
all.group_by { |notification| notification.send(group_by) }
|
21
|
-
end
|
22
|
-
|
23
|
-
def recursive_grouping(notifications, group_by)
|
24
|
-
if notifications.is_a?(Hash)
|
25
|
-
recursive_hash_grouping(notifications, group_by)
|
26
|
-
else
|
27
|
-
notifications.grouping_by(group_by)
|
28
|
-
end
|
29
|
-
notifications
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def type
|
34
|
-
self[:type] || NotificationRenderer.configuration.default_type
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def recursive_hash_grouping(notifications, group_by)
|
40
|
-
notifications.each_pair do |k, v|
|
41
|
-
if v.is_a?(Hash)
|
42
|
-
recursive_hash_grouping(v, group_by)
|
43
|
-
else
|
44
|
-
notifications[k] = v.grouping_by(group_by)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'notification-handler'
|
4
|
-
require 'active_support'
|
5
|
-
|
6
|
-
module NotificationRenderer
|
7
|
-
module NotificationScopes
|
8
|
-
extend ActiveSupport::Concern
|
9
|
-
|
10
|
-
module ClassMethods
|
11
|
-
def method_missing(method, *args)
|
12
|
-
if method.to_s[/(.+)_type/]
|
13
|
-
where(type: $1.singularize.classify)
|
14
|
-
else
|
15
|
-
super
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def respond_to_missing?(method, include_private = false)
|
20
|
-
super || method.to_s[/(.+)_type/]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|