Module: Cms::Concerns::Addressable
- Defined in:
- lib/cms/concerns/can_be_addressable.rb
Defined Under Namespace
Modules: ClassMethods, DeprecatedPageAccessors, DynamicPath, MarkAsDirty, NodeAccessors
Class Method Summary collapse
-
.classes_that_require_custom_routes ⇒ Object
Returns all classes which need a custom route to show themselves.
-
.descendants ⇒ Array<Class>
List of all classes that can be in the sitemap.
Instance Method Summary collapse
-
#accessible_to_guests?(public_sections, parent) ⇒ Boolean
Resources are accessible to guests if their parent section is.
-
#ancestors(options = {}) ⇒ Array<Addressable>
Returns a list of all Addressable objects that are ancestors to this record.
- #cache_parent(section) ⇒ Object
-
#destroy_node ⇒ Object
Allows for manual destruction of node.
-
#landing_page? ⇒ Boolean
Whether or not this content is the ‘landing’ page for its section.
-
#page_title ⇒ String
Returns the value that will appear in the <title> element of the page when this content is rendered.
- #parent ⇒ Object
- #parent=(sec) ⇒ Object
- #parent_id ⇒ Object
- #parent_id=(id) ⇒ Object
-
#partial_for ⇒ Object
Computes the name of the partial used to render this object in the sitemap.
Class Method Details
.classes_that_require_custom_routes ⇒ Object
Returns all classes which need a custom route to show themselves.
183 184 185 |
# File 'lib/cms/concerns/can_be_addressable.rb', line 183 def self.classes_that_require_custom_routes descendants.select { |klass| klass.path != nil } end |
.descendants ⇒ Array<Class>
List of all classes that can be in the sitemap.
190 191 192 |
# File 'lib/cms/concerns/can_be_addressable.rb', line 190 def self.descendants ObjectSpace.each_object(::Class).select { |klass| klass < Cms::Concerns::Addressable } end |
Instance Method Details
#accessible_to_guests?(public_sections, parent) ⇒ Boolean
Resources are accessible to guests if their parent section is. Variables are passed in for performance reasons since this gets called ‘MANY’ times on the sitemap.
178 179 180 |
# File 'lib/cms/concerns/can_be_addressable.rb', line 178 def accessible_to_guests?(public_sections, parent) public_sections.include?(parent) end |
#ancestors(options = {}) ⇒ Array<Addressable>
Returns a list of all Addressable objects that are ancestors to this record.
225 226 227 228 229 230 231 |
# File 'lib/cms/concerns/can_be_addressable.rb', line 225 def ancestors(={}) return [] unless node ancestor_nodes = node.ancestors ancestors = ancestor_nodes.collect { |node| node.node } ancestors << self if [:include_self] ancestors end |
#cache_parent(section) ⇒ Object
238 239 240 |
# File 'lib/cms/concerns/can_be_addressable.rb', line 238 def cache_parent(section) @parent = section end |
#destroy_node ⇒ Object
Allows for manual destruction of node
195 196 197 |
# File 'lib/cms/concerns/can_be_addressable.rb', line 195 def destroy_node node.destroy end |
#landing_page? ⇒ Boolean
Whether or not this content is the ‘landing’ page for its section.
202 203 204 |
# File 'lib/cms/concerns/can_be_addressable.rb', line 202 def landing_page? false end |
#page_title ⇒ String
Returns the value that will appear in the <title> element of the page when this content is rendered. Subclasses can override this.
216 217 218 |
# File 'lib/cms/concerns/can_be_addressable.rb', line 216 def page_title name end |
#parent ⇒ Object
233 234 235 236 |
# File 'lib/cms/concerns/can_be_addressable.rb', line 233 def parent @parent if @parent node ? node.section : nil end |
#parent=(sec) ⇒ Object
255 256 257 258 259 260 261 |
# File 'lib/cms/concerns/can_be_addressable.rb', line 255 def parent=(sec) if node node.move_to_end(sec) else build_section_node(:node_id => self.id, :section => sec) end end |
#parent_id ⇒ Object
242 243 244 |
# File 'lib/cms/concerns/can_be_addressable.rb', line 242 def parent_id parent.try(:id) end |
#parent_id=(id) ⇒ Object
246 247 248 249 250 251 252 253 |
# File 'lib/cms/concerns/can_be_addressable.rb', line 246 def parent_id=(id) self.parent = Cms::Section.find(id) # Handles slug being set before there is a parent if @slug self.slug = @slug @slug = nil end end |
#partial_for ⇒ Object
Computes the name of the partial used to render this object in the sitemap.
264 265 266 |
# File 'lib/cms/concerns/can_be_addressable.rb', line 264 def partial_for self.class.name.demodulize.underscore end |