1 module ApplicationHelper
2 require 'rexml/document'
6 Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow")).html_safe
8 Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow"))
12 def rss_link_to(*args)
13 return link_to(image_tag("RSS.png", :size => "16x16", :border => 0), Hash[*args], { :class => "rsssmall" });
16 def atom_link_to(*args)
17 return 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 @user;
25 css << ".hide_if_logged_in { display: none !important }" if @user;
26 css << ".hide_if_user_#{@user.id} { display: none !important }" if @user;
27 css << ".show_if_user_#{@user.id} { display: inline !important }" if @user;
28 css << ".hide_unless_administrator { display: none !important }" unless @user and @user.administrator?;
30 return content_tag(:style, css, :type => "text/css")
33 def if_logged_in(tag = :div, &block)
34 content_tag(tag, capture(&block), :class => "hide_unless_logged_in")
37 def if_not_logged_in(tag = :div, &block)
38 content_tag(tag, capture(&block), :class => "hide_if_logged_in")
41 def if_user(user, tag = :div, &block)
43 content_tag(tag, capture(&block), :class => "hidden show_if_user_#{user.id}")
47 def unless_user(user, tag = :div, &block)
49 content_tag(tag, capture(&block), :class => "hide_if_user_#{user.id}")
51 content_tag(tag, capture(&block))
55 def if_administrator(tag = :div, &block)
56 content_tag(tag, capture(&block), :class => "hide_unless_administrator")
62 elsif @user and @user.preferred_editor
63 @user.preferred_editor
69 def scale_to_zoom(scale)
70 Math.log(360.0 / (scale.to_f * 512.0)) / Math.log(2.0)
73 def richtext_area(object_name, method, options = {})
74 id = "#{object_name.to_s}_#{method.to_s}"
75 format = options.delete(:format) || "markdown"
77 content_tag(:div, :id => "#{id}_container", :class => "richtext_container") do
78 output_buffer << content_tag(:div, :id => "#{id}_content", :class => "richtext_content") do
79 output_buffer << text_area(object_name, method, options.merge("data-preview-url" => preview_url(:format => format)))
80 output_buffer << content_tag(:div, "", :id => "#{id}_preview", :class => "richtext_preview")
83 output_buffer << content_tag(:div, :id => "#{id}_help", :class => "richtext_help") do
84 output_buffer << render("site/#{format}_help")
85 output_buffer << submit_tag(I18n.t("site.richtext_area.edit"), :id => "#{id}_doedit", :class => "richtext_doedit", :disabled => true)
86 output_buffer << submit_tag(I18n.t("site.richtext_area.preview"), :id => "#{id}_dopreview", :class => "richtext_dopreview")
93 dir == "rtl" ? "rtl" : "ltr"