Module: Card::Set::Type::EmailTemplate::Format
- Extended by:
- AbstractFormat
- Defined in:
- platypus/tmp/set/gem-defaults/mod012-email/type/email_template.rb
Instance Method Summary collapse
-
#add_attachments(mail, list) ⇒ Object
-
#attachment_name(file, number) ⇒ Object
-
#body_method_and_args(html, text) ⇒ Object
-
#each_valid_attachment(list) ⇒ Object
-
#html_body(mail, message) ⇒ Object
-
#mail(context = nil, fields = {}, opts = {}) ⇒ Object
-
#message_body(mail, config) ⇒ Object
-
#multipart_mixed(mail, text_message, html_message) ⇒ Object
-
#text_and_html_message(mail, text_message, html_message, attachment_list = nil) ⇒ Object
-
#text_body(mail, message) ⇒ Object
Instance Method Details
#add_attachments(mail, list) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'platypus/tmp/set/gem-defaults/mod012-email/type/email_template.rb', line 79 def mail, list return unless list.present? list do |file, index| mail.add_file filename: (file, index), content: File.read(file.path) end end |
#attachment_name(file, number) ⇒ Object
96 97 98 |
# File 'platypus/tmp/set/gem-defaults/mod012-email/type/email_template.rb', line 96 def file, number "attachment-#{number + 1}.#{file.extension}" end |
#body_method_and_args(html, text) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'platypus/tmp/set/gem-defaults/mod012-email/type/email_template.rb', line 37 def body_method_and_args html, text if html && text [:text_and_html_message, %i[text_message html_message attach]] elsif html %i[html_body html_message] else %i[text_body text_message] end end |
#each_valid_attachment(list) ⇒ Object
88 89 90 91 92 93 94 |
# File 'platypus/tmp/set/gem-defaults/mod012-email/type/email_template.rb', line 88 def list list.each_with_index do |cardname, index| next unless (file = Card[cardname]&.try(:attachment)) yield file, index end end |
#html_body(mail, message) ⇒ Object
69 70 71 72 |
# File 'platypus/tmp/set/gem-defaults/mod012-email/type/email_template.rb', line 69 def html_body mail, mail.content_type "text/html; charset=UTF-8" mail.body end |
#mail(context = nil, fields = {}, opts = {}) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'platypus/tmp/set/gem-defaults/mod012-email/type/email_template.rb', line 20 def mail context=nil, fields={}, opts={} config = card.email_config context, fields, opts fmt = self # self is <Mail::Message> within the new_mail block Card::Mailer.new_mail config do fmt. self, config fmt. self, config.delete(:attach) end end |
#message_body(mail, config) ⇒ Object
29 30 31 32 33 34 35 |
# File 'platypus/tmp/set/gem-defaults/mod012-email/type/email_template.rb', line 29 def mail, config config[:html_message] &&= config[:html_message].call mail method, args = body_method_and_args config[:html_message].present?, config[:text_message].present? args = Array.wrap(args).map { |arg| config[arg] } send method, mail, *args end |
#multipart_mixed(mail, text_message, html_message) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'platypus/tmp/set/gem-defaults/mod012-email/type/email_template.rb', line 57 def multipart_mixed mail, , mail.content_type "multipart/mixed" mail.part content_type: "multipart/alternative" do |copy| copy.part content_type: "text/plain" do |plain| plain.body = end copy.part content_type: "text/html" do |html| html.body = end end end |
#text_and_html_message(mail, text_message, html_message, attachment_list = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'platypus/tmp/set/gem-defaults/mod012-email/type/email_template.rb', line 47 def mail, , , =nil fmt = self if &.any? mail.multipart_mixed , else mail.text_part { body } mail.html_part { fmt.html_body self, } end end |
#text_body(mail, message) ⇒ Object
74 75 76 77 |
# File 'platypus/tmp/set/gem-defaults/mod012-email/type/email_template.rb', line 74 def text_body mail, mail.content_type "text/plain; charset=UTF-8" mail.text_part { body } end |