Split come changset display logic into a helper
authorAaron Lidman <aaronlidman@gmail.com>
Wed, 6 Nov 2013 21:47:10 +0000 (13:47 -0800)
committerAaron Lidman <aaronlidman@gmail.com>
Wed, 6 Nov 2013 21:59:42 +0000 (13:59 -0800)
app/helpers/changeset_helper.rb [new file with mode: 0644]
app/views/browse/changeset.html.erb
config/locales/en.yml

diff --git a/app/helpers/changeset_helper.rb b/app/helpers/changeset_helper.rb
new file mode 100644 (file)
index 0000000..1476241
--- /dev/null
@@ -0,0 +1,24 @@
+module ChangesetHelper
+    def changeset_time_ago(changeset)
+        out = ''
+        created_at = distance_of_time_in_words_to_now(changeset.created_at)
+        closed_at = distance_of_time_in_words_to_now(changeset.closed_at)
+        if created_at == closed_at
+            out << t('browse.changeset_details.closed_at') + ' '
+            both_times = t('browse.changeset_details.created_at') + ': ' + l(changeset.created_at)
+            both_times << '&#10;'
+            both_times << t('browse.changeset_details.closed_at') + ': ' + l(changeset.closed_at)
+            out << content_tag(:abbr, t('browse.changeset_details.ago', :ago => created_at), title: both_times.html_safe)
+        else
+            out << t('browse.changeset_details.created_at') + ' '
+            out << content_tag(:abbr, t('browse.changeset_details.ago', :ago => created_at), title: l(changeset.created_at))
+            out << t('browse.changeset_details.closed_at') + ' '
+            out << content_tag(:abbr, t('browse.changeset_details.ago', :ago => closed_at), title: l(changeset.closed_at))
+        end
+        if changeset.user.data_public?
+            out << ' ' + t('browse.changeset_details.by') + ' '
+            out << link_to(h(changeset.user.display_name), :controller => "user", :action => "view", :display_name => changeset.user.display_name)
+        end
+        return out.html_safe
+    end
+end
index 08979c2834ed571e0748fc77c61ccd040546b930..b9b37da47108cb2205685423f7cb60bab0021249 100644 (file)
@@ -4,30 +4,10 @@
 <div class="browse-section">
   <p>
     <%=
-      if @changeset.tags['comment'].to_s != ''
-        @changeset.tags['comment'].to_s
-      else
-        t ('browse.changeset_details.no_comment')
-      end
+        @changeset.tags['comment'].to_s.presence || t('browse.changeset_details.no_comment')
     %>
   </p>
-  <h4>
-    <%
-      created_at = distance_of_time_in_words_to_now(@changeset.created_at)
-      closed_at = distance_of_time_in_words_to_now(@changeset.closed_at)
-      if created_at == closed_at
-    %>
-      <%= t 'browse.changeset_details.closed_at' %> 
-      <abbr title="<%= t 'browse.changeset_details.created_at' %>: <%= l @changeset.created_at %> &#10;<%= t 'browse.changeset_details.closed_at' %>: <%= l @changeset.closed_at %>">
-      <%= t('browse.changeset_details.ago', :ago => created_at) %></abbr> 
-    <% else %>
-      <%= t 'browse.changeset_details.created_at' %> <abbr title="<%= l @changeset.created_at %>"><%= t('browse.changeset_details.ago', :ago => created_at) %></abbr>, 
-      <%= t 'browse.changeset_details.closed_at' %> <abbr title="<%= l @changeset.closed_at %>"><%= t('browse.changeset_details.ago', :ago => closed_at) %><abbr>
-    <% end %>
-    <% if @changeset.user.data_public? %>
-      by <%= link_to h(@changeset.user.display_name), :controller => "user", :action => "view", :display_name => @changeset.user.display_name %>
-    <% end %>
-  </h4>
+  <span><%= changeset_time_ago(@changeset) %></span>
 </div>
   
 <%=
index a72ad287c882b2cc0ce7138994c732ef10fcc9cb..2fcd737c923bbe5ad2dc25db83b733f8f35f565b 100644 (file)
@@ -135,6 +135,7 @@ en:
       has_relations: "Relations (%{count})"
       no_comment: "(no comment)"
       ago: "%{ago} ago"
+      by: "by"
     common_details:
       edited: "Edited"
       deleted: "Deleted"