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



109
110
111
# File 'app/models/page.rb', line 109

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



92
93
94
# File 'app/models/page.rb', line 92

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

#authorsObject



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

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

#bliki_referencesObject



79
80
81
# File 'app/models/page.rb', line 79

def bliki_references
  web.select_bliki.pages_that_reference(name)
end

#categoriesObject



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

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

#has_todos?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'app/models/page.rb', line 99

def has_todos?
  not display_content.find_chunks(Todo).empty?
end

#in_category?(cat) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'app/models/page.rb', line 63

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


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

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”.



84
85
86
# File 'app/models/page.rb', line 84

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

#pretty_revised_onObject



59
60
61
# File 'app/models/page.rb', line 59

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

#referencesObject



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

def references
  web.select.pages_that_reference(name)
end

#revise(content, created_at, author, edit_type = 'default') ⇒ Object



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 20

def revise(content, created_at, author, edit_type='default')
  case edit_type
    when 'major'
      revise_major(content, created_at, author)
    
    when 'minor'
      if !@revisions.empty? # sanity check
        revise_minor(content, created_at, author)
      else
        revise_major(content, created_at, author)
      end
      
    when 'default'
      if !@revisions.empty? && continous_revision?(created_at, author)
        revise_minor(content, created_at, author)
      else
        revise_major(content, created_at, author)
      end
      
    else
      revise_major(content, created_at, author)
  end
  
  web.refresh_pages_with_references(name) if @revisions.length == 1
end

#revised_onObject



55
56
57
# File 'app/models/page.rb', line 55

def revised_on
  created_on
end

#revisions?Boolean

Returns:

  • (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