Sha256: 7455e4bc3f85f96c35d0c0df7498076860a02972de8825657ac1ee6a35d88eb0

Contents?: true

Size: 866 Bytes

Versions: 1

Compression:

Stored size: 866 Bytes

Contents

module Mjml
  module Mailer
    def mail(headers, &block)
      scope = Mjml::Scope.new(self, headers[:template_variables])
      content = _layout ? mjml_layout_content(headers, scope) : mjml_template_content(headers, scope)

      headers[:body] = Mjml.template(content)
      headers[:content_type] = "text/html"

      super(headers, &block)
    end

    def mjml_layout_content(headers, scope)
      erb_layout = Tilt::ERBTemplate.new("#{Dir.pwd}/app/views/layouts/#{_layout}.mjml")
      erb_template = Tilt::ERBTemplate.new("#{headers[:template_path]}/#{headers[:template_name]}.mjml")
      erb_layout.render(scope) { erb_template.render(scope) }
    end

    def mjml_template_content(headers, scope)
      erb_template = Tilt::ERBTemplate.new("#{headers[:template_path]}/#{headers[:template_name]}.mjml")
      erb_template.render(scope)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mjml-0.0.4 lib/mjml/mailer.rb