Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 390
- Log:
Initial import of Canvass, a donations-based poll application.
- Author:
- rool
- Date:
- Mon Mar 21 14:58:04 +0000 2011
- Size:
- 2433 Bytes
1 | ######################################################################## |
2 | # File:: canvass_mailer.rb |
3 | # (C):: Hipposoft 2011 |
4 | # |
5 | # Purpose:: Send e-mail messages for important events. |
6 | # ---------------------------------------------------------------------- |
7 | # 21-Feb-2011 (ADH): Created. Based upon Artisan Mailer. |
8 | ######################################################################## |
9 | |
10 | class CanvassMailer < BaseMailer |
11 | |
12 | helper :application, :currencies |
13 | |
14 | # Called via deliver_... when wanting to send a new donation confirmation |
15 | # message to a donor. Pass the donation of interest. |
16 | # |
17 | def new_donation_made( donation ) |
18 | setup_mail( |
19 | donation.user_email, |
20 | donation, |
21 | :new_donation_made |
22 | ) |
23 | end |
24 | |
25 | # Called via deliver_... when wanting to send a new donation notification |
26 | # message to an administrator. Pass the donation of interest. |
27 | # |
28 | def new_donation_made_admin( donation ) |
29 | setup_mail( |
30 | ADMINISTRATOR_EMAIL_ADDRESS, # config/initializers/50_general_settings.rb |
31 | donation, |
32 | :new_donation_made_admin |
33 | ) |
34 | end |
35 | |
36 | private |
37 | |
38 | # Configure default email options and render the message template. Pass a |
39 | # recipient e-mail address, data to be passed into the view template under |
40 | # instance variable "@data", the key to look up for the subject line and to |
41 | # use as the base of the template leafname and an optional parameter passed |
42 | # in to the translator when the subject line is looked up - this should be a |
43 | # hash corresponding to the substitution parameters expected by the caller |
44 | # for the message the key passed in the third parameter selects. |
45 | # |
46 | def setup_mail( recipient, data, key, translation_data = {} ) |
47 | subject "[#{ self.class.site_name }] #{ translate( key, translation_data ) }" |
48 | from NOTIFICATION_EMAILS_COME_FROM # config/initializers/50_general_settings.rb |
49 | recipients recipient |
50 | sent_on Time.now |
51 | content_type 'text/plain' |
52 | body render( |
53 | :file => "canvass_mailer/#{ key }.txt.erb", |
54 | :body => { :data => data } |
55 | ) |
56 | end |
57 | |
58 | # Translate a given key, using that key as the default string. Pass also |
59 | # an optional translation data hash to use for substitutions. |
60 | # |
61 | def translate( key, translation_data = {} ) |
62 | I18n.t( |
63 | "uk.org.pond.canvass.canvass_mailer.#{ key }", |
64 | translation_data.merge!( :default => key ) |
65 | ) |
66 | end |
67 | end |