Moved Page#pretty_revised_on to the view (it is not a model method)

This commit is contained in:
Alexey Verkhovsky 2005-01-16 22:19:28 +00:00
parent 042391bfff
commit da3674770e
3 changed files with 16 additions and 15 deletions

View file

@ -1,14 +1,12 @@
require "date"
require "page_lock"
require "revision"
require "wiki_words"
require "chunks/wiki"
require 'date'
require 'page_lock'
require 'revision'
require 'wiki_words'
require 'chunks/wiki'
class Page
include PageLock
CONTINOUS_REVISION_PERIOD = 30 * 60 # 30 minutes
attr_reader :name, :revisions, :web
def initialize(web, name, content, created_at, author)
@ -17,6 +15,10 @@ class Page
end
def revise(content, created_at, author)
# A user may change a page, look at it and make some more changes - several times.
# Not to record every such iteration as a new revision, if the previous revision was done
# by the same author, not more than 30 minutes ago, then update the last revision instead of
# creating a new one
if !@revisions.empty? && continous_revision?(created_at, author)
@revisions.last.created_at = Time.now
@revisions.last.content = content
@ -41,10 +43,6 @@ class Page
created_on
end
def pretty_revised_on
DateTime.new(revised_on.year, revised_on.mon, revised_on.day).strftime "%B %e, %Y"
end
def in_category?(cat)
cat.nil? || cat.empty? || categories.include?(cat)
end
@ -76,7 +74,7 @@ class Page
private
def continous_revision?(created_at, author)
@revisions.last.author == author && @revisions.last.created_at + CONTINOUS_REVISION_PERIOD > created_at
@revisions.last.author == author && @revisions.last.created_at + 30.minutes > created_at
end
# Forward method calls to the current revision, so the page responds to all revision calls

View file

@ -12,7 +12,11 @@
<ul>
<% for page in @pages_by_revision %>
<% if page.revised_on < revision_date %>
</ul><b><%= page.pretty_revised_on %></b><ul>
</ul><b>
<%= DateTime.new(page.revised_on.year, page.revised_on.mon,
page.revised_on.day).strftime('%B %e, %Y')
%>
</b><ul>
<% end %>
<li>

View file

@ -21,7 +21,6 @@ class PageTest < Test::Unit::TestCase
def test_basics
assert_equal "First Page", @page.plain_name
assert_equal "April 4, 2004", @page.pretty_revised_on
end
def test_locking