class Hanami::Mailer::Rendering::TemplatesFinder
Find templates for a mailer
@api private @since 0.1.0
@see Mailer::Template
Constants
- ENGINES
Default template engines
@api private @since 0.1.0
- FORMAT
Default format
@api private @since 0.1.0
- RECURSIVE
Recursive pattern
@api private @since 0.1.0
Public Class Methods
Initialize a finder
@param mailer [Class] the mailer class
@api private @since 0.1.0
# File lib/hanami/mailer/rendering/templates_finder.rb, line 39 def initialize(mailer) @mailer = mailer end
Public Instance Methods
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
@return [Hash] the templates
@api private @since 0.1.0
@see Hanami::Mailer::Dsl#root @see Hanami::Mailer::Dsl#templates
@example
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">]
# 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
Protected Instance Methods
@api private @since 0.1.0
# File lib/hanami/mailer/rendering/templates_finder.rb, line 87 def _find(lookup = search_path) Dir.glob("#{[root, lookup, template_name].join(separator)}.#{format}.#{engines}") end
@api private @since 0.1.0
# File lib/hanami/mailer/rendering/templates_finder.rb, line 129 def engines ENGINES end
@api private @since 0.1.0
# File lib/hanami/mailer/rendering/templates_finder.rb, line 123 def format FORMAT end
@api private @since 0.1.0
# File lib/hanami/mailer/rendering/templates_finder.rb, line 111 def recursive RECURSIVE end
@api private @since 0.1.0
# File lib/hanami/mailer/rendering/templates_finder.rb, line 99 def root @mailer.configuration.root end
@api private @since 0.1.0
# File lib/hanami/mailer/rendering/templates_finder.rb, line 105 def search_path recursive end
@api private @since 0.1.0
# File lib/hanami/mailer/rendering/templates_finder.rb, line 117 def separator ::File::SEPARATOR end
@api private @since 0.1.0
# File lib/hanami/mailer/rendering/templates_finder.rb, line 93 def template_name Rendering::TemplateName.new(@mailer.template, @mailer.configuration.namespace).to_s end