Module: Card::Set::Type::EmailTemplate::EmailConfig
- Extended by:
- Card::Set
- Defined in:
- platypus/tmp/set/gem-defaults/mod012-email/type/email_template/email_config.rb
Overview
Set: All “EmailTemplate+EmailConfig” cards (EmailConfig)
Constant Summary collapse
- EMAIL_FIELDS =
%i[to from cc bcc attach subject text_message html_message].freeze
- EMAIL_FIELD_METHODS =
{ subject: :contextual_content, text_message: :contextual_content, attach: :recursed_item_contents }.freeze
Constants included from Helpers
Helpers::SET_PATTERN_TEST_REGEXP
Constants included from Event::Api
Class Method Summary collapse
Instance Method Summary collapse
-
#configured_from_name_and_email(raw_string) ⇒ Object
-
#email_config(context, fields = {}, opts = {}) ⇒ Object
-
#email_field_from_card(field, auth, format_opts) ⇒ Object
-
#email_from_field_value(conf_name, conf_email, actual_email) ⇒ Object
-
#email_html_message_field(message_card, auth, format_opts) ⇒ Object
html messages return procs because image attachments can’t be properly rendered without a mail object.
-
#safe_from_and_reply_to!(config) ⇒ Object
whenever a default “from” field is configured in Card::Mailer, emails are always actually “from” that address.
-
#special_email_field_method(field, field_card, auth, format_opts) ⇒ Object
-
#standard_email_field(field, field_card, auth, format_opts) ⇒ Object
Methods included from Card::Set
Methods included from I18nScope
Methods included from Registrar
#extended, #finalize_load, #process_base_modules, #register_set
Methods included from Helpers
#format_module, #format_modules, #method_missing, #modules, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscored_name
Methods included from AdvancedApi
#assign_type, #attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method
Methods included from Format
#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name
Methods included from Inheritance
#include_set, #include_set_formats
Methods included from Card::Set::Trait
#card_accessor, #card_reader, #card_writer, #require_field
Methods included from Event::Api
Class Method Details
.source_location ⇒ Object
7 |
# File 'platypus/tmp/set/gem-defaults/mod012-email/type/email_template/email_config.rb', line 7 def self.source_location; "/Users/ethan/dev/decko/gem/mod/email/set/type/email_template/email_config.rb"; end |
Instance Method Details
#configured_from_name_and_email(raw_string) ⇒ Object
84 85 86 87 88 89 90 |
# File 'platypus/tmp/set/gem-defaults/mod012-email/type/email_template/email_config.rb', line 84 def configured_from_name_and_email raw_string if raw_string =~ /(.*)<(.*)>/ [Regexp.last_match(1).strip, Regexp.last_match(2)] else [nil, raw_string] end end |
#email_config(context, fields = {}, opts = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'platypus/tmp/set/gem-defaults/mod012-email/type/email_template/email_config.rb', line 20 def email_config context, fields={}, opts={} @active_email_context = context || self auth = opts.delete :auth config = EMAIL_FIELDS.each_with_object({}) do |field, conf| conf[field] = fields[field] || email_field_from_card(field, auth, opts) end safe_from_and_reply_to! config config.select { |_k, v| v.present? } end |
#email_field_from_card(field, auth, format_opts) ⇒ Object
30 31 32 33 34 35 36 |
# File 'platypus/tmp/set/gem-defaults/mod012-email/type/email_template/email_config.rb', line 30 def email_field_from_card field, auth, format_opts return unless (field_card = fetch(field)) auth ||= field_card.updater special_email_field_method(field, field_card, auth, format_opts) || standard_email_field(field, field_card, auth, format_opts) end |
#email_from_field_value(conf_name, conf_email, actual_email) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'platypus/tmp/set/gem-defaults/mod012-email/type/email_template/email_config.rb', line 73 def email_from_field_value conf_name, conf_email, actual_email conf_text = conf_name || conf_email if conf_text != actual_email %("#{conf_text}" <#{actual_email}>) elsif actual_email.present? actual_email else Card[WagnBotID].account.email end end |
#email_html_message_field(message_card, auth, format_opts) ⇒ Object
html messages return procs because image attachments can’t be properly rendered without a mail object. (which isn’t available at initial config time)
55 56 57 58 59 60 61 62 |
# File 'platypus/tmp/set/gem-defaults/mod012-email/type/email_template/email_config.rb', line 55 def , auth, format_opts proc do |mail| Auth.as auth do format_opts = format_opts.merge format: :email_html, active_mail: mail .format(format_opts).email_content @active_email_context end end end |
#safe_from_and_reply_to!(config) ⇒ Object
whenever a default “from” field is configured in Card::Mailer, emails are always actually “from” that address
66 67 68 69 70 71 |
# File 'platypus/tmp/set/gem-defaults/mod012-email/type/email_template/email_config.rb', line 66 def safe_from_and_reply_to! config conf_name, conf_email = configured_from_name_and_email config[:from] actual_email = Card::Mailer.default[:from] || conf_email config[:from] = email_from_field_value conf_name, conf_email, actual_email config[:reply_to] ||= actual_email end |
#special_email_field_method(field, field_card, auth, format_opts) ⇒ Object
38 39 40 41 42 43 |
# File 'platypus/tmp/set/gem-defaults/mod012-email/type/email_template/email_config.rb', line 38 def special_email_field_method field, field_card, auth, format_opts method = "email_#{field}_field" return unless respond_to? method send method, field_card, auth, format_opts end |
#standard_email_field(field, field_card, auth, format_opts) ⇒ Object
45 46 47 48 49 50 51 |
# File 'platypus/tmp/set/gem-defaults/mod012-email/type/email_template/email_config.rb', line 45 def standard_email_field field, field_card, auth, format_opts method = EMAIL_FIELD_METHODS[field] || :email_addresses format_opts = format_opts.merge format: :email_text Auth.as auth do field_card.format(format_opts).send method, @active_email_context end end |