Sha256: 337c26b7cea09d85ec6bb0fa2f031872094f98e28b8e7eb33aa101071f1ea1f7

Contents?: true

Size: 980 Bytes

Versions: 5

Compression:

Stored size: 980 Bytes

Contents

# frozen_string_literal: true

module Mail
  module Notify
    module MailersController
      def preview
        @email_action = File.basename(params[:path])
        return super unless @preview.email_exists?(@email_action)

        @email = @preview.call(@email_action, params)

        return super unless notify?

        return render_part if params[:part]

        render_preview_wrapper
      end

      private

      def render_part
        # Add the current directory to the view path so that Rails can find
        # the `govuk_notify_layout` layout
        append_view_path(__dir__)

        response.content_type = "text/html"
        render html: @email.preview.html.html_safe, layout: "govuk_notify_layout"
      end

      def render_preview_wrapper
        @part = @email
        render action: "email", layout: false, formats: %i[html]
      end

      def notify?
        @email.delivery_method.class == Mail::Notify::DeliveryMethod
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mail-notify-1.0.5 lib/mail/notify/mailers_controller.rb
mail-notify-1.0.4 lib/mail/notify/mailers_controller.rb
mail-notify-1.0.3 lib/mail/notify/mailers_controller.rb
mail-notify-1.0.2 lib/mail/notify/mailers_controller.rb
mail-notify-1.0.1 lib/mail/notify/mailers_controller.rb