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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6571f35b67e51f1547d094219716e4545cf9a635
4
- data.tar.gz: 0768e76da9516ffca6a432db97a5ff484df60444
3
+ metadata.gz: d3a5586226e9c9c2d3873fa148109906568a72bd
4
+ data.tar.gz: f0028131bb564be48fb02c89914559727834f6fd
5
5
  SHA512:
6
- metadata.gz: 6c54ef82d778a0e4dfda4b7608f1ac382c1dfaa8b00c9c47382433a6fd185e272a989f58a49fd368f8c32ae9d9904f56a73a7a9d86d5fb79f56e4468516404cf
7
- data.tar.gz: c474429545bc4fc5600df7c69ebb346fb4443da12cf52cdfd4b2c91aaeff4650aa2706b07ea6076a8a617255d4009886efc29065c6a25879a5cf6e379a0495d0
6
+ metadata.gz: ae5bb559b00b5e577bf18a91f16398abe0dca5a330806cf553764c44fbc79af499aa54cc72c1e45e7e10e82ccb7ad2707c565aae63da26bb955f34dca7412fa7
7
+ data.tar.gz: cd7b5a66c3e5592c834ce79380d28ded690e079a36e80814af27a77d1b78f1f3243c14211980a94fa5708398f70b6fb1984a5f46afddef32dca271df9b6f57e0
data/README.md CHANGED
@@ -1,29 +1,105 @@
1
1
  # Digestifier
2
2
 
3
- TODO: Write a gem description
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
- And then execute:
11
+ Don't forget to bundle:
12
12
 
13
13
  $ bundle
14
14
 
15
- Or install it yourself as:
15
+ Then, add the migrations to your app and update your database accordingly:
16
16
 
17
- $ gem install digestifier
17
+ $ rake digestifier:install:migrations db:migrate
18
18
 
19
- ## Usage
19
+ ## Configuration
20
20
 
21
- TODO: Write usage instructions here
21
+ Create an initializer that sets up both a digest and the sender address:
22
22
 
23
- ## Contributing
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.
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = 'digestifier'
4
- spec.version = '0.0.1'
4
+ spec.version = '0.0.2'
5
5
  spec.authors = ['Pat Allan']
6
6
  spec.email = ['pat@freelancing-gods.com']
7
7
  spec.summary = 'Digests as a Rails Engine'
@@ -21,9 +21,7 @@ class Digestifier::Delivery
21
21
  delegate :default_frequency, to: :digest
22
22
 
23
23
  def contents
24
- digest.contents.call.where(
25
- created_at: last_sent..Time.zone.now
26
- )
24
+ digest.contents.call(last_sent..Time.zone.now)
27
25
  end
28
26
 
29
27
  def frequency
@@ -3,6 +3,6 @@ class Digestifier::Digest
3
3
 
4
4
  def initialize
5
5
  @default_frequency = 24.hours
6
- @recipients = Proc.new { User.order(:id) }
6
+ @recipients = lambda { User.order(:id) }
7
7
  end
8
8
  end
@@ -7,7 +7,9 @@ describe 'Custom digest partials' do
7
7
  before :each do
8
8
  ActionMailer::Base.deliveries.clear
9
9
 
10
- digest.contents = lambda { Book }
10
+ digest.contents = lambda { |range|
11
+ Book.where(created_at: range).order(:created_at)
12
+ }
11
13
 
12
14
  user
13
15
  end
@@ -7,7 +7,9 @@ describe 'Delivering digests' do
7
7
  before :each do
8
8
  ActionMailer::Base.deliveries.clear
9
9
 
10
- digest.contents = lambda { Article }
10
+ digest.contents = lambda { |range|
11
+ Article.where(created_at: range).order(:created_at)
12
+ }
11
13
 
12
14
  user
13
15
  end
@@ -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 { Article }
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: digestifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan