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

Class Method Details

.update_positions(page_ids) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/models/activeadmin_selleo_cms/page.rb', line 119

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



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

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

#create_missing_sectionsObject



73
74
75
76
77
# File 'app/models/activeadmin_selleo_cms/page.rb', line 73

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



132
133
134
135
136
137
138
# File 'app/models/activeadmin_selleo_cms/page.rb', line 132

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



67
68
69
70
71
# File 'app/models/activeadmin_selleo_cms/page.rb', line 67

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



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

def layout
  @layout ||= Layout.find(layout_name)
end

#rootsObject



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

def roots
  Page.published.roots
end

#section_namesObject



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

def section_names
  @section_names ||= layout.section_names
end

#set_nest(translation) ⇒ Object



63
64
65
# File 'app/models/activeadmin_selleo_cms/page.rb', line 63

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

#to_labelObject



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

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

#to_paramObject



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

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

#to_sObject



79
80
81
# File 'app/models/activeadmin_selleo_cms/page.rb', line 79

def to_s
  title
end

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



107
108
109
110
111
112
113
114
115
116
117
# File 'app/models/activeadmin_selleo_cms/page.rb', line 107

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