class Lita::TemplateResolver
Finds the file path of the most appropriate template for the given adapter. @api private @since 4.2.0
Attributes
adapter_name[R]
The name of the current adapter.
template_name[R]
The name of the template to search for.
template_root[R]
The directory to search for templates.
Public Class Methods
new(template_root, template_name, adapter_name)
click to toggle source
@param template_root
[String] The directory to search for templates. @param template_name
[String] The name of the template to search for. @param adapter_name
[String, Symbol] The name of the current adapter.
# File lib/lita/template_resolver.rb, line 9 def initialize(template_root, template_name, adapter_name) @template_root = template_root @template_name = template_name @adapter_name = adapter_name end
Public Instance Methods
resolve()
click to toggle source
Returns the adapter-specific template, falling back to a generic template. @return [String] The path of the template to use. @raise [MissingTemplateError] If no templates with the given name exist.
# File lib/lita/template_resolver.rb, line 18 def resolve return adapter_template if File.exist?(adapter_template) return generic_template if File.exist?(generic_template) raise MissingTemplateError, I18n.t("lita.template.missing_template", path: generic_template) end
Private Instance Methods
adapter_template()
click to toggle source
Path to the adapter-specific template.
# File lib/lita/template_resolver.rb, line 36 def adapter_template @adapter_template ||= File.join(template_root, "#{template_name}.#{adapter_name}.erb") end
generic_template()
click to toggle source
Path to the generic template.
# File lib/lita/template_resolver.rb, line 41 def generic_template @generic_template ||= File.join(template_root, "#{template_name}.erb") end