Sha256: de33c93b72c246c0e6d8b7dc1076f03e9ba96990248623ee8175c5ced82fddf6

Contents?: true

Size: 833 Bytes

Versions: 10

Compression:

Stored size: 833 Bytes

Contents

module Effective
  class EmailTemplatesMailer < ::ActionMailer::Base

    def mail(headers = {}, &block)
      email_template = Effective::EmailTemplate.where(template_name: action_name).first!

      # Parse Assigns. :body is a special key
      assigns = (@assigns || {})

      if (body = assigns.delete(:body))
        email_template.body = body
      end

      assigns = route_url_assigns(email_template).merge(assigns)

      # Render from the template, possibly with updated body
      rendered = email_template.render(assigns)

      super(rendered.merge(headers))
    end

    private

    def route_url_assigns(email_template)
      email_template.template_variables.select { |name| name.ends_with?('_url') }.inject({}) do |h, name|
        h[name] = public_send(name) if respond_to?(name); h
      end
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
effective_email_templates-1.0.12 app/mailers/effective/email_templates_mailer.rb
effective_email_templates-1.0.11 app/mailers/effective/email_templates_mailer.rb
effective_email_templates-1.0.10 app/mailers/effective/email_templates_mailer.rb
effective_email_templates-1.0.9 app/mailers/effective/email_templates_mailer.rb
effective_email_templates-1.0.8 app/mailers/effective/email_templates_mailer.rb
effective_email_templates-1.0.7 app/mailers/effective/email_templates_mailer.rb
effective_email_templates-1.0.6 app/mailers/effective/email_templates_mailer.rb
effective_email_templates-1.0.5 app/mailers/effective/email_templates_mailer.rb
effective_email_templates-1.0.4 app/mailers/effective/email_templates_mailer.rb
effective_email_templates-1.0.3 app/mailers/effective/email_templates_mailer.rb