Class: BillyCms::Page

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Includes:
ActiveModel::Serialization
Defined in:
app/models/billy_cms/page.rb

Instance Method Summary collapse

Instance Method Details

#additional_attribute(attribute_name) ⇒ Object



56
57
58
# File 'app/models/billy_cms/page.rb', line 56

def additional_attribute(attribute_name)
    self.additional_attributes_values[attribute_name.to_s] if self.additional_attributes_values.present?
end

#additional_attributesObject



50
51
52
53
54
# File 'app/models/billy_cms/page.rb', line 50

def additional_attributes
    type = PageType.find_by_name(self.page_type)
    return [] unless type.present?
    type.additional_attributes
end

#binariesObject



29
30
31
# File 'app/models/billy_cms/page.rb', line 29

def binaries
    pages.where(page_type: 'Binary').sort_by(&:order_key)
end

#binary?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'app/models/billy_cms/page.rb', line 46

def binary?
    self.page_type == 'Binary'
end

#boxesObject



25
26
27
# File 'app/models/billy_cms/page.rb', line 25

def boxes
    pages.where(page_type: 'box').sort_by(&:order_key)
end

#childrenObject



17
18
19
# File 'app/models/billy_cms/page.rb', line 17

def children
  pages.sort_by(&:order_key)
end

#cms_pathObject



13
14
15
# File 'app/models/billy_cms/page.rb', line 13

def cms_path
  get_cms_path_component_for_parent '', self
end

#is_in_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
# File 'app/models/billy_cms/page.rb', line 33

def is_in_path?(path)
  if path == '/'
    return slug == 'startseite' ? true : false
  end
  # byebug if id == 6
  reg = Regexp.new("^(#{cms_path})", 'i')
  path.match(reg) != nil
end


21
22
23
# File 'app/models/billy_cms/page.rb', line 21

def navigation
  self.children.reject { |page| page.hide_from_navigation? || page.page_type == 'Binary' || page.page_type == 'box' }
end

#sibblingsObject



42
43
44
# File 'app/models/billy_cms/page.rb', line 42

def sibblings
  self.class.where(parent_page_id: parent_page_id).where.not(id: id).order(:order_key)
end