Class: Page
Constant Summary collapse
- CONTINOUS_REVISION_PERIOD =
30 minutes
30 * 60
Constants included from PageLock
Instance Attribute Summary collapse
-
#last_visited ⇒ Object
Returns the value of attribute last_visited.
-
#name ⇒ Object
Returns the value of attribute name.
-
#revisions ⇒ Object
readonly
Returns the value of attribute revisions.
-
#viewed ⇒ Object
Returns the value of attribute viewed.
-
#web ⇒ Object
readonly
Returns the value of attribute web.
Instance Method Summary collapse
- #author_link(options = {}) ⇒ Object
- #authors ⇒ Object
- #bliki_references ⇒ Object
- #categories ⇒ Object
- #has_todos? ⇒ Boolean
- #in_category?(cat) ⇒ Boolean
-
#initialize(web, name, content, created_at, author) ⇒ Page
constructor
A new instance of Page.
- #link(options = {}) ⇒ Object
-
#plain_name ⇒ Object
Returns the original wiki-word name as separate words, so “MyPage” becomes “My Page”.
- #pretty_revised_on ⇒ Object
- #references ⇒ Object
- #revise(content, created_at, author, edit_type = 'default') ⇒ Object
- #revised_on ⇒ Object
- #revisions? ⇒ Boolean
- #rollback(revision_number, created_at, author_ip = nil) ⇒ Object
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, ) @web, @name, @revisions = web, name, [] revise(content, created_at, ) 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_visited ⇒ Object
Returns the value of attribute last_visited.
12 13 14 |
# File 'app/models/page.rb', line 12 def last_visited @last_visited end |
#name ⇒ Object
Returns the value of attribute name.
12 13 14 |
# File 'app/models/page.rb', line 12 def name @name end |
#revisions ⇒ Object (readonly)
Returns the value of attribute revisions.
13 14 15 |
# File 'app/models/page.rb', line 13 def revisions @revisions end |
#viewed ⇒ Object
Returns the value of attribute viewed.
12 13 14 |
# File 'app/models/page.rb', line 12 def viewed @viewed end |
#web ⇒ Object (readonly)
Returns the value of attribute web.
13 14 15 |
# File 'app/models/page.rb', line 13 def web @web end |
Instance Method Details
#author_link(options = {}) ⇒ Object
92 93 94 |
# File 'app/models/page.rb', line 92 def ( = {}) web.make_link(, nil, ) end |
#authors ⇒ Object
71 72 73 |
# File 'app/models/page.rb', line 71 def revisions.collect { |rev| rev. } end |
#bliki_references ⇒ Object
79 80 81 |
# File 'app/models/page.rb', line 79 def bliki_references web.select_bliki.pages_that_reference(name) end |
#categories ⇒ Object
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
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
63 64 65 |
# File 'app/models/page.rb', line 63 def in_category?(cat) cat.nil? || cat.empty? || categories.include?(cat) end |
#link(options = {}) ⇒ Object
88 89 90 |
# File 'app/models/page.rb', line 88 def link( = {}) web.make_link(name, nil, ) 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 WikiWords.separate(name, web.brackets_only) end |
#pretty_revised_on ⇒ Object
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 |
#references ⇒ Object
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, , edit_type='default') case edit_type when 'major' revise_major(content, created_at, ) when 'minor' if !@revisions.empty? # sanity check revise_minor(content, created_at, ) else revise_major(content, created_at, ) end when 'default' if !@revisions.empty? && continous_revision?(created_at, ) revise_minor(content, created_at, ) else revise_major(content, created_at, ) end else revise_major(content, created_at, ) end 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, = nil) roll_back_revision = @revisions[revision_number].dup revise(roll_back_revision.content, created_at, Author.new(roll_back_revision., )) end |