Module: Card::Set::Type::EmailTemplate::Format
- Extended by:
- AbstractFormat
- Defined in:
- tmpsets/set/mod016-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
80 81 82 83 84 85 86 |
# File 'tmpsets/set/mod016-email/type/email_template.rb', line 80 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
95 96 97 |
# File 'tmpsets/set/mod016-email/type/email_template.rb', line 95 def file, number "attachment-#{number + 1}.#{file.extension}" end |
#body_method_and_args(html, text) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'tmpsets/set/mod016-email/type/email_template.rb', line 38 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 |
# File 'tmpsets/set/mod016-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
70 71 72 73 |
# File 'tmpsets/set/mod016-email/type/email_template.rb', line 70 def html_body mail, mail.content_type "text/html; charset=UTF-8" mail.body end |
#mail(context = nil, fields = {}, opts = {}) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'tmpsets/set/mod016-email/type/email_template.rb', line 21 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
30 31 32 33 34 35 36 |
# File 'tmpsets/set/mod016-email/type/email_template.rb', line 30 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
58 59 60 61 62 63 64 65 66 67 68 |
# File 'tmpsets/set/mod016-email/type/email_template.rb', line 58 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
48 49 50 51 52 53 54 55 56 |
# File 'tmpsets/set/mod016-email/type/email_template.rb', line 48 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
75 76 77 78 |
# File 'tmpsets/set/mod016-email/type/email_template.rb', line 75 def text_body mail, mail.content_type "text/plain; charset=UTF-8" mail.text_part { body } end |