Class: Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Page
- Defined in:
- app/models/page.rb
Instance Method Summary collapse
- #after_initialize ⇒ Object
- #before_save ⇒ Object
- #default(value, *attrs) ⇒ Object
- #editable_by?(user) ⇒ Boolean
- #editors ⇒ Object
- #is_open_to_all? ⇒ Boolean
- #name ⇒ Object
- #name_before_type_cast ⇒ Object
- #original_author ⇒ Object
- #position ⇒ Object
- #reported_by ⇒ Object
- #revise(author, time, attrs) ⇒ Object
- #text ⇒ Object
- #title ⇒ Object
- #to_headline ⇒ Object
Instance Method Details
#after_initialize ⇒ Object
67 68 69 70 |
# File 'app/models/page.rb', line 67 def after_initialize default('', :name) default('common', :kind) end |
#before_save ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'app/models/page.rb', line 79 def before_save if title == PLACE_HOLDER_TITLE.t revisions.last.title = title_from_kind end write_attribute(:modified_at, self.modified_at) write_attribute(:name, self.name) end |
#default(value, *attrs) ⇒ Object
72 73 74 75 76 77 |
# File 'app/models/page.rb', line 72 def default(value, *attrs) attrs.each do |attr| cur = send(attr) send("#{attr}=".to_sym, value) if cur.nil? || cur.empty? end end |
#editable_by?(user) ⇒ Boolean
137 138 139 140 141 |
# File 'app/models/page.rb', line 137 def editable_by?(user) user == || is_open_to_all? || editors.split.include?(user.login) end |
#editors ⇒ Object
50 51 52 |
# File 'app/models/page.rb', line 50 def editors most_recent(:editors) || '' end |
#is_open_to_all? ⇒ Boolean
95 96 97 |
# File 'app/models/page.rb', line 95 def is_open_to_all? 0 == editors.strip.size end |
#name ⇒ Object
88 |
# File 'app/models/page.rb', line 88 def name; name_before_type_cast; end |
#name_before_type_cast ⇒ Object
89 90 91 92 93 |
# File 'app/models/page.rb', line 89 def name_before_type_cast result = read_attribute(:name) return name_from_title if result.nil? || result.empty? return result end |
#original_author ⇒ Object
34 35 36 |
# File 'app/models/page.rb', line 34 def oldest(:last_editor) end |
#position ⇒ Object
59 60 61 |
# File 'app/models/page.rb', line 59 def position nil end |
#reported_by ⇒ Object
63 64 65 |
# File 'app/models/page.rb', line 63 def reported_by self.kind.pluralize end |
#revise(author, time, attrs) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/models/page.rb', line 99 def revise(, time, attrs) #TODO ugly! ugly! ugly! if !attrs[:happens_at] && attrs['happens_at(1i)'] && attrs['happens_at(2i)'] && attrs['happens_at(3i)'] attrs[:happens_at] = Date.new(attrs['happens_at(1i)'].to_i, attrs['happens_at(2i)'].to_i, attrs['happens_at(3i)'].to_i) end unless revisions.size == 0 || revisions.first.last_editor = revisions.first.save end rev = Revision.new(:last_editor => , :modified_at => time, :position => self.revisions.size + 1) rev.editors = if .can_change_editors?(self) attrs[:editors] else revisions.last.editors end self.kind = attrs[:kind] if attrs[:kind] self.happens_at = attrs[:happens_at] if attrs[:happens_at] rev.kind, rev.happens_at = self.kind, self.happens_at rev.title, rev.text, rev.done = attrs[:title], attrs[:text], attrs[:done] update_references(rev.text) if rev.text self.revisions << rev save self end |
#text ⇒ Object
54 55 56 57 |
# File 'app/models/page.rb', line 54 def text most_recent(:text) || ('MainPage' == self.name ? CONGRATS_TEXT : WIKI_NOT_FOUND_TEXT) end |
#title ⇒ Object
44 45 46 47 48 |
# File 'app/models/page.rb', line 44 def title result = most_recent(:title) return title_from_name || PLACE_HOLDER_TITLE.t if result.nil? || result.empty? return result end |
#to_headline ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'app/models/page.rb', line 128 def to_headline #TODO (for 0.7): headlines and pages should _really_ be the same thing # reporters should write ordinary wiki pages Headline.new(:rid => name, :author => last_editor ? last_editor.login : DEFAULT_AUTHOR, :happened_at => (kind == 'event' ? happens_at.to_t : modified_at) || DEFAULT_TIME, :description => inject_title_into_text) end |