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)}"
54 def javascript_strings_for_key(key)
56 value = t(key, :locale => "en")
58 if value.is_a?(String)
59 js << "i18n_strings['#{key}'] = '" << escape_javascript(t(key)) << "';\n"
62 js << javascript_strings_for_key("#{key}.#{k}")