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

Instance Method Summary collapse

Class Method Details

.classes_that_require_custom_routesObject

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

.descendantsArray<Class>

List of all classes that can be in the sitemap.

Returns:

  • (Array<Class>)

    Returns all classes which inherit from Cms::Concerns::Addressable



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.

Parameters:

Returns:

  • (Boolean)


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.

Parameters:

  • options (Hash) (defaults to: {})
  • [Symbol] (Hash)

    a customizable set of options

Returns:

  • (Array<Addressable>)

    Or [] if no ancestors and/or has no parent.



225
226
227
228
229
230
231
# File 'lib/cms/concerns/can_be_addressable.rb', line 225

def ancestors(options={})
  return [] unless node
  ancestor_nodes = node.ancestors
  ancestors = ancestor_nodes.collect { |node| node.node }
  ancestors << self if options[: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_nodeObject

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.

Returns:

  • (Boolean)

    false always, since a content block won’t ever be the landing page for the section



202
203
204
# File 'lib/cms/concerns/can_be_addressable.rb', line 202

def landing_page?
  false
end

#page_titleString

Returns the value that will appear in the <title> element of the page when this content is rendered. Subclasses can override this.

Examples:

Override the page title

class MyWidget < ActiveRecord::Base
  def page_title
    "My Widget | #{name}"
  end
end

Returns:

  • (String)


216
217
218
# File 'lib/cms/concerns/can_be_addressable.rb', line 216

def page_title
  name
end

#parentObject



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_idObject



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_forObject

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