2012-04-21 19:23:48 +00:00
|
|
|
module NotificationFactory
|
2014-12-28 13:02:23 +00:00
|
|
|
|
|
|
|
=begin
|
|
|
|
|
2016-04-13 23:40:37 +00:00
|
|
|
result = NotificationFactory.template_read(
|
2016-02-29 23:52:51 +00:00
|
|
|
template: 'password_reset',
|
|
|
|
locale: 'en-us',
|
2016-04-13 23:40:37 +00:00
|
|
|
format: 'html', # md
|
|
|
|
type: 'mailer', # slack
|
2016-02-29 23:52:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
{
|
2016-04-13 23:40:37 +00:00
|
|
|
subject: 'some subject',
|
2016-02-29 23:52:51 +00:00
|
|
|
body: 'some body',
|
|
|
|
}
|
|
|
|
|
2016-02-19 21:05:36 +00:00
|
|
|
=end
|
|
|
|
|
2016-04-13 23:40:37 +00:00
|
|
|
def self.template_read(data)
|
2016-02-19 21:05:36 +00:00
|
|
|
|
|
|
|
template_subject = nil
|
|
|
|
template_body = ''
|
|
|
|
locale = data[:locale] || 'en'
|
|
|
|
template = data[:template]
|
2016-04-13 23:40:37 +00:00
|
|
|
format = data[:format]
|
|
|
|
type = data[:type]
|
2016-03-02 10:43:57 +00:00
|
|
|
root = Rails.root
|
2016-04-13 23:40:37 +00:00
|
|
|
location = "#{root}/app/views/#{type}/#{template}/#{locale}.#{format}.erb"
|
2016-02-19 21:05:36 +00:00
|
|
|
|
|
|
|
# as fallback, use 2 char locale
|
|
|
|
if !File.exist?(location)
|
|
|
|
locale = locale[0, 2]
|
2016-04-13 23:40:37 +00:00
|
|
|
location = "#{root}/app/views/#{type}/#{template}/#{locale}.#{format}.erb"
|
2016-02-19 21:05:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# as fallback, use en
|
|
|
|
if !File.exist?(location)
|
2016-04-13 23:40:37 +00:00
|
|
|
location = "#{root}/app/views/#{type}/#{template}/en.#{format}.erb"
|
2016-02-19 21:05:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
File.open(location, 'r:UTF-8').each do |line|
|
|
|
|
if !template_subject
|
|
|
|
template_subject = line
|
|
|
|
next
|
|
|
|
end
|
|
|
|
template_body += line
|
|
|
|
end
|
|
|
|
{
|
2016-04-13 23:40:37 +00:00
|
|
|
subject: template_subject,
|
|
|
|
body: template_body,
|
2016-02-19 21:05:36 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-04-13 23:40:37 +00:00
|
|
|
=begin
|
2016-02-19 21:05:36 +00:00
|
|
|
|
2016-04-13 23:40:37 +00:00
|
|
|
string = NotificationFactory.application_template_read(
|
|
|
|
format: 'html', # md
|
|
|
|
type: 'mailer', # slack
|
|
|
|
)
|
2016-02-19 21:05:36 +00:00
|
|
|
|
2016-04-13 23:40:37 +00:00
|
|
|
returns
|
2016-02-19 21:05:36 +00:00
|
|
|
|
2016-04-13 23:40:37 +00:00
|
|
|
'some template'
|
2016-02-19 21:05:36 +00:00
|
|
|
|
2016-04-13 23:40:37 +00:00
|
|
|
=end
|
2016-02-19 21:05:36 +00:00
|
|
|
|
2016-04-13 23:40:37 +00:00
|
|
|
def self.application_template_read(data)
|
|
|
|
format = data[:format]
|
|
|
|
type = data[:type]
|
|
|
|
root = Rails.root
|
|
|
|
application_template = nil
|
|
|
|
File.open("#{root}/app/views/#{type}/application.#{format}.erb", 'r:UTF-8') do |file|
|
|
|
|
application_template = file.read
|
2016-02-19 21:05:36 +00:00
|
|
|
end
|
2016-04-13 23:40:37 +00:00
|
|
|
application_template
|
2016-02-19 21:05:36 +00:00
|
|
|
end
|
2016-04-13 23:40:37 +00:00
|
|
|
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|