Class: Html2Email
- Inherits:
-
Object
- Object
- Html2Email
- Defined in:
- lib/html2email.rb
Overview
Command line wrapper for creating and writing HtmlEmail objects
Constant Summary collapse
- VERSION =
'0.1.4'
Instance Method Summary collapse
-
#initialize(args = []) ⇒ Html2Email
constructor
A new instance of Html2Email.
- #options ⇒ Object
-
#run ⇒ Object
Command line interface.
Constructor Details
#initialize(args = []) ⇒ Html2Email
Returns a new instance of Html2Email.
12 13 14 |
# File 'lib/html2email.rb', line 12 def initialize(args = []) @args, @options = args, { :default_type => 'str', :test_recipients => [] } end |
Instance Method Details
#options ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/html2email.rb', line 16 def OptionParser.new do |opt| opt. = %Q{\ Convert an html file to an email-compatible form. Usage: #{File.basename $0} [options] [infile[:outfile], ...] Options: }.gsub(/^ +/,'') opt.on('-l', '--layout FILE', 'Use FILE as a layout template') do |arg| @options[:layout] = File. arg end types = Tilt.mappings.keys opt.on('-t', '--default-type FORMAT', 'Fall back to FORMAT when template type cannot be inferred from', "a file's extension, e.g. input from STDIN. " + "Defaults to `#{@options[:default_type]}'") do |arg| if types.include? arg @options[:default_type] = arg else raise ArgumentError, "Default type must be one of: #{types.join ', '}" end end opt.on('-e', '--email [ADDR,ADDR]', Array, 'Send rendered html to recipients; list can also be defined', 'within the template') do |arg| @options[:email_test] = true @options[:test_recipients] = arg || [] end opt.on('--stdout', 'Write to STDOUT when an outfile is not explicitly specified') do @options[:stdout] = true end opt.separator "\nSupported FORMATs:\n#{types.join ', '}" end end |
#run ⇒ Object
Command line interface
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/html2email.rb', line 59 def run .parse! @args = [] process(@args).each do |infile, outfile| htmlemail = HtmlEmail.new infile, @options[:layout], @options write (html = htmlemail.render), outfile << html @options[:test_recipients] += htmlemail.test_recipients end if @options[:email_test] HtmlMailer.new(, @options[:test_recipients].uniq).html_send end ensure FileUtils.rm_f(@tempfile) if @tempfile end |