Class: Activa::Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Activa::Page
- Defined in:
- app/models/activa/page.rb
Constant Summary collapse
- MENU_TYPES =
%w(none neighbours children)
Class Method Summary collapse
- .has_root? ⇒ Boolean
-
.move(firstNodeId, secondNodeId, nesting) ⇒ Object
Move node as a neighbour of child of another node.
- .normalize_path(path) ⇒ Object
- .normalize_uri(uri) ⇒ Object
- .retrieve(uri) ⇒ Object
Instance Method Summary collapse
- #draft? ⇒ Boolean
- #inner_pages ⇒ Object
- #neighbours ⇒ Object
- #path ⇒ Object
-
#potential_parents ⇒ Object
Retrieve list of all potential parents pages for current page.
- #publish(params = nil) ⇒ Object
- #published? ⇒ Boolean
- #regenerate_uri! ⇒ Object
- #save_as_draft ⇒ Object
- #to_s ⇒ Object
- #update_as_draft(params) ⇒ Object
Class Method Details
.has_root? ⇒ Boolean
128 129 130 |
# File 'app/models/activa/page.rb', line 128 def has_root? unscoped.count > 0 end |
.move(firstNodeId, secondNodeId, nesting) ⇒ Object
Move node as a neighbour of child of another node
147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'app/models/activa/page.rb', line 147 def move(firstNodeId, secondNodeId, nesting) firstNode = find(firstNodeId) secondNode = find(secondNodeId) if (nesting.to_i == 0) firstNode.move_to_right_of(secondNode) else firstNode.move_to_child_of(secondNode) end return true end |
.normalize_path(path) ⇒ Object
142 143 144 |
# File 'app/models/activa/page.rb', line 142 def normalize_path(path) path.sub(/^\/+/, '') end |
.normalize_uri(uri) ⇒ Object
138 139 140 |
# File 'app/models/activa/page.rb', line 138 def normalize_uri(uri) "/#{uri}".sub(/\/+/, '/') end |
.retrieve(uri) ⇒ Object
132 133 134 135 136 |
# File 'app/models/activa/page.rb', line 132 def retrieve(uri) uri = Activa::Page.normalize_uri(uri) uri = '/' if uri == '/home' Activa::Page.published.find_by_uri(Activa::Page.normalize_uri(uri)) end |
Instance Method Details
#draft? ⇒ Boolean
114 115 116 |
# File 'app/models/activa/page.rb', line 114 def draft? state == 'draft' end |
#inner_pages ⇒ Object
106 107 108 |
# File 'app/models/activa/page.rb', line 106 def inner_pages children.select([:id, :parent_id, :title, :uri, :slug]) end |
#neighbours ⇒ Object
110 111 112 |
# File 'app/models/activa/page.rb', line 110 def neighbours self_and_siblings.select([:id, :parent_id, :title, :uri, :slug]) end |
#path ⇒ Object
102 103 104 |
# File 'app/models/activa/page.rb', line 102 def path root? ? slug : Activa::Page.normalize_path(uri) end |
#potential_parents ⇒ Object
Retrieve list of all potential parents pages for current page
94 95 96 |
# File 'app/models/activa/page.rb', line 94 def potential_parents new_record? ? Activa::Page.published : Activa::Page.published.where("id != ?", id) end |
#publish(params = nil) ⇒ Object
77 78 79 80 81 |
# File 'app/models/activa/page.rb', line 77 def publish(params = nil) self.attributes = params if params self.state = :published save end |
#published? ⇒ Boolean
118 119 120 |
# File 'app/models/activa/page.rb', line 118 def published? state == 'published' end |
#regenerate_uri! ⇒ Object
98 99 100 |
# File 'app/models/activa/page.rb', line 98 def regenerate_uri! update_attribute(:uri, generate_uri) end |
#save_as_draft ⇒ Object
83 84 85 86 |
# File 'app/models/activa/page.rb', line 83 def save_as_draft self.state = :draft save end |
#to_s ⇒ Object
122 123 124 |
# File 'app/models/activa/page.rb', line 122 def to_s title end |
#update_as_draft(params) ⇒ Object
88 89 90 91 |
# File 'app/models/activa/page.rb', line 88 def update_as_draft(params) self.attributes = params save_as_draft end |