trabajo-afectivo/lib/notification_factory/template.rb

30 lines
579 B
Ruby
Raw Normal View History

2016-04-13 23:40:37 +00:00
class NotificationFactory::Template
2016-11-11 10:17:53 +00:00
=begin
examples how to use
cleaned_template = NotificationFactory::Template.new(
2016-11-11 10:17:53 +00:00
'some template <b><%= d "ticket.title", false %></b> <%= c "fqdn", false %>',
).to_s
2016-11-11 10:17:53 +00:00
=end
def initialize(template)
2016-04-13 23:40:37 +00:00
@template = template
end
def to_s
strip_html
2016-04-13 23:40:37 +00:00
@template
2016-04-15 21:56:10 +00:00
end
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