Module: Cms::Concerns::Addressable::ClassMethods

Defined in:
lib/cms/concerns/can_be_addressable.rb

Instance Method Summary collapse

Instance Method Details

#addressable?Boolean

Returns Once is_addressable is called, this will always be true.

Returns:

  • (Boolean)

    Once is_addressable is called, this will always be true.



118
119
120
# File 'lib/cms/concerns/can_be_addressable.rb', line 118

def addressable?
  true
end

#base_pathObject

Used in UI forms to show what the complete URL will look like with a slug added to it.



127
128
129
# File 'lib/cms/concerns/can_be_addressable.rb', line 127

def base_path
  "#{self.path}/"
end

#calculate_path(slug) ⇒ Object



122
123
124
# File 'lib/cms/concerns/can_be_addressable.rb', line 122

def calculate_path(slug)
  "#{self.path}/#{slug}"
end

#layoutString

Returns the layout (Page Template) that should be used to render instances of this content. Can be specified as is_addressable template: ‘subpage’

Returns:

  • (String)

    template/default unless template was set.



143
144
145
# File 'lib/cms/concerns/can_be_addressable.rb', line 143

def layout
  normalize_layout(self, @template)
end

#pathString

The base path where new records will be added.

Returns:

  • (String)


113
114
115
# File 'lib/cms/concerns/can_be_addressable.rb', line 113

def path
  @path
end

#requires_slug?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/cms/concerns/can_be_addressable.rb', line 107

def requires_slug?
  !@path.nil?
end

#with_slug(slug) ⇒ Addressable

Find an addressable object with the given content type.

Parameters:

  • slug (String)

Returns:

  • (Addressable)

    The content block with that slug (if it exists). Nil otherwise



135
136
137
138
# File 'lib/cms/concerns/can_be_addressable.rb', line 135

def with_slug(slug)
  section_node = SectionNode.where(slug: slug).where(node_type: self.name).first
  section_node ? section_node.node : nil
end