Moved pretty date formatting from revision to the main view helper, where this presentation logic obviously belongs

This commit is contained in:
Alexey Verkhovsky 2005-08-14 23:35:10 +00:00
parent 5b075ca338
commit 06959ab278
6 changed files with 10 additions and 12 deletions

View file

@ -72,4 +72,10 @@ module ApplicationHelper
h(text).gsub(/\n/, '<br/>')
end
def format_date(date)
# Must use DateTime because Time doesn't support %e on at least some platforms
DateTime.new(date.year, date.mon, date.day, date.hour, date.min,
date.sec).strftime("%B %e, %Y %H:%M:%S")
end
end

View file

@ -3,14 +3,6 @@ class Revision < ActiveRecord::Base
belongs_to :page
composed_of :author, :mapping => [ %w(author name), %w(ip ip) ]
# TODO this method belongs in the view helpers (only views use it)
def pretty_created_on
# Must use DateTime because Time doesn't support %e on at least some platforms
DateTime.new(
revised_at.year, revised_at.mon, revised_at.day, revised_at.hour, revised_at.min, revised_at.sec
).strftime "%B %e, %Y %H:%M:%S"
end
# Returns an array of all the WikiIncludes present in the content of this revision.
def wiki_includes
unless @wiki_includes_cache

View file

@ -22,7 +22,7 @@
<% end %>
<div class="byline">
<%= @page.revisions? ? "Revised" : "Created" %> on <%= @page.pretty_created_on %>
<%= @page.revisions? ? "Revised" : "Created" %> on <%= format_date(@page.revised_at) %>
by <%= @page.author_link %>
<%= "(#{@page.author.ip})" if @page.author.respond_to?(:ip) %>
<% if @web.count_pages? %>

View file

@ -8,7 +8,7 @@
<%= @page.display_content_for_export %>
<div class="byline">
<%= @page.revisions? ? "Revised" : "Created" %> on <%= @page.pretty_created_on %>
<%= @page.revisions? ? "Revised" : "Created" %> on <%= format_date(@page.revised_at) %>
by
<%= @page.author_link({ :mode => (@link_mode || :show) }) %>
</div>

View file

@ -17,7 +17,7 @@
<%= link_to_existing_page page %>
<div class="byline" style="margin-bottom: 0px">
by <%= link_to_page(page.author) %>
at <%= page.current_revision.pretty_created_on %>
at <%= format_date(page.revised_at) %>
<%= "from #{page.author.ip}" if page.author.respond_to?(:ip) %>
</div>
</li>

View file

@ -17,7 +17,7 @@
<div class="byline">
<%= "Revision from #{@revision.pretty_created_on} by" %>
<%= "Revision from #{format_date(@revision.revised_at)} by" %>
<%= link_to_page @revision.author %>
</div>