Skip to content

Instantly share code, notes, and snippets.

@codeincontext
Created June 21, 2011 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeincontext/1038072 to your computer and use it in GitHub Desktop.
Save codeincontext/1038072 to your computer and use it in GitHub Desktop.
A script to generate all of our ActionMailer emails
# rails runner lib/mail_generator.rb
OUTPUT_DIR = 'mail_examples'
`rm -rf #{OUTPUT_DIR}/`
`mkdir #{OUTPUT_DIR}/`
@methods = UserMailer.instance_methods(false).map(&:to_sym)
def generate(method, *params)
mail = UserMailer.send(method, *params)
parts = {}
parts['html'] = mail.html_part if mail.html_part
parts['txt'] = mail.text_part if mail.text_part
parts.each_pair do |type, part|
path = "#{OUTPUT_DIR}/#{method}.#{type}"
File.open(path, 'w') {|f| f.write(part.body.decoded) }
`open #{path}`
end
@methods.delete(method)
end
generate :creation_message, User.last
generate :clip_featured_notification, AudioClip.last
generate :username_change_message, User.last, 'monkey'
generate :comment_notification, User.last, Comment.last
generate :messaging_invitation, User.last, "james@audioboo.fm"
generate :password_reset_message, User.last
generate :following_notification, Following.last
generate :email_change_message, User.last, 'frog@monkey.info'
generate :message_notification, User.last, Message.last
generate :api_approval_notification, User.last, Service.last
puts "Methods not generated: " + @methods.join(', ') unless @methods.empty?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment