1 module ApplicationHelper
2 require "rexml/document"
6 Rinku.auto_link(text, :urls, tag_builder.tag_options(:rel => "nofollow")).html_safe
8 Rinku.auto_link(text, :urls, tag_builder.tag_options(:rel => "nofollow"))
12 def rss_link_to(*args)
13 link_to(image_tag("RSS.png", :size => "16x16", :border => 0), Hash[*args], :class => "rsssmall")
16 def atom_link_to(*args)
17 link_to(image_tag("RSS.png", :size => "16x16", :border => 0), Hash[*args], :class => "rsssmall")
23 css << ".hidden { display: none !important }"
24 css << ".hide_unless_logged_in { display: none !important }" unless current_user
25 css << ".hide_if_logged_in { display: none !important }" if current_user
26 css << ".hide_if_user_#{current_user.id} { display: none !important }" if current_user
27 css << ".show_if_user_#{current_user.id} { display: inline !important }" if current_user
28 css << ".hide_unless_administrator { display: none !important }" unless current_user && current_user.administrator?
29 css << ".hide_unless_moderator { display: none !important }" unless current_user && current_user.moderator?
31 content_tag(:style, css, :type => "text/css")
34 def if_logged_in(tag = :div, &block)
35 content_tag(tag, capture(&block), :class => "hide_unless_logged_in")
38 def if_not_logged_in(tag = :div, &block)
39 content_tag(tag, capture(&block), :class => "hide_if_logged_in")
42 def if_user(user, tag = :div, &block)
44 content_tag(tag, capture(&block), :class => "hidden show_if_user_#{user.id}")
48 def unless_user(user, tag = :div, &block)
50 content_tag(tag, capture(&block), :class => "hide_if_user_#{user.id}")
52 content_tag(tag, capture(&block))
56 def if_administrator(tag = :div, &block)
57 content_tag(tag, capture(&block), :class => "hide_unless_administrator")
60 def richtext_area(object_name, method, options = {})
61 id = "#{object_name}_#{method}"
62 type = options.delete(:format) || "markdown"
64 content_tag(:div, :id => "#{id}_container", :class => "richtext_container") do
65 output_buffer << content_tag(:div, :id => "#{id}_content", :class => "richtext_content") do
66 output_buffer << text_area(object_name, method, options.merge("data-preview-url" => preview_url(:type => type)))
67 output_buffer << content_tag(:div, "", :id => "#{id}_preview", :class => "richtext_preview richtext")
70 output_buffer << content_tag(:div, :id => "#{id}_help", :class => "richtext_help") do
71 output_buffer << render("site/#{type}_help")
72 output_buffer << content_tag(:div, :class => "buttons") do
73 output_buffer << submit_tag(I18n.t("site.richtext_area.edit"), :id => "#{id}_doedit", :class => "richtext_doedit deemphasize", :disabled => true)
74 output_buffer << submit_tag(I18n.t("site.richtext_area.preview"), :id => "#{id}_dopreview", :class => "richtext_dopreview deemphasize")
82 dir == "rtl" ? "rtl" : "ltr"
88 def friendly_date(date)
89 content_tag(:span, time_ago_in_words(date), :title => l(date, :format => :friendly))
93 if content_for? :body_class
94 content_for :body_class
96 "#{params[:controller]} #{params[:controller]}-#{params[:action]}"
100 def current_page_class(path)
101 :current if current_page?(path)
106 :locale => I18n.locale,
107 :preferred_editor => preferred_editor
111 data[:user] = current_user.id.to_json
113 unless current_user.home_lon.nil? || current_user.home_lat.nil?
114 data[:user_home] = { :lat => current_user.home_lat, :lon => current_user.home_lon }
118 data[:location] = session[:location] if session[:location]
121 data[:token] = @oauth.token
122 data[:token_secret] = @oauth.secret
123 data[:consumer_key] = @oauth.client_application.key
124 data[:consumer_secret] = @oauth.client_application.secret