Class: ActionMailer::Markdown::Resolver
- Inherits:
-
ActionView::Resolver
- Object
- ActionView::Resolver
- ActionMailer::Markdown::Resolver
- Defined in:
- lib/action_mailer/markdown/resolver.rb
Constant Summary collapse
- FORMAT_TO_EXTENSION =
{ text: :mdt, html: :md }.freeze
Instance Method Summary collapse
- #build_template(path, contents, identifier, format) ⇒ Object
- #find_contents(name, prefix, details) ⇒ Object
- #find_templates(name, prefix, _partial, details, _outside_app_allowed = false) ⇒ Object
- #handler_for(format) ⇒ Object
- #translations ⇒ Object
- #virtual_path(name, prefix) ⇒ Object
Instance Method Details
#build_template(path, contents, identifier, format) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# 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) ⇒ Object
47 48 49 50 51 52 |
# 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) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# 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) ⇒ Object
33 34 35 36 |
# 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 ⇒ Object
42 43 44 45 |
# 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) ⇒ Object
38 39 40 |
# File 'lib/action_mailer/markdown/resolver.rb', line 38 def virtual_path(name, prefix) "#{prefix}/#{name}" end |