]> git.openstreetmap.org Git - rails.git/blob - app/helpers/application_helper.rb
Converted invalid_chars validator to use locale
[rails.git] / app / helpers / application_helper.rb
1 module ApplicationHelper
2   require "rexml/document"
3
4   def linkify(text)
5     if text.html_safe?
6       Rinku.auto_link(text, :urls, tag_builder.tag_options(:rel => "nofollow")).html_safe
7     else
8       Rinku.auto_link(text, :urls, tag_builder.tag_options(:rel => "nofollow"))
9     end
10   end
11
12   def rss_link_to(*args)
13     link_to(image_tag("RSS.png", :size => "16x16", :border => 0), Hash[*args], :class => "rsssmall")
14   end
15
16   def atom_link_to(*args)
17     link_to(image_tag("RSS.png", :size => "16x16", :border => 0), Hash[*args], :class => "rsssmall")
18   end
19
20   def richtext_area(object_name, method, options = {})
21     id = "#{object_name}_#{method}"
22     type = options.delete(:format) || "markdown"
23
24     content_tag(:div, :id => "#{id}_container", :class => "richtext_container") do
25       output_buffer << content_tag(:div, :id => "#{id}_content", :class => "richtext_content") do
26         output_buffer << text_area(object_name, method, options.merge("data-preview-url" => preview_url(:type => type)))
27         output_buffer << content_tag(:div, "", :id => "#{id}_preview", :class => "richtext_preview richtext")
28       end
29
30       output_buffer << content_tag(:div, :id => "#{id}_help", :class => "richtext_help") do
31         output_buffer << render("site/#{type}_help")
32         output_buffer << content_tag(:div, :class => "buttons") do
33           output_buffer << submit_tag(I18n.t("site.richtext_area.edit"), :id => "#{id}_doedit", :class => "richtext_doedit deemphasize", :disabled => true)
34           output_buffer << submit_tag(I18n.t("site.richtext_area.preview"), :id => "#{id}_dopreview", :class => "richtext_dopreview deemphasize")
35         end
36       end
37     end
38   end
39
40   def dir
41     if dir = params[:dir]
42       dir == "rtl" ? "rtl" : "ltr"
43     else
44       I18n.t("html.dir")
45     end
46   end
47
48   def friendly_date(date)
49     content_tag(:span, time_ago_in_words(date), :title => l(date, :format => :friendly))
50   end
51
52   def body_class
53     if content_for? :body_class
54       content_for :body_class
55     else
56       "#{params[:controller]} #{params[:controller]}-#{params[:action]}"
57     end
58   end
59
60   def current_page_class(path)
61     :current if current_page?(path)
62   end
63
64   def application_data
65     data = {
66       :locale => I18n.locale,
67       :preferred_editor => preferred_editor
68     }
69
70     if current_user
71       data[:user] = current_user.id.to_json
72
73       data[:user_home] = { :lat => current_user.home_lat, :lon => current_user.home_lon } unless current_user.home_lon.nil? || current_user.home_lat.nil?
74     end
75
76     data[:location] = session[:location] if session[:location]
77
78     if @oauth
79       data[:token] = @oauth.token
80       data[:token_secret] = @oauth.secret
81       data[:consumer_key] = @oauth.client_application.key
82       data[:consumer_secret] = @oauth.client_application.secret
83     end
84
85     data
86   end
87 end