Improved file location detection.

This commit is contained in:
Martin Edenhofer 2016-03-02 11:43:57 +01:00
parent f4f99306b9
commit 42b5e37c9c

View file

@ -314,17 +314,18 @@ returns
template_body = '' template_body = ''
locale = data[:locale] || 'en' locale = data[:locale] || 'en'
template = data[:template] template = data[:template]
location = "app/views/mailer/#{template}/#{locale}.html.erb" root = Rails.root
location = "#{root}/app/views/mailer/#{template}/#{locale}.html.erb"
# as fallback, use 2 char locale # as fallback, use 2 char locale
if !File.exist?(location) if !File.exist?(location)
locale = locale[0, 2] locale = locale[0, 2]
location = "app/views/mailer/#{template}/#{locale}.html.erb" location = "#{root}/app/views/mailer/#{template}/#{locale}.html.erb"
end end
# as fallback, use en # as fallback, use en
if !File.exist?(location) if !File.exist?(location)
location = "app/views/mailer/#{template}/en.html.erb" location = "#{root}/app/views/mailer/#{template}/en.html.erb"
end end
File.open(location, 'r:UTF-8').each do |line| File.open(location, 'r:UTF-8').each do |line|
@ -340,7 +341,7 @@ returns
if !data[:raw] if !data[:raw]
application_template = nil application_template = nil
File.open('app/views/mailer/application.html.erb', 'r:UTF-8') do |file| File.open("#{root}/app/views/mailer/application.html.erb", 'r:UTF-8') do |file|
application_template = file.read application_template = file.read
end end
data[:objects][:message] = message_body data[:objects][:message] = message_body