Class: Hanami::Mailer::Rendering::TemplatesFinder Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/mailer/rendering/templates_finder.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.

Find templates for a mailer

See Also:

Since:

  • 0.1.0

Constant Summary collapse

FORMAT =

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

Default format

Since:

  • 0.1.0

"*"
ENGINES =

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

Default template engines

Since:

  • 0.1.0

"*"
RECURSIVE =

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

Recursive pattern

Since:

  • 0.1.0

"**"

Instance Method Summary collapse

Constructor Details

#initialize(mailer) ⇒ TemplatesFinder

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.

Initialize a finder

Parameters:

  • mailer (Class)

    the mailer class

Since:

  • 0.1.0



39
40
41
# File 'lib/hanami/mailer/rendering/templates_finder.rb', line 39

def initialize(mailer)
  @mailer = mailer
end

Instance Method Details

#findHash

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.

Find all the associated templates to the mailer. It recursively looks for templates under the root path of the mailer, that are matching the template name

Examples:

require 'hanami/mailer'

module Mailers
  class Welcome
    include Hanami::Mailer
  end
end

Mailers::Welcome.root     # => "/path/to/templates"
Mailers::Welcome.templates # => {[:html] => "welcome"}

# This mailer has a template:
#
#   "/path/to/templates/welcome.html.erb"

Hanami::Mailer::Rendering::TemplatesFinder.new(Mailers::Welcome).find
  # => [#<Hanami::Mailer::Template:0x007f8a0a86a970 ... @file="/path/to/templates/welcome.html.erb">]

Returns:

  • (Hash)

    the templates

See Also:

Since:

  • 0.1.0



73
74
75
76
77
78
79
80
81
# File 'lib/hanami/mailer/rendering/templates_finder.rb', line 73

def find
  templates = Hash[]
  _find.map do |template|
    name = File.basename(template)
    format = (name.split(".")[-2]).to_sym
    templates[format] = Mailer::Template.new(template)
  end
  templates
end