Class: Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Page
- Includes:
- Elasticsearch::Model, Elasticsearch::Model::Callbacks, PublicActivity::Common
- Defined in:
- app/models/page.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#old_ancestor_ids ⇒ Object
Returns the value of attribute old_ancestor_ids.
Instance Method Summary collapse
- #as_indexed_json(options = {}) ⇒ Object
- #last_updated ⇒ Object
- #reorder!(options) ⇒ Object
- #save_and_destroy(deleted_by) ⇒ Object
- #to_param ⇒ Object
- #touch_ancestry ⇒ Object
- #type ⇒ Object
- #update_to_gollum(user) ⇒ Object
- #versions ⇒ Object
- #wiki_dir ⇒ Object
Instance Attribute Details
#old_ancestor_ids ⇒ Object
Returns the value of attribute old_ancestor_ids.
37 38 39 |
# File 'app/models/page.rb', line 37 def old_ancestor_ids @old_ancestor_ids end |
Instance Method Details
#as_indexed_json(options = {}) ⇒ Object
101 102 103 104 105 106 107 |
# File 'app/models/page.rb', line 101 def as_indexed_json( = {}) json = self.as_json json[:body] = Nokogiri::HTML(self.body || "").text json[:tag] = self.tag_list json[:type] = self.class.to_s.underscore json end |
#last_updated ⇒ Object
74 75 76 77 78 79 80 |
# File 'app/models/page.rb', line 74 def last_updated activities. where(key: 'page.update_details'). order("created_at desc").first || activities.where(key: 'page.created'). order("created_at desc").first end |
#reorder!(options) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'app/models/page.rb', line 86 def reorder!() if [:parent_id] self.old_ancestor_ids = self.ancestor_ids self.parent_id = [:parent_id] self.save end self.insert_at [:position].to_i self.save end |
#save_and_destroy(deleted_by) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/models/page.rb', line 109 def save_and_destroy(deleted_by) # let's get this page and all child pages and attachments # let's save them to deleted_items # let's delete them all self.children.each do |child| child.save_and_destroy(deleted_by) end self..each do || .save_and_destroy(deleted_by) end DeletedItem.save_and_destroy(self, deleted_by) end |
#to_param ⇒ Object
48 49 50 |
# File 'app/models/page.rb', line 48 def to_param [id, title.parameterize].join("-") end |
#touch_ancestry ⇒ Object
96 97 98 99 |
# File 'app/models/page.rb', line 96 def touch_ancestry self.old_ancestor_ids ||= [] Page.where(id: (ancestor_ids + old_ancestor_ids).uniq).update_all(updated_at: Time.now) end |
#type ⇒ Object
70 71 72 |
# File 'app/models/page.rb', line 70 def type @type || "Page" end |
#update_to_gollum(user) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/models/page.rb', line 56 def update_to_gollum(user) commit = { message: 'no message', name: user.name, email: user.email } body_page = "#{id}-body" title_page = "#{id}-title" $wiki.write_page("/" + body_page, :textile, body, commit, wiki_dir) $wiki.write_page("/" + title_page, :textile, title, commit, wiki_dir) end |
#versions ⇒ Object
82 83 84 |
# File 'app/models/page.rb', line 82 def versions $wiki.page("#{id}-body", nil, wiki_dir).try(:versions) || [] end |
#wiki_dir ⇒ Object
52 53 54 |
# File 'app/models/page.rb', line 52 def wiki_dir "/wiki/#{id}" end |