Module: EffectiveActsAsEmailFormHelper

Defined in:
app/helpers/effective_acts_as_email_form_helper.rb

Instance Method Summary collapse

Instance Method Details

#email_form_fields(form, action = nil, skip: true, to: nil, variables: nil, partial: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/effective_acts_as_email_form_helper.rb', line 5

def email_form_fields(form, action = nil, skip: true, to: nil, variables: nil, partial: nil)
  raise('expected a form') unless form.respond_to?(:object)

  resource = form.object

  # Intended for acts_as_email_form but sometimes we use a duck typed object to save these fields as well
  unless resource.class.respond_to?(:acts_as_email_form?) || resource.respond_to?("email_form_action=")
    raise('expected an acts_as_email_form resource or one that responds to email_form_action') 
  end

  # Load the template.
  email_template = if action.present? && defined?(EffectiveEmailTemplates)
    action.kind_of?(Effective::EmailTemplate) ? action : Effective::EmailTemplate.where(template_name: action).first!
  end

  # These defaults are only used when there is no email_template
  email_defaults = form.object.email_form_defaults(action) unless email_template.present?

  locals = {
    form: form,
    email_to: to,
    email_skip: skip,
    email_action: (action || true),
    email_defaults: email_defaults,
    email_template: email_template,
    email_variables: variables
  }

  render(partial: (partial || 'effective/acts_as_email_form/fields'), locals: locals)
end

#mailer_froms_collection(froms: nil) ⇒ Object



36
37
38
39
40
41
42
43
# File 'app/helpers/effective_acts_as_email_form_helper.rb', line 36

def mailer_froms_collection(froms: nil)
  froms ||= EffectiveResources.mailer_froms

  froms.map do |from|
    html = (:span, escape_once(from))
    [from, from, 'data-html': html]
  end
end