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
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/action_mailer/markdown/resolver.rb', line 28 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
53 54 55 56 57 58 |
# File 'lib/action_mailer/markdown/resolver.rb', line 53 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 21 22 23 24 25 26 |
# File 'lib/action_mailer/markdown/resolver.rb', line 11 def find_templates( name, prefix, _partial, details, _outside_app_allowed = false # rubocop:disable Style/OptionalBooleanParameter ) 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
39 40 41 42 |
# File 'lib/action_mailer/markdown/resolver.rb', line 39 def handler_for(format) ActionView::Template .registered_template_handler(FORMAT_TO_EXTENSION.fetch(format)) end |
#translations ⇒ Object
48 49 50 51 |
# File 'lib/action_mailer/markdown/resolver.rb', line 48 def translations I18n.backend.initialize unless I18n.backend.initialized? I18n.backend.send(:translations) end |
#virtual_path(name, prefix) ⇒ Object
44 45 46 |
# File 'lib/action_mailer/markdown/resolver.rb', line 44 def virtual_path(name, prefix) "#{prefix}/#{name}" end |