Created
June 21, 2011 15:17
-
-
Save codeincontext/1038072 to your computer and use it in GitHub Desktop.
A script to generate all of our ActionMailer emails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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, "[email protected]" | |
generate :password_reset_message, User.last | |
generate :following_notification, Following.last | |
generate :email_change_message, User.last, '[email protected]' | |
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