1 module ApplicationHelper
2 require 'rexml/document'
5 return linkify(sanitize(simple_format(text)))
9 return auto_link(text, :link => :urls, :html => { :rel => "nofollow" })
12 def html_escape_unicode(text)
13 chars = ActiveSupport::Multibyte::Chars.u_unpack(text).map do |c|
14 c < 127 ? c.chr : "&##{c.to_s};"
20 def rss_link_to(*args)
21 return link_to(image_tag("RSS.gif", :size => "16x16", :border => 0), Hash[*args], { :class => "rsssmall" });
24 def atom_link_to(*args)
25 return link_to(image_tag("RSS.gif", :size => "16x16", :border => 0), Hash[*args], { :class => "rsssmall" });
28 def javascript_strings
31 js << "<script type='text/javascript'>\n"
32 js << "i18n_strings = new Array();\n"
33 js << javascript_strings_for_key("javascripts")
39 def describe_location(lat, lon, zoom = nil, language = nil)
41 language = language || request.user_preferred_languages.join(',')
42 url = "http://nominatim.openstreetmap.org/reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{language}"
43 response = REXML::Document.new(Net::HTTP.get(URI.parse(url)))
45 if result = response.get_text("reversegeocode/result")
48 "#{number_with_precision(lat, :precision => 3)}, #{number_with_precision(lon, :precision => 3)}"
52 def user_image(user, options = {})
53 options[:class] ||= "user_image"
56 image_tag url_for_file_column(user, "image"), options
58 image_tag "anon_large.png", options
62 def user_thumbnail(user, options = {})
63 options[:class] ||= "user_thumbnail"
66 image_tag url_for_file_column(user, "image"), options
68 image_tag "anon_small.png", options
74 def javascript_strings_for_key(key)
76 value = t(key, :locale => "en")
78 if value.is_a?(String)
79 js << "i18n_strings['#{key}'] = '" << escape_javascript(t(key)) << "';\n"
82 js << javascript_strings_for_key("#{key}.#{k}")