Class: Page
Constant Summary
collapse
- CONTINOUS_REVISION_PERIOD =
30 * 60
Constants included
from PageLock
PageLock::LOCKING_PERIOD
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from PageLock
#lock, #lock_duration, #locked?, #locked_by_link, #unlock
Constructor Details
#initialize(web, name, content, created_at, author) ⇒ Page
Returns a new instance of Page.
14
15
16
17
|
# File 'app/models/page.rb', line 14
def initialize(web, name, content, created_at, author)
@web, @name, @revisions = web, name, []
revise(content, created_at, author)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_symbol) ⇒ Object
Forward method calls to the current revision, so the page responds to all revision calls
83
84
85
|
# File 'app/models/page.rb', line 83
def method_missing(method_symbol)
revisions.last.send(method_symbol)
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
12
13
14
|
# File 'app/models/page.rb', line 12
def name
@name
end
|
#revisions ⇒ Object
Returns the value of attribute revisions.
12
13
14
|
# File 'app/models/page.rb', line 12
def revisions
@revisions
end
|
#web ⇒ Object
Returns the value of attribute web.
12
13
14
|
# File 'app/models/page.rb', line 12
def web
@web
end
|
Instance Method Details
#author_link(options = {}) ⇒ Object
73
74
75
|
# File 'app/models/page.rb', line 73
def author_link(options = {})
web.make_link(author, nil, options)
end
|
#authors ⇒ Object
56
57
58
|
# File 'app/models/page.rb', line 56
def authors
revisions.collect { |rev| rev.author }
end
|
#categories ⇒ Object
52
53
54
|
# File 'app/models/page.rb', line 52
def categories
display_content.find_chunks(Category).map { |cat| cat.list }.flatten
end
|
#in_category?(cat) ⇒ Boolean
48
49
50
|
# File 'app/models/page.rb', line 48
def in_category?(cat)
cat.nil? || cat.empty? || categories.include?(cat)
end
|
#link(options = {}) ⇒ Object
69
70
71
|
# File 'app/models/page.rb', line 69
def link(options = {})
web.make_link(name, nil, options)
end
|
#plain_name ⇒ Object
Returns the original wiki-word name as separate words, so “MyPage” becomes “My Page”.
65
66
67
|
# File 'app/models/page.rb', line 65
def plain_name
WikiWords.separate(name, web.brackets_only)
end
|
#pretty_revised_on ⇒ Object
44
45
46
|
# File 'app/models/page.rb', line 44
def pretty_revised_on
DateTime.new(revised_on.year, revised_on.mon, revised_on.day).strftime "%B %e, %Y"
end
|
#references ⇒ Object
60
61
62
|
# File 'app/models/page.rb', line 60
def references
web.select.pages_that_reference(name)
end
|
#revise(content, created_at, author) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# File 'app/models/page.rb', line 19
def revise(content, created_at, author)
if !@revisions.empty? && continous_revision?(created_at, author)
@revisions.last.created_at = Time.now
@revisions.last.content = content
@revisions.last.clear_display_cache
else
@revisions << Revision.new(self, @revisions.length, content, created_at, author)
end
web.refresh_pages_with_references(name) if @revisions.length == 1
end
|
#revised_on ⇒ Object
40
41
42
|
# File 'app/models/page.rb', line 40
def revised_on
created_on
end
|
#revisions? ⇒ Boolean
36
37
38
|
# File 'app/models/page.rb', line 36
def revisions?
revisions.length > 1
end
|
#rollback(revision_number, created_at, author_ip = nil) ⇒ Object
31
32
33
34
|
# File 'app/models/page.rb', line 31
def rollback(revision_number, created_at, author_ip = nil)
roll_back_revision = @revisions[revision_number].dup
revise(roll_back_revision.content, created_at, Author.new(roll_back_revision.author, author_ip))
end
|