Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Commit

Permalink
Both html & plain text emails are sent from markdown templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Kel4545 committed Apr 15, 2015
1 parent 35f8131 commit 86c1c2a
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 52 deletions.
6 changes: 6 additions & 0 deletions app/helpers/mailer_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module MailerHelper

def md_link_to(name, path)
"[#{name}](#{path})"
end
end
11 changes: 11 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class ApplicationMailer < ActionMailer::Base
helper MailerHelper

def mail_markdown(options)
mail options do |format|
markdown_string = render_to_string(action_name, formats: :md)
format.text { render text: markdown_string}
format.html { render text: Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(markdown_string)}
end
end
end
4 changes: 2 additions & 2 deletions app/mailers/comment_notification_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CommentNotificationMailer < ActionMailer::Base
class CommentNotificationMailer < ApplicationMailer
def email_notification(comment)
@comment = comment

Expand All @@ -10,7 +10,7 @@ def email_notification(comment)
end.compact

if bcc.any?
mail(bcc: bcc,
mail_markdown(bcc: bcc,
from: @comment.proposal.event.contact_email,
subject: "A comment has been posted")
end
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/invitation_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class InvitationMailer < ActionMailer::Base
class InvitationMailer < ApplicationMailer

def speaker(invitation, speaker)
@invitation = invitation
@proposal = invitation.proposal
@speaker = speaker

mail(to: @invitation.email, from: @proposal.event.contact_email, subject: "You've been invited to join the \"#{@proposal.title}\" proposal for #{@proposal.event}")
mail_markdown(to: @invitation.email, from: @proposal.event.contact_email, subject: "You've been invited to join the \"#{@proposal.title}\" proposal for #{@proposal.event}")
end
end
10 changes: 6 additions & 4 deletions app/mailers/participant_invitation_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
class ParticipantInvitationMailer < ActionMailer::Base
class ParticipantInvitationMailer < ApplicationMailer

def create(participant_invitation)
@participant_invitation = participant_invitation
@event = participant_invitation.event

mail to: participant_invitation.email,
from: @event.contact_email,
subject: "You've been invited to participate in a CFP"
mail_markdown to: participant_invitation.email,
from: @event.contact_email,
subject: "You've been invited to participate in a CFP"
end
end

4 changes: 2 additions & 2 deletions app/mailers/proposal_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ProposalMailer < ActionMailer::Base
class ProposalMailer < ApplicationMailer
def comment_notification(proposal, comment)
@proposal = proposal
@comment = comment
Expand All @@ -8,7 +8,7 @@ def comment_notification(proposal, comment)
end

if bcc.any?
mail(bcc: bcc,
mail_markdown(bcc: bcc,
from: @proposal.event.contact_email,
subject: "You've received a comment on your proposal '#{@proposal.title}'")
end
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Hello!
<%= @comment.person.name %> has left a comment on the proposal '<%= @comment.proposal.title %>' for <%= @comment.proposal.event.name %>:

> <%= simple_format(@comment.body) %>

<%= md_link_to 'View the proposal', proposal_url(slug: @comment.proposal.event.slug, uuid: @comment.proposal) %>
6 changes: 0 additions & 6 deletions app/views/invitation_mailer/speaker.html.haml

This file was deleted.

6 changes: 6 additions & 0 deletions app/views/invitation_mailer/speaker.md.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Hello!

<%= @speaker.name %> <%= @speaker.email %> has invited you as a speaker on the proposal <%= @proposal.title %> for <%= @proposal.event %>.

You can accept or refuse this invitation by visiting <% md_link_to 'the proposal page', invitation_url(invitation_slug: @invitation.slug) %>.

21 changes: 0 additions & 21 deletions app/views/participant_invitation_mailer/create.html.haml

This file was deleted.

17 changes: 17 additions & 0 deletions app/views/participant_invitation_mailer/create.md.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Hi there!

You've been invited to participate in a Call for Proposals for the event
<%= @participant_invitation.event %> as the role <%= @participant_invitation.role %>.

<%= md_link_to 'Click here to accept.',
accept_participant_invitation_url(@participant_invitation.slug,
@participant_invitation.token) %>
You'll be prompted to create an account if you don't already have one.

<%= md_link_to 'Click here to decline.',
refuse_participant_invitation_url(@participant_invitation.slug,
@participant_invitation.token) %>

You can view the event <%= md_link_to 'here', event_url(@event.slug) %>.

The <%= @event.name %> Program Committee
8 changes: 0 additions & 8 deletions app/views/proposal_mailer/comment_notification.html.haml

This file was deleted.

7 changes: 7 additions & 0 deletions app/views/proposal_mailer/comment_notification.md.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<%= @comment.person.name %> has left a comment on your proposal <%= @proposal.title %> for <%= @proposal.event.name %>:

> <%= simple_format(@comment.body) %>

<%= md_link_to 'View your proposal', proposal_url(slug: @proposal.event.slug, uuid: @proposal) %>


5 changes: 5 additions & 0 deletions test/mailers/previews/invitation_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class InvitationPreview < ActionMailer::Preview
def create
ParticipantInvitationMailer.create(ParticipantInvitation.first)
end
end

0 comments on commit 86c1c2a

Please sign in to comment.