digestifier 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +84 -8
- data/digestifier.gemspec +1 -1
- data/lib/digestifier/delivery.rb +1 -3
- data/lib/digestifier/digest.rb +1 -1
- data/spec/acceptance/custom_views_spec.rb +3 -1
- data/spec/acceptance/delivering_digests_spec.rb +3 -1
- data/spec/acceptance/recipient_preferences_spec.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3a5586226e9c9c2d3873fa148109906568a72bd
|
4
|
+
data.tar.gz: f0028131bb564be48fb02c89914559727834f6fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae5bb559b00b5e577bf18a91f16398abe0dca5a330806cf553764c44fbc79af499aa54cc72c1e45e7e10e82ccb7ad2707c565aae63da26bb955f34dca7412fa7
|
7
|
+
data.tar.gz: cd7b5a66c3e5592c834ce79380d28ded690e079a36e80814af27a77d1b78f1f3243c14211980a94fa5708398f70b6fb1984a5f46afddef32dca271df9b6f57e0
|
data/README.md
CHANGED
@@ -1,29 +1,105 @@
|
|
1
1
|
# Digestifier
|
2
2
|
|
3
|
-
|
3
|
+
A simple Rails engine for sending out email digests of activity.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
gem 'digestifier'
|
9
|
+
gem 'digestifier', '0.0.2'
|
10
10
|
|
11
|
-
|
11
|
+
Don't forget to bundle:
|
12
12
|
|
13
13
|
$ bundle
|
14
14
|
|
15
|
-
|
15
|
+
Then, add the migrations to your app and update your database accordingly:
|
16
16
|
|
17
|
-
$
|
17
|
+
$ rake digestifier:install:migrations db:migrate
|
18
18
|
|
19
|
-
##
|
19
|
+
## Configuration
|
20
20
|
|
21
|
-
|
21
|
+
Create an initializer that sets up both a digest and the sender address:
|
22
22
|
|
23
|
-
|
23
|
+
```ruby
|
24
|
+
# config/initializers/digestifier.rb
|
25
|
+
|
26
|
+
# Set the sender of your digest emails
|
27
|
+
Digestifier.sender = 'Hello <hello@inspire9.com>'
|
28
|
+
|
29
|
+
# Set the digest object to a constant so it can be referred to elsewhere.
|
30
|
+
DIGEST = Digestifier::Digest.new
|
31
|
+
# Set the lambda that returns objects for the digest. This takes a single
|
32
|
+
# argument - the time range - and should return a collection of objects. How
|
33
|
+
# you get this collection is up to you, but the example below is a decent
|
34
|
+
# starting point.
|
35
|
+
DIGEST.contents = lambda { |range|
|
36
|
+
Article.where(created_at: range).order(:created_at)
|
37
|
+
}
|
38
|
+
# The digest recipients defaults to all User objects in your system. If you
|
39
|
+
# want to use a different class, or filter those objects, you can customise it:
|
40
|
+
DIGEST.recipients = lambda { User }
|
41
|
+
# The default frequency is once a day.
|
42
|
+
DIGEST.default_frequency = 24.hours
|
43
|
+
```
|
44
|
+
|
45
|
+
### Sending emails
|
46
|
+
|
47
|
+
This will likely go in a rake task - but it's up to you.
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
Digestifier::Delivery.deliver DIGEST
|
51
|
+
```
|
52
|
+
|
53
|
+
If it does go in a rake task, ensure the task loads your Rails environment as well:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
task :send_digest => :environment do
|
57
|
+
Digestifier::Delivery.deliver DIGEST
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
### Customising partial templates
|
62
|
+
|
63
|
+
This step is almost certainly essential: you'll want to customise how each item in your digest is presented. The partials for this should be located in `app/views/digestifier/mailer`, and use the item's class name, downcased and underscored (for example: `_article.html.erb` or `_comment.html.haml`).
|
64
|
+
|
65
|
+
What goes in these templates is completely up to you - the default is super-simple and almost certainly not enough for a decent digest:
|
66
|
+
|
67
|
+
```erb
|
68
|
+
<%= digest_item.name %>
|
69
|
+
```
|
70
|
+
|
71
|
+
`digest_item` will be available in your partial, but you can also refer to it using a downcased and underscored interpretation of the class (so, `article` and `comment` respectively in the example file names above).
|
72
|
+
|
73
|
+
### Customising the main email
|
74
|
+
|
75
|
+
The main email template should probably be overwritten as well - just put your preferred view code in `app/views/digestifier/mailer/digest.[html.erb|html.haml|etc]`.
|
76
|
+
|
77
|
+
The two instance variables you have access to are `@recipient` and `@content_items`. If you wish to use the Digestifier partial matching, something like this should do the trick:
|
78
|
+
|
79
|
+
```erb
|
80
|
+
<% @content_items.each do |item| %>
|
81
|
+
<%= render_digest_partial item %>
|
82
|
+
<% end %>
|
83
|
+
```
|
84
|
+
|
85
|
+
### Customising the mailer
|
86
|
+
|
87
|
+
If you want to put your own Mailer, then this is certainly possible:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
Digestifier.mailer = CustomMailer
|
91
|
+
```
|
92
|
+
|
93
|
+
Your new mailer class should respond to `digest` and accept the following arguments: recipient and content_items.
|
94
|
+
|
95
|
+
### Contributing
|
24
96
|
|
25
97
|
1. Fork it
|
26
98
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
99
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
100
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
101
|
5. Create new Pull Request
|
102
|
+
|
103
|
+
## Licence
|
104
|
+
|
105
|
+
Copyright (c) 2013, Digestifier is developed and maintained by [Inspire9](http://inspire9.com), and is released under the open MIT Licence.
|
data/digestifier.gemspec
CHANGED
data/lib/digestifier/delivery.rb
CHANGED
data/lib/digestifier/digest.rb
CHANGED
@@ -7,7 +7,9 @@ describe 'Custom digest frequency' do
|
|
7
7
|
before :each do
|
8
8
|
ActionMailer::Base.deliveries.clear
|
9
9
|
|
10
|
-
digest.contents = lambda {
|
10
|
+
digest.contents = lambda { |range|
|
11
|
+
Article.where(created_at: range).order(:created_at)
|
12
|
+
}
|
11
13
|
end
|
12
14
|
|
13
15
|
it 'respects receipient frequency preferences' do
|