Class: Jets::MailersController

Inherits:
Controller::Base show all
Defined in:
lib/jets/internal/app/controllers/jets/mailers_controller.rb

Overview

:nodoc:

Constant Summary

Constants included from Router::Helpers::CoreHelper

Router::Helpers::CoreHelper::CONTROLLER_DELEGATES

Instance Attribute Summary

Attributes inherited from Controller::Base

#request, #response, #session

Attributes inherited from Lambda::Functions

#context, #event, #meth

Instance Method Summary collapse

Methods inherited from Controller::Base

#action_name, #controller_name, #controller_paths, #dispatch!, #event_log, helper_method, #initialize, internal, #json_dump, #log_finish, #log_start, process, #process!

Methods included from Controller::Rendering

#actual_host, #add_stage_name, #adjust_content_type!, #default_layout, #ensure_render, #managed_options, #normalize_options, #render, #url_for

Methods included from Controller::Redirection

#ensure_protocol, #redirect_back, #redirect_to

Methods included from Controller::Params

#body_params, #filtered_parameters, #params, #path_params, #query_params, #request_params, #unescape_recursively

Methods included from Router::Helpers::NamedRoutesHelper

clear!

Methods included from Router::Helpers::CoreHelper

#polymorphic_path

Methods included from Controller::ForgeryProtection

#verify_authenticity_token

Methods included from Controller::Cookies

#cookies

Methods inherited from Lambda::Functions

inherited, #initialize, output_keys, subclasses

Methods included from Lambda::Dsl

#lambda_functions

Constructor Details

This class inherits a constructor from Jets::Controller::Base

Instance Method Details

#indexObject

TODO: content_security_policy content_security_policy(false)



15
16
17
18
# File 'lib/jets/internal/app/controllers/jets/mailers_controller.rb', line 15

def index
  @previews = ActionMailer::Preview.all
  @page_title = "Mailer Previews"
end

#previewObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/jets/internal/app/controllers/jets/mailers_controller.rb', line 20

def preview
  if params[:path] == @preview.preview_name
    @page_title = "Mailer Previews for #{@preview.preview_name}"
    render :mailer
  else
    @email_action = File.basename(params[:path])

    if @preview.email_exists?(@email_action)
      @email = @preview.call(@email_action, params)

      if params[:part]
        part_type = Mime::Type.lookup(params[:part])

        if part = find_part(part_type)
          response.headers["Content-Type"] = params[:part]
          render plain: part.respond_to?(:decoded) ? part.decoded : part
        else
          raise AbstractController::ActionNotFound, "Email part '#{part_type}' not found in #{@preview.name}##{@email_action}"
        end
      else
        @part = find_preferred_part(Mime[:html], Mime[:text])
        render :email, layout: false, formats: %w[html]
      end
    else
      raise AbstractController::ActionNotFound, "Email '#{@email_action}' not found in #{@preview.name}"
    end
  end
end