Sha256: df8baa3573e32482acf674f2793b5a0c90fe66a7655091508b84de5c2ab96004

Contents?: true

Size: 1.48 KB

Versions: 36

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

module EffectiveActsAsEmailFormHelper

  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

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

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

end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
effective_resources-2.22.2 app/helpers/effective_acts_as_email_form_helper.rb
effective_resources-2.22.1 app/helpers/effective_acts_as_email_form_helper.rb
effective_resources-2.22.0 app/helpers/effective_acts_as_email_form_helper.rb
effective_resources-2.20.5 app/helpers/effective_acts_as_email_form_helper.rb
effective_resources-2.20.4 app/helpers/effective_acts_as_email_form_helper.rb
effective_resources-2.20.3 app/helpers/effective_acts_as_email_form_helper.rb
effective_resources-2.20.2 app/helpers/effective_acts_as_email_form_helper.rb
effective_resources-2.20.1 app/helpers/effective_acts_as_email_form_helper.rb
effective_resources-2.20.0 app/helpers/effective_acts_as_email_form_helper.rb
effective_resources-2.19.13 app/helpers/effective_acts_as_email_form_helper.rb
effective_resources-2.19.12 app/helpers/effective_acts_as_email_form_helper.rb
effective_resources-2.19.11 app/helpers/effective_acts_as_email_form_helper.rb
effective_resources-2.19.10 app/helpers/effective_acts_as_email_form_helper.rb
effective_resources-2.19.9 app/helpers/effective_acts_as_email_form_helper.rb
effective_resources-2.19.8 app/helpers/effective_acts_as_email_form_helper.rb
effective_resources-2.19.7 app/helpers/effective_acts_as_email_form_helper.rb
effective_resources-2.19.6 app/helpers/effective_acts_as_email_form_helper.rb
effective_resources-2.19.5 app/helpers/effective_acts_as_email_form_helper.rb
effective_resources-2.19.4 app/helpers/effective_acts_as_email_form_helper.rb
effective_resources-2.19.3 app/helpers/effective_acts_as_email_form_helper.rb