Class: ActiveadminSelleoCms::Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ActiveadminSelleoCms::Page
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
#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
#breadcrumb ⇒ Object
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_sections ⇒ Object
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_page ⇒ Object
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_sections ⇒ Object
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
|
#layout ⇒ Object
91
92
93
|
# File 'app/models/activeadmin_selleo_cms/page.rb', line 91
def layout
@layout ||= Layout.find(layout_name)
end
|
#roots ⇒ Object
99
100
101
|
# File 'app/models/activeadmin_selleo_cms/page.rb', line 99
def roots
Page.published.roots
end
|
#section_names ⇒ Object
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_label ⇒ Object
83
84
85
|
# File 'app/models/activeadmin_selleo_cms/page.rb', line 83
def to_label
"#{'- ' * depth} #{title}"
end
|
#to_param ⇒ Object
95
96
97
|
# File 'app/models/activeadmin_selleo_cms/page.rb', line 95
def to_param
parent ? "#{parent.to_param}/#{slug}" : slug
end
|
#to_s ⇒ Object
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
|