2013-06-03 16:12:24 -04:00
|
|
|
module UserNotificationsHelper
|
2014-07-08 13:03:11 -04:00
|
|
|
|
2013-06-03 16:12:24 -04:00
|
|
|
def indent(text, by=2)
|
|
|
|
spacer = " " * by
|
|
|
|
result = ""
|
|
|
|
text.each_line do |line|
|
|
|
|
result << spacer << line
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
2013-07-24 03:13:15 -04:00
|
|
|
def correct_top_margin(html, desired)
|
|
|
|
fragment = Nokogiri::HTML.fragment(html)
|
|
|
|
if para = fragment.css("p:first").first
|
|
|
|
para["style"] = "margin-top: #{desired};"
|
|
|
|
end
|
|
|
|
fragment.to_html.html_safe
|
|
|
|
end
|
|
|
|
|
2013-11-28 17:20:56 -05:00
|
|
|
def logo_url
|
2014-03-18 15:56:17 -04:00
|
|
|
logo_url = SiteSetting.digest_logo_url
|
|
|
|
logo_url = SiteSetting.logo_url if logo_url.blank?
|
2014-07-21 14:18:32 -04:00
|
|
|
|
|
|
|
return nil if logo_url.blank?
|
2013-11-28 17:20:56 -05:00
|
|
|
if logo_url !~ /http(s)?\:\/\//
|
|
|
|
logo_url = "#{Discourse.base_url}#{logo_url}"
|
|
|
|
end
|
|
|
|
logo_url
|
|
|
|
end
|
|
|
|
|
|
|
|
def html_site_link
|
|
|
|
"<a href='#{Discourse.base_url}'>#{@site_name}</a>"
|
|
|
|
end
|
|
|
|
|
2014-01-22 15:30:30 -05:00
|
|
|
def first_paragraph_from(html)
|
|
|
|
doc = Nokogiri::HTML(html)
|
2014-02-13 16:11:01 -05:00
|
|
|
|
|
|
|
result = ""
|
2014-01-22 15:30:30 -05:00
|
|
|
doc.css('p').each do |p|
|
2014-02-13 16:11:01 -05:00
|
|
|
if p.text.present?
|
|
|
|
result << p.to_s
|
|
|
|
return result if result.size >= 100
|
|
|
|
end
|
2014-01-22 15:30:30 -05:00
|
|
|
end
|
2014-02-13 16:11:01 -05:00
|
|
|
return result unless result.blank?
|
2014-01-22 15:30:30 -05:00
|
|
|
|
|
|
|
# If there is no first paragaph, return the first div (onebox)
|
|
|
|
doc.css('div').first
|
|
|
|
end
|
|
|
|
|
2014-01-22 12:37:37 -05:00
|
|
|
def email_excerpt(html, posts_count)
|
2014-11-05 14:37:00 -05:00
|
|
|
# only include 1st paragraph when more than 1 posts
|
|
|
|
html = first_paragraph_from(html).to_s if posts_count > 1
|
|
|
|
raw format_for_email(html)
|
2013-11-28 17:20:56 -05:00
|
|
|
end
|
2014-04-17 12:32:51 -04:00
|
|
|
|
2014-11-05 14:37:00 -05:00
|
|
|
def format_for_email(html)
|
|
|
|
PrettyText.format_for_email(html).html_safe
|
2014-04-17 12:32:51 -04:00
|
|
|
end
|
2014-04-17 14:40:30 -04:00
|
|
|
|
2014-04-17 16:42:40 -04:00
|
|
|
def email_category(category, opts=nil)
|
|
|
|
opts = opts || {}
|
|
|
|
|
|
|
|
# If there is no category, bail
|
|
|
|
return "" if category.blank?
|
|
|
|
|
|
|
|
# By default hide uncategorized
|
|
|
|
return "" if category.uncategorized? && !opts[:show_uncategorized]
|
|
|
|
|
2014-04-17 14:40:30 -04:00
|
|
|
result = ""
|
2014-11-07 17:00:09 -05:00
|
|
|
|
2014-11-28 13:44:40 -05:00
|
|
|
category_url = "#{Discourse.base_url}#{category.url}"
|
|
|
|
|
2014-11-07 17:00:09 -05:00
|
|
|
if opts[:only_stripe]
|
2014-11-29 06:58:44 -05:00
|
|
|
result << "<a href='#{category_url}' style='background-color: ##{category.color}; font-size: 12px; padding: 2px 1px; font-weight: bold; margin: 0; width: 2px; white-space:nowrap;'> </a>"
|
2014-11-28 13:44:40 -05:00
|
|
|
result << "<a href='#{category_url}' style='font-size: 12px; font-weight: bold; margin-left: 3px;'>#{category.name}</a>"
|
2014-11-07 17:00:09 -05:00
|
|
|
else
|
|
|
|
if category.parent_category.present?
|
2014-11-28 13:44:40 -05:00
|
|
|
result << "<a href='#{category_url}' style='background-color: ##{category.parent_category.color}; font-size: 12px; padding: 4px 2px; font-weight: bold; margin: 0; width: 2px; white-space:nowrap;'> </a>"
|
2014-11-07 17:00:09 -05:00
|
|
|
end
|
2014-11-28 13:44:40 -05:00
|
|
|
result << "<a href='#{category_url}' style='background-color: ##{category.color}; color: ##{category.text_color}; font-size: 12px; padding: 4px 6px; font-weight: bold; margin: 0; white-space:nowrap;'>#{category.name}</a>"
|
2014-04-17 14:40:30 -04:00
|
|
|
end
|
2014-11-07 17:00:09 -05:00
|
|
|
|
2014-04-17 14:40:30 -04:00
|
|
|
result.html_safe
|
|
|
|
end
|
2013-06-03 16:12:24 -04:00
|
|
|
end
|