2016-04-13 23:40:37 +00:00
|
|
|
class NotificationFactory::Template
|
|
|
|
|
2016-11-11 10:17:53 +00:00
|
|
|
=begin
|
|
|
|
|
|
|
|
examples how to use
|
|
|
|
|
2016-11-11 15:57:25 +00:00
|
|
|
cleaned_template = NotificationFactory::Template.new(
|
2016-11-11 10:17:53 +00:00
|
|
|
'some template <b><%= d "ticket.title", false %></b> <%= c "fqdn", false %>',
|
2016-11-11 15:57:25 +00:00
|
|
|
).to_s
|
2016-11-11 10:17:53 +00:00
|
|
|
|
|
|
|
=end
|
|
|
|
|
2016-11-11 15:57:25 +00:00
|
|
|
def initialize(template)
|
2016-04-13 23:40:37 +00:00
|
|
|
@template = template
|
|
|
|
end
|
|
|
|
|
2016-11-11 15:57:25 +00:00
|
|
|
def to_s
|
|
|
|
strip_html
|
2016-04-13 23:40:37 +00:00
|
|
|
|
2016-11-11 15:57:25 +00:00
|
|
|
@template
|
2016-04-15 21:56:10 +00:00
|
|
|
end
|
|
|
|
|
2016-11-11 15:57:25 +00:00
|
|
|
def strip_html
|
|
|
|
# some browsers start adding HTML tags
|
|
|
|
# fixes https://github.com/zammad/zammad/issues/385
|
|
|
|
@template.gsub!(%r{#\{\s*<[^>]+>([^<]+)</[^>]+>\s*\}}, '\1')
|
|
|
|
@template.gsub!(/#\{\s*<[^>]+>([^<]+)\s*\}/, '\1')
|
2016-04-13 23:40:37 +00:00
|
|
|
end
|
|
|
|
end
|