Class: ActiveadminSelleoCms::Page

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ContentTranslation
Defined in:
app/models/activeadmin_selleo_cms/page.rb

Defined Under Namespace

Classes: Translation

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ContentTranslation

#create_missing_translations, included, #initialize_missing_translations, #translated_attribute

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



143
144
145
# File 'app/models/activeadmin_selleo_cms/page.rb', line 143

def method_missing(sym, *args)
  sections.with_name(sym.to_s).first
end

Class Method Details

.update_positions(page_ids) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
# File 'app/models/activeadmin_selleo_cms/page.rb', line 122

def self.update_positions(page_ids)
  begin
    ActiveRecord::Base.transaction do
      page_ids.each_cons(2) do |pair|
        Page.find(pair.last).move_to_right_of(Page.find(pair.first))
      end
    end
    return true
  rescue
    return false
  end
end

Instance Method Details



106
107
108
# File 'app/models/activeadmin_selleo_cms/page.rb', line 106

def breadcrumb
  self_and_ancestors.map{|p| p.translated_attribute(:title, I18n.default_locale)}.join(' » ').html_safe
end

#create_missing_sectionsObject



76
77
78
79
80
# File 'app/models/activeadmin_selleo_cms/page.rb', line 76

def create_missing_sections
  section_names.each do |section_name|
    sections.create(name: section_name) unless sections.detect{|section| section.name == section_name}
  end
end

#go_back_pageObject



135
136
137
138
139
140
141
# File 'app/models/activeadmin_selleo_cms/page.rb', line 135

def go_back_page
  if parent and !parent.redirect_to_first_sub_page
    parent
  elsif parent
    parent.go_back_page
  end
end

#initialize_missing_sectionsObject



70
71
72
73
74
# File 'app/models/activeadmin_selleo_cms/page.rb', line 70

def initialize_missing_sections
  section_names.each do |section_name|
    sections.build(name: section_name) unless sections.detect{|section| section.name == section_name}
  end
end

#layoutObject



94
95
96
# File 'app/models/activeadmin_selleo_cms/page.rb', line 94

def layout
  Layout.find(layout_name)
end

#rootsObject



102
103
104
# File 'app/models/activeadmin_selleo_cms/page.rb', line 102

def roots
  Page.published.roots
end

#section_namesObject



90
91
92
# File 'app/models/activeadmin_selleo_cms/page.rb', line 90

def section_names
  layout.section_names
end

#set_nest(translation) ⇒ Object



66
67
68
# File 'app/models/activeadmin_selleo_cms/page.rb', line 66

def set_nest(translation)
  translation.activeadmin_selleo_cms_page ||= self
end

#to_labelObject



86
87
88
# File 'app/models/activeadmin_selleo_cms/page.rb', line 86

def to_label
  "#{'- ' * depth.to_i} #{title}"
end

#to_paramObject



98
99
100
# File 'app/models/activeadmin_selleo_cms/page.rb', line 98

def to_param
  parent ? "#{parent.to_param}/#{slug}" : slug
end

#to_sObject



82
83
84
# File 'app/models/activeadmin_selleo_cms/page.rb', line 82

def to_s
  title
end

#url(options = {locale: true}) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
# File 'app/models/activeadmin_selleo_cms/page.rb', line 110

def url(options={locale: true})
  _url = if is_link_url
    link_url
  elsif redirect_to_first_sub_page and children.published.any?
    "/:locale/#{children.published.first.to_param}"
  else
    "/:locale/#{to_param}"
  end
  _url = _url.gsub(':locale', I18n.locale.to_s) if _url.match(/:locale/) and options[:locale]
  _url
end