class ActionMailer::Markdown::Resolver

Constants

FORMAT_TO_EXTENSION

Public Instance Methods

build_template(path, contents, identifier, format) click to toggle source
# File lib/action_mailer/markdown/resolver.rb, line 22
def build_template(path, contents, identifier, format)
  ActionView::Template.new(
    contents,
    identifier,
    handler_for(format),
    virtual_path: path,
    format: format,
    locals: []
  )
end
find_contents(name, prefix, details) click to toggle source
# File lib/action_mailer/markdown/resolver.rb, line 47
def find_contents(name, prefix, details)
  [details[:locale].try(:first) || I18n.locale, prefix, name, :body]
    .reduce(translations) do |buffer, key|
      buffer && buffer[key.to_sym]
    end
end
find_templates(name, prefix, _partial, details, _outside_app_allowed = false) click to toggle source
# File lib/action_mailer/markdown/resolver.rb, line 11
def find_templates(name, prefix, _partial, details, _outside_app_allowed = false)
  contents = find_contents(name, prefix, details)
  return [] unless contents

  %i[html text].map do |format|
    identifier = "#{prefix}##{name} (#{format})"
    path = virtual_path(name, prefix)
    build_template(path, contents, identifier, format)
  end
end
handler_for(format) click to toggle source
# File lib/action_mailer/markdown/resolver.rb, line 33
def handler_for(format)
  ActionView::Template
    .registered_template_handler(FORMAT_TO_EXTENSION.fetch(format))
end
translations() click to toggle source
# File lib/action_mailer/markdown/resolver.rb, line 42
def translations
  I18n.backend.initialize unless I18n.backend.initialized?
  I18n.backend.send(:translations)
end
virtual_path(name, prefix) click to toggle source
# File lib/action_mailer/markdown/resolver.rb, line 38
def virtual_path(name, prefix)
  "#{prefix}/#{name}"
end