Moved Page#pretty_revised_on to the view (it is not a model method)
This commit is contained in:
parent
042391bfff
commit
da3674770e
|
@ -1,14 +1,12 @@
|
||||||
require "date"
|
require 'date'
|
||||||
require "page_lock"
|
require 'page_lock'
|
||||||
require "revision"
|
require 'revision'
|
||||||
require "wiki_words"
|
require 'wiki_words'
|
||||||
require "chunks/wiki"
|
require 'chunks/wiki'
|
||||||
|
|
||||||
class Page
|
class Page
|
||||||
include PageLock
|
include PageLock
|
||||||
|
|
||||||
CONTINOUS_REVISION_PERIOD = 30 * 60 # 30 minutes
|
|
||||||
|
|
||||||
attr_reader :name, :revisions, :web
|
attr_reader :name, :revisions, :web
|
||||||
|
|
||||||
def initialize(web, name, content, created_at, author)
|
def initialize(web, name, content, created_at, author)
|
||||||
|
@ -17,6 +15,10 @@ class Page
|
||||||
end
|
end
|
||||||
|
|
||||||
def revise(content, created_at, author)
|
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)
|
if !@revisions.empty? && continous_revision?(created_at, author)
|
||||||
@revisions.last.created_at = Time.now
|
@revisions.last.created_at = Time.now
|
||||||
@revisions.last.content = content
|
@revisions.last.content = content
|
||||||
|
@ -41,10 +43,6 @@ class Page
|
||||||
created_on
|
created_on
|
||||||
end
|
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)
|
def in_category?(cat)
|
||||||
cat.nil? || cat.empty? || categories.include?(cat)
|
cat.nil? || cat.empty? || categories.include?(cat)
|
||||||
end
|
end
|
||||||
|
@ -76,7 +74,7 @@ class Page
|
||||||
|
|
||||||
private
|
private
|
||||||
def continous_revision?(created_at, author)
|
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
|
end
|
||||||
|
|
||||||
# Forward method calls to the current revision, so the page responds to all revision calls
|
# Forward method calls to the current revision, so the page responds to all revision calls
|
||||||
|
|
|
@ -12,7 +12,11 @@
|
||||||
<ul>
|
<ul>
|
||||||
<% for page in @pages_by_revision %>
|
<% for page in @pages_by_revision %>
|
||||||
<% if page.revised_on < revision_date %>
|
<% 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 %>
|
<% end %>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
|
|
|
@ -21,7 +21,6 @@ class PageTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_basics
|
def test_basics
|
||||||
assert_equal "First Page", @page.plain_name
|
assert_equal "First Page", @page.plain_name
|
||||||
assert_equal "April 4, 2004", @page.pretty_revised_on
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_locking
|
def test_locking
|
||||||
|
|
Loading…
Reference in a new issue