Class: Page

Inherits:
Object
  • Object
show all
Includes:
PageLock
Defined in:
app/models/page.rb

Constant Summary collapse

CONTINOUS_REVISION_PERIOD =

30 minutes

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.



15
16
17
18
# File 'app/models/page.rb', line 15

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 (private)

Forward method calls to the current revision, so the page responds to all revision calls



88
89
90
# File 'app/models/page.rb', line 88

def method_missing(method_symbol)
  revisions.last.send(method_symbol)
end

Instance Attribute Details

#last_visitedObject

Returns the value of attribute last_visited.



12
13
14
# File 'app/models/page.rb', line 12

def last_visited
  @last_visited
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'app/models/page.rb', line 12

def name
  @name
end

#revisionsObject (readonly)

Returns the value of attribute revisions.



13
14
15
# File 'app/models/page.rb', line 13

def revisions
  @revisions
end

#viewedObject

Returns the value of attribute viewed.



12
13
14
# File 'app/models/page.rb', line 12

def viewed
  @viewed
end

#webObject (readonly)

Returns the value of attribute web.



13
14
15
# File 'app/models/page.rb', line 13

def web
  @web
end

Instance Method Details



74
75
76
# File 'app/models/page.rb', line 74

def author_link(options = {})
  web.make_link(author, nil, options)
end

#authorsObject



57
58
59
# File 'app/models/page.rb', line 57

def authors
  revisions.collect { |rev| rev.author }
end

#categoriesObject



53
54
55
# File 'app/models/page.rb', line 53

def categories
  display_content.find_chunks(Category).map { |cat| cat.list }.flatten
end

#in_category?(cat) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/models/page.rb', line 49

def in_category?(cat)
  cat.nil? || cat.empty? || categories.include?(cat)
end


70
71
72
# File 'app/models/page.rb', line 70

def link(options = {})
  web.make_link(name, nil, options)
end

#plain_nameObject

Returns the original wiki-word name as separate words, so “MyPage” becomes “My Page”.



66
67
68
# File 'app/models/page.rb', line 66

def plain_name
  WikiWords.separate(name, web.brackets_only)
end

#pretty_revised_onObject



45
46
47
# File 'app/models/page.rb', line 45

def pretty_revised_on
  DateTime.new(revised_on.year, revised_on.mon, revised_on.day).strftime "%B %e, %Y" 
end

#referencesObject



61
62
63
# File 'app/models/page.rb', line 61

def references
  web.select.pages_that_reference(name)
end

#revise(content, created_at, author) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/page.rb', line 20

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_onObject



41
42
43
# File 'app/models/page.rb', line 41

def revised_on
  created_on
end

#revisions?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'app/models/page.rb', line 37

def revisions?
  revisions.length > 1
end

#rollback(revision_number, created_at, author_ip = nil) ⇒ Object



32
33
34
35
# File 'app/models/page.rb', line 32

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