1 module ApplicationHelper
2 require 'rexml/document'
5 Sanitize.clean(text, Sanitize::Config::OSM)
9 return linkify(sanitize(simple_format(text)))
13 return auto_link(text, :link => :urls, :html => { :rel => "nofollow" })
16 def html_escape_unicode(text)
17 chars = ActiveSupport::Multibyte::Chars.u_unpack(text).map do |c|
18 c < 127 ? c.chr : "&##{c.to_s};"
24 def rss_link_to(*args)
25 return link_to(image_tag("RSS.gif", :size => "16x16", :border => 0), Hash[*args], { :class => "rsssmall" });
28 def atom_link_to(*args)
29 return link_to(image_tag("RSS.gif", :size => "16x16", :border => 0), Hash[*args], { :class => "rsssmall" });
32 def javascript_strings
35 js << "<script type='text/javascript'>\n"
36 js << "i18n_strings = new Array();\n"
37 js << javascript_strings_for_key("javascripts")
43 def describe_location(lat, lon, zoom = nil, language = nil)
45 language = language || request.user_preferred_languages.join(',')
46 url = "http://nominatim.openstreetmap.org/reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{language}"
47 response = REXML::Document.new(Net::HTTP.get(URI.parse(url)))
49 if result = response.get_text("reversegeocode/result")
52 "#{number_with_precision(lat, :precision => 3)}, #{number_with_precision(lon, :precision => 3)}"
56 def user_image(user, options = {})
57 options[:class] ||= "user_image"
60 image_tag url_for_file_column(user, "image"), options
62 image_tag "anon_large.png", options
66 def user_thumbnail(user, options = {})
67 options[:class] ||= "user_thumbnail"
70 image_tag url_for_file_column(user, "image"), options
72 image_tag "anon_small.png", options
78 def javascript_strings_for_key(key)
80 value = I18n.t(key, :locale => "en")
82 if value.is_a?(String)
83 js << "i18n_strings['#{key}'] = '" << escape_javascript(t(key)) << "';\n"
86 js << javascript_strings_for_key("#{key}.#{k}")