Class: Hanami::Mailer::ViewIntegration::DefaultViewBuilder Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/mailer/view_integration.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Builder class for constructing default views. Keeps view building logic separate from mailer instances.

Class Method Summary collapse

Class Method Details

.call(mailer_class) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Builds a default view from exposures if Hanami::View is available.



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/hanami/mailer/view_integration.rb', line 117

def call(mailer_class)
  view_class = mailer_class.config.view_class || Hanami::View

  # A view needs paths to find its templates. These may be configured on the mailer, or
  # inherited from an already-configured `view_class` (e.g. within a Hanami app).
  paths = mailer_class.config.paths
  if (paths.nil? || paths.empty?) && view_class.respond_to?(:config)
    paths = view_class.config.paths
  end
  return nil if paths.nil? || paths.empty?

  template = mailer_class.config.template
  template ||= inferred_template(mailer_class)

  build_view_class(
    view_class: view_class,
    template: template,
    exposures: mailer_class.exposures,
    config: mailer_class.config
  )
end