Make helpers return text instead of appending to the output buffer

This commit is contained in:
Tom Hughes 2010-09-03 15:25:11 +01:00
parent 92c171dcaa
commit ed54379218
7 changed files with 15 additions and 15 deletions

View file

@ -54,29 +54,29 @@ module ApplicationHelper
end end
def if_logged_in(tag = :div, &block) def if_logged_in(tag = :div, &block)
concat(content_tag(tag, capture(&block), :class => "hide_unless_logged_in")) content_tag(tag, capture(&block), :class => "hide_unless_logged_in")
end end
def if_not_logged_in(tag = :div, &block) def if_not_logged_in(tag = :div, &block)
concat(content_tag(tag, capture(&block), :class => "hide_if_logged_in")) content_tag(tag, capture(&block), :class => "hide_if_logged_in")
end end
def if_user(user, tag = :div, &block) def if_user(user, tag = :div, &block)
if user if user
concat(content_tag(tag, capture(&block), :class => "hidden show_if_user_#{user.id}")) content_tag(tag, capture(&block), :class => "hidden show_if_user_#{user.id}")
end end
end end
def unless_user(user, tag = :div, &block) def unless_user(user, tag = :div, &block)
if user if user
concat(content_tag(tag, capture(&block), :class => "hide_if_user_#{user.id}")) content_tag(tag, capture(&block), :class => "hide_if_user_#{user.id}")
else else
concat(content_tag(tag, capture(&block))) content_tag(tag, capture(&block))
end end
end end
def if_administrator(tag = :div, &block) def if_administrator(tag = :div, &block)
concat(content_tag(tag, capture(&block), :class => "hide_unless_administrator")) content_tag(tag, capture(&block), :class => "hide_unless_administrator")
end end
def describe_location(lat, lon, zoom = nil, language = nil) def describe_location(lat, lon, zoom = nil, language = nil)

View file

@ -1,7 +1,7 @@
<%= user_thumbnail diary_comment.user %> <%= user_thumbnail diary_comment.user %>
<h4 id="comment<%= diary_comment.id %>"><%= raw(t('diary_entry.diary_comment.comment_from', :link_user => (link_to h(diary_comment.user.display_name), :controller => 'user', :action => 'view', :display_name => diary_comment.user.display_name), :comment_created_at => l(diary_comment.created_at, :format => :friendly))) %></h4> <h4 id="comment<%= diary_comment.id %>"><%= raw(t('diary_entry.diary_comment.comment_from', :link_user => (link_to h(diary_comment.user.display_name), :controller => 'user', :action => 'view', :display_name => diary_comment.user.display_name), :comment_created_at => l(diary_comment.created_at, :format => :friendly))) %></h4>
<%= htmlize(diary_comment.body) %> <%= htmlize(diary_comment.body) %>
<% if_administrator(:span) do %> <%= if_administrator(:span) do %>
<%= link_to t('diary_entry.diary_comment.hide_link'), {:action => 'hidecomment', :display_name => diary_comment.diary_entry.user.display_name, :id => diary_comment.diary_entry.id, :comment => diary_comment.id}, {:confirm => t('diary_entry.diary_comment.confirm')} %> <%= link_to t('diary_entry.diary_comment.hide_link'), {:action => 'hidecomment', :display_name => diary_comment.diary_entry.user.display_name, :id => diary_comment.diary_entry.id, :comment => diary_comment.id}, {:confirm => t('diary_entry.diary_comment.confirm')} %>
<% end %> <% end %>
<hr /> <hr />

View file

@ -19,10 +19,10 @@
| |
<%= link_to t('diary_entry.diary_entry.comment_count', :count => diary_entry.visible_comments.count), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id, :anchor => 'comments' %> <%= link_to t('diary_entry.diary_entry.comment_count', :count => diary_entry.visible_comments.count), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id, :anchor => 'comments' %>
<% end %> <% end %>
<% if_user(diary_entry.user, :span) do %> <%= if_user(diary_entry.user, :span) do %>
| <%= link_to t('diary_entry.diary_entry.edit_link'), :action => 'edit', :display_name => diary_entry.user.display_name, :id => diary_entry.id %> | <%= link_to t('diary_entry.diary_entry.edit_link'), :action => 'edit', :display_name => diary_entry.user.display_name, :id => diary_entry.id %>
<% end %> <% end %>
<% if_administrator(:span) do %> <%= if_administrator(:span) do %>
| <%= link_to t('diary_entry.diary_entry.hide_link'), {:action => 'hide', :display_name => diary_entry.user.display_name, :id => diary_entry.id}, {:confirm => t('diary_entry.diary_entry.confirm')} %> | <%= link_to t('diary_entry.diary_entry.hide_link'), {:action => 'hide', :display_name => diary_entry.user.display_name, :id => diary_entry.id}, {:confirm => t('diary_entry.diary_entry.confirm')} %>
<% end %> <% end %>

View file

@ -5,11 +5,11 @@
<h2><%= h(@title) %></h2> <h2><%= h(@title) %></h2>
<% if @this_user %> <% if @this_user %>
<% if_user(@this_user) do %> <%= if_user(@this_user) do %>
<%= link_to image_tag("new.png", :border=>0) + t('diary_entry.list.new'), {:controller => 'diary_entry', :action => 'new'}, {:title => t('diary_entry.list.new_title')} %> <%= link_to image_tag("new.png", :border=>0) + t('diary_entry.list.new'), {:controller => 'diary_entry', :action => 'new'}, {:title => t('diary_entry.list.new_title')} %>
<% end %> <% end %>
<% else %> <% else %>
<% if_logged_in do %> <%= if_logged_in do %>
<%= link_to image_tag("new.png", :border=>0) + t('diary_entry.list.new'), {:controller => 'diary_entry', :action => 'new'}, {:title => t('diary_entry.list.new_title')} %> <%= link_to image_tag("new.png", :border=>0) + t('diary_entry.list.new'), {:controller => 'diary_entry', :action => 'new'}, {:title => t('diary_entry.list.new_title')} %>
<% end %> <% end %>
<% end %> <% end %>

View file

@ -8,7 +8,7 @@
<%= render :partial => 'diary_comment', :collection => @entry.visible_comments %> <%= render :partial => 'diary_comment', :collection => @entry.visible_comments %>
<% if_logged_in(:div) do %> <%= if_logged_in(:div) do %>
<h4 id="newcomment"><%= t 'diary_entry.view.leave_a_comment' %></h4> <h4 id="newcomment"><%= t 'diary_entry.view.leave_a_comment' %></h4>
<%= error_messages_for 'diary_comment' %> <%= error_messages_for 'diary_comment' %>
@ -21,6 +21,6 @@
<% end %> <% end %>
<% end %> <% end %>
<% if_not_logged_in(:div) do %> <%= if_not_logged_in(:div) do %>
<h4 id="newcomment"><%= t("diary_entry.view.login_to_leave_a_comment", :login_link => link_to(t("diary_entry.view.login"), :controller => 'user', :action => 'login', :referer => request.request_uri)) %></h4> <h4 id="newcomment"><%= t("diary_entry.view.login_to_leave_a_comment", :login_link => link_to(t("diary_entry.view.login"), :controller => 'user', :action => 'login', :referer => request.request_uri)) %></h4>
<% end %> <% end %>

View file

@ -14,7 +14,7 @@
<% if @display_name %> <% if @display_name %>
| <%= link_to t('trace.trace_header.see_all_traces'), :controller => 'trace', :action => 'list', :display_name => nil, :tag => nil, :page => nil %> | <%= link_to t('trace.trace_header.see_all_traces'), :controller => 'trace', :action => 'list', :display_name => nil, :tag => nil, :page => nil %>
<% end %> <% end %>
<% unless_user(@target_user, :span) do %> <%= unless_user(@target_user, :span) do %>
| <%= link_to t('trace.trace_header.see_your_traces'), :action => 'mine', :tag => nil, :page => nil %> | <%= link_to t('trace.trace_header.see_your_traces'), :action => 'mine', :tag => nil, :page => nil %>
<% end %> <% end %>
<% end %> <% end %>

View file

@ -52,7 +52,7 @@
<br /><br /> <br /><br />
<% if_user(@trace.user) do %> <%= if_user(@trace.user) do %>
<table> <table>
<tr> <tr>
<td><%= button_to t('trace.view.edit_track'), :controller => 'trace', :action => 'edit', :id => @trace.id %></td> <td><%= button_to t('trace.view.edit_track'), :controller => 'trace', :action => 'edit', :id => @trace.id %></td>