Module: Hanami::Mailer::ViewIntegration::PrependedMethods Private

Defined in:
lib/hanami/mailer/view_integration.rb

Overview

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

Internal module for prepending view and render behavior. Wraps the base class to provide automatic view building and per-format template error handling.

Instance Method Summary collapse

Instance Method Details

#render(input, format: nil) ⇒ 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.

Renders HTML and text bodies, handling missing templates per format.



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/hanami/mailer/view_integration.rb', line 91

def render(input, format: nil)
  html, html_error = try_render(:html, input) unless format == :text
  text, text_error = try_render(:text, input) unless format == :html

  # Tolerate one missing template if attempting to render both. Otherwise, consider any
  # error as fatal.
  raise html_error if html_error && (format || text_error)
  raise text_error if text_error && format

  [html, text]
end

#try_render(format, input) ⇒ 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.



103
104
105
106
107
# File 'lib/hanami/mailer/view_integration.rb', line 103

def try_render(format, input)
  [render_view(format, input), nil]
rescue Hanami::View::TemplateNotFoundError => exception
  [nil, exception]
end

#viewObject

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.

The view used for rendering: a per-instance override passed to the constructor, falling back to the mailer class’s lazily-built, memoized default view.



86
87
88
# File 'lib/hanami/mailer/view_integration.rb', line 86

def view
  @view || self.class.default_view
end