Class: Page
Constant Summary
Constants included
from PageLock
PageLock::LOCKING_PERIOD
Instance Attribute Summary collapse
Attributes included from PageLock
#locked_by
Instance Method Summary
collapse
Methods included from PageLock
#lock, #lock_duration, #locked?, #unlock
Constructor Details
#initialize(web, name, content, created_at, author) ⇒ Page
Returns a new instance of Page.
13
14
15
16
|
# File 'app/models/page.rb', line 13
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
108
109
110
|
# File 'app/models/page.rb', line 108
def method_missing(method_symbol)
revisions.last.send(method_symbol)
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
10
11
12
|
# File 'app/models/page.rb', line 10
def name
@name
end
|
#revisions ⇒ Object
Returns the value of attribute revisions.
11
12
13
|
# File 'app/models/page.rb', line 11
def revisions
@revisions
end
|
#web ⇒ Object
Returns the value of attribute web.
10
11
12
|
# File 'app/models/page.rb', line 10
def web
@web
end
|
Instance Method Details
#author_link(options = {}) ⇒ Object
97
98
99
|
# File 'app/models/page.rb', line 97
def author_link(options = {})
@web.make_link(author, nil, options)
end
|
#authors ⇒ Object
67
68
69
|
# File 'app/models/page.rb', line 67
def authors
revisions.collect { |rev| rev.author }
end
|
#categories ⇒ Object
63
64
65
|
# File 'app/models/page.rb', line 63
def categories
display_content.find_chunks(Category).map { |cat| cat.list }.flatten
end
|
#id ⇒ Object
89
90
91
|
# File 'app/models/page.rb', line 89
def id
@id ||= name.unpack('H*').first
end
|
#in_category?(cat) ⇒ Boolean
59
60
61
|
# File 'app/models/page.rb', line 59
def in_category?(cat)
cat.nil? || cat.empty? || categories.include?(cat)
end
|
#included_from ⇒ Object
79
80
81
|
# File 'app/models/page.rb', line 79
def included_from
@web.select.pages_that_include(name)
end
|
#link(options = {}) ⇒ Object
93
94
95
|
# File 'app/models/page.rb', line 93
def link(options = {})
@web.make_link(name, nil, options)
end
|
#linked_from ⇒ Object
75
76
77
|
# File 'app/models/page.rb', line 75
def linked_from
@web.select.pages_that_link_to(name)
end
|
#plain_name ⇒ Object
Returns the original wiki-word name as separate words, so “MyPage” becomes “My Page”.
84
85
86
|
# File 'app/models/page.rb', line 84
def plain_name
@web.brackets_only ? name : WikiWords.separate(name)
end
|
#references ⇒ Object
71
72
73
|
# File 'app/models/page.rb', line 71
def references
@web.select.pages_that_reference(name)
end
|
#revise(content, created_at, author) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'app/models/page.rb', line 18
def revise(content, created_at, author)
if not @revisions.empty? and content == @revisions.last.content
raise Instiki::ValidationError.new(
"You have tried to save page '#{name}' without changing its content")
end
if !@revisions.empty? && continous_revision?(created_at, author)
@revisions.last.created_at = created_at
@revisions.last.content = content
@revisions.last.clear_display_cache
else
@revisions << Revision.new(self, @revisions.length, content, created_at, author)
end
self.revisions.last.force_rendering
self.revisions.last.clear_display_cache
@web.refresh_pages_with_references(@name) if @revisions.length == 1
end
|
#revised_on ⇒ Object
55
56
57
|
# File 'app/models/page.rb', line 55
def revised_on
created_on
end
|
#revisions? ⇒ Boolean
51
52
53
|
# File 'app/models/page.rb', line 51
def revisions?
revisions.length > 1
end
|
#rollback(revision_number, created_at, author_ip = nil) ⇒ Object
46
47
48
49
|
# File 'app/models/page.rb', line 46
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
|