Skip to content

Commit

Permalink
Checking in - working on mailer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Neufeld committed Jul 1, 2009
1 parent b851481 commit 01d185a
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 14 deletions.
12 changes: 6 additions & 6 deletions app/models/freemailer.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
class Freemailer < ActionMailer::Base


def from_template(sent_at = Time.now)
subject 'Freemailer#from_template'
recipients ''
from ''
def from_template(campaign, contact, sent_at = Time.now)
subject campaign.subject
recipients contact.primary_email
from campaign.from
sent_on sent_at
body :greeting => 'Hi,'

body campaign.fill_template_for_contact(contact)
end

end
24 changes: 21 additions & 3 deletions app/models/freemailer_campaign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def contact_names
contacts.map(&:name_for_display).join(', ').squeeze(' ')
end

def contact_emails
self[:contacts].map(&:primary_email)
end

def status
if sent
'Sent'
Expand All @@ -25,9 +29,9 @@ def make_active_for_sender
end

def preview

fill_template(preview_user)
end

private

def preview_user
Expand All @@ -41,9 +45,23 @@ def preview_user
}
end

def fill_template_for_contact(person)
fill_template ({
'first name' => person.first_name,
'last name' => person.last_name,
'middle name' => person.middle_name,
'middle initial' => person.middle_name.first.upcase,
'name' => person.name_for_display,
'email' => person.primary_email,
'address' => person.primary_address
})
end

def fill_template(user_hash)
user_hash.default = ''
body_template.gsub /\{(.*)\}/, user_hash[$1].to_s
body_template.gsub(/\{(.*)\}/) do |item|
user_hash[$1].to_s
end
end

def remove_active_campaign
Expand Down
4 changes: 4 additions & 0 deletions app/views/freemailer_campaigns/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
Contacts:
%br
= @freemailer_campaign.contact_names
%p
= f.label :from
%br
= f.text_field :from
%p
= f.label :subject
%br
Expand Down
8 changes: 6 additions & 2 deletions app/views/freemailer_campaigns/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
Your Mailing Campaigns
%h2
Active Campaign
%p Lorem ipsum dolor sit amet, consectetur magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
%table
%tr
%th Subject
%th Title
%th Contacts
%th From
%th Body template
%th Status
- @freemailer_campaigns.each do |freemailer_campaign|
Expand All @@ -16,11 +18,13 @@
%td
= h freemailer_campaign.title
%td
== (#{freemailer_campaign.contacts.count}) #{freemailer_campaign.contact_names}
== (#{freemailer_campaign.contacts.count}) #{h freemailer_campaign.contact_names}
%td
= h freemailer_campaign.from
%td
- if freemailer_campaign.body_template
= h freemailer_campaign.body_template[0..75]
%td
%td
- if freemailer_campaign.sent
Sent
- else
Expand Down
4 changes: 4 additions & 0 deletions app/views/freemailer_campaigns/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
%b
Contacts:
= h @freemailer_campaign.contact_names
%p
%b
From:
= h @freemailer_campaign.from
%p
%b
Subject:
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20090701134557_add_from_to_freemailer_campaign.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddFromToFreemailerCampaign < ActiveRecord::Migration
def self.up
add_column :freemailer_campaigns, :from, :string
end

def self.down
remove_column :freemailer_campaigns, :from
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20090625174247) do
ActiveRecord::Schema.define(:version => 20090701134557) do

create_table "contact_addresses", :force => true do |t|
t.integer "contact_id", :null => false
Expand Down Expand Up @@ -103,6 +103,7 @@
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "sent", :default => false
t.string "from"
end

create_table "log_items", :force => true do |t|
Expand Down
3 changes: 1 addition & 2 deletions spec/models/freemailer_campaign_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
campaign.stub!(:contacts).and_return do
[ Contact.new( :first_name => 'that', :last_name => 'guy' ),
Contact.new( :first_name => 'this', :last_name => 'guy' )]

end
campaign.contact_names.should == "that guy, this guy"
end
Expand All @@ -50,7 +49,7 @@
Doe!
John Doe
123 Some Pl.
Where, Ever 90120
Where, Ever 90210
Canada
EOS
end
Expand Down

0 comments on commit 01d185a

Please sign in to comment.