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) ⇒ Page
Returns a new instance of Page.
13
14
15
16
17
|
# File 'app/models/page.rb', line 13
def initialize(web, name)
raise 'nil web' if web.nil?
raise 'nil name' if name.nil?
@web, @name, @revisions = web, name, []
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
116
117
118
|
# File 'app/models/page.rb', line 116
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
105
106
107
|
# File 'app/models/page.rb', line 105
def author_link(options = {})
@web.make_link(author, nil, options)
end
|
#authors ⇒ Object
75
76
77
|
# File 'app/models/page.rb', line 75
def authors
revisions.collect { |rev| rev.author }
end
|
#categories ⇒ Object
71
72
73
|
# File 'app/models/page.rb', line 71
def categories
display_content.find_chunks(Category).map { |cat| cat.list }.flatten
end
|
#id ⇒ Object
97
98
99
|
# File 'app/models/page.rb', line 97
def id
@id ||= name.unpack('H*').first
end
|
#in_category?(cat) ⇒ Boolean
67
68
69
|
# File 'app/models/page.rb', line 67
def in_category?(cat)
cat.nil? || cat.empty? || categories.include?(cat)
end
|
#included_from ⇒ Object
87
88
89
|
# File 'app/models/page.rb', line 87
def included_from
@web.select.pages_that_include(name)
end
|
#link(options = {}) ⇒ Object
101
102
103
|
# File 'app/models/page.rb', line 101
def link(options = {})
@web.make_link(name, nil, options)
end
|
#linked_from ⇒ Object
83
84
85
|
# File 'app/models/page.rb', line 83
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”.
92
93
94
|
# File 'app/models/page.rb', line 92
def plain_name
@web.brackets_only ? name : WikiWords.separate(name)
end
|
#references ⇒ Object
79
80
81
|
# File 'app/models/page.rb', line 79
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'app/models/page.rb', line 19
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
Revision.new(self, @revisions.length, content, created_at, author).force_rendering
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
self
end
|
#revised_on ⇒ Object
63
64
65
|
# File 'app/models/page.rb', line 63
def revised_on
created_on
end
|
#revisions? ⇒ Boolean
59
60
61
|
# File 'app/models/page.rb', line 59
def revisions?
revisions.length > 1
end
|
#rollback(revision_number, created_at, author_ip = nil) ⇒ Object
54
55
56
57
|
# File 'app/models/page.rb', line 54
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
|