Class: Kuhsaft::Page
Constant Summary
Constants included
from Searchable
Searchable::DICTIONARIES
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Searchable
#update_fulltext
Methods included from BrickList
#brick_types, #collect_fulltext, included, #renders_own_childs?, #to_brick_item_id, #to_brick_list_id, #uploader?, #user_can_add_childs?, #user_can_delete?, #user_can_save?
included
#define_localized_attr_finder, #define_localized_attr_getter, #define_localized_attr_predicate_method, #define_localized_attr_setter, #locale_attr, #locale_for_attr_name, #translate
Methods included from Orderable
included
Class Method Details
.arrange_as_array(options = {}, hash = nil) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
|
# File 'app/models/kuhsaft/page.rb', line 42
def arrange_as_array(options = {}, hash = nil)
hash ||= arrange(options)
arr = []
hash.each do |node, children|
arr << node
arr += arrange_as_array(options, children) unless children.empty?
end
arr
end
|
.by_identifier(identifier) ⇒ Object
54
55
56
|
# File 'app/models/kuhsaft/page.rb', line 54
def by_identifier(identifier)
where(identifier: identifier).first
end
|
.flat_tree ⇒ Object
38
39
40
|
# File 'app/models/kuhsaft/page.rb', line 38
def flat_tree
arrange_as_array
end
|
Instance Method Details
#allowed_brick_types ⇒ Object
144
145
146
|
# File 'app/models/kuhsaft/page.rb', line 144
def allowed_brick_types
Kuhsaft::BrickType.enabled.pluck(:class_name) - ['Kuhsaft::AccordionItemBrick']
end
|
#as_json ⇒ Object
152
153
154
155
156
157
158
|
# File 'app/models/kuhsaft/page.rb', line 152
def as_json
Hash.new.tap do |json|
json['title'] = send("title_#{I18n.locale.to_s.underscore}")
json['pretty_url'] = '/' + send("url_#{I18n.locale.to_s.underscore}")
json['url'] = "/pages/#{id}"
end
end
|
#brick_list_type ⇒ Object
136
137
138
|
# File 'app/models/kuhsaft/page.rb', line 136
def brick_list_type
'Kuhsaft::Page'
end
|
#cache_key ⇒ Object
148
149
150
|
# File 'app/models/kuhsaft/page.rb', line 148
def cache_key
super + bricks.map(&:cache_key).join
end
|
#create_slug ⇒ Object
117
118
119
120
121
122
123
|
# File 'app/models/kuhsaft/page.rb', line 117
def create_slug
if title.present? && slug.blank?
self.slug = title.downcase.parameterize
elsif slug.present?
self.slug = slug.downcase
end
end
|
#create_url ⇒ Object
113
114
115
|
# File 'app/models/kuhsaft/page.rb', line 113
def create_url
self.url = url_with_locale[1..-1]
end
|
#link ⇒ Object
87
88
89
90
91
92
93
|
# File 'app/models/kuhsaft/page.rb', line 87
def link
if bricks.count == 0 && children.count > 0
children.first.link
else
url_with_locale
end
end
|
#nesting_name ⇒ Object
130
131
132
133
134
|
# File 'app/models/kuhsaft/page.rb', line 130
def nesting_name
num_dashes = parent_pages.size
num_dashes = 0 if num_dashes < 0
"#{'-' * num_dashes} #{title}".strip
end
|
#parent_pages ⇒ Object
79
80
81
|
# File 'app/models/kuhsaft/page.rb', line 79
def parent_pages
ancestors
end
|
#path_segments ⇒ Object
TODO: needs naming and routing refactoring (url/locale/path/slug)
96
97
98
99
100
|
# File 'app/models/kuhsaft/page.rb', line 96
def path_segments
paths = parent.present? ? parent.path_segments : []
paths << slug unless navigation?
paths
end
|
#state_class ⇒ Object
67
68
69
|
# File 'app/models/kuhsaft/page.rb', line 67
def state_class
published? ? 'published' : 'unpublished'
end
|
#to_style_class ⇒ Object
140
141
142
|
# File 'app/models/kuhsaft/page.rb', line 140
def to_style_class
'kuhsaft-page'
end
|
#translated? ⇒ Boolean
83
84
85
|
# File 'app/models/kuhsaft/page.rb', line 83
def translated?
url.present? && title.present? && slug.present?
end
|
#update_child_urls ⇒ Object
125
126
127
128
|
# File 'app/models/kuhsaft/page.rb', line 125
def update_child_urls
return unless children.any?
children.each { |child| child.update_attributes(url: child.create_url) }
end
|
#url_with_locale ⇒ Object
106
107
108
109
110
111
|
# File 'app/models/kuhsaft/page.rb', line 106
def url_with_locale
opts = { locale: I18n.locale }
url = url_without_locale
opts[:url] = url if url.present?
page_path(opts)
end
|
#url_without_locale ⇒ Object
102
103
104
|
# File 'app/models/kuhsaft/page.rb', line 102
def url_without_locale
path_segments.join('/')
end
|
#without_self ⇒ Object
59
60
61
|
# File 'app/models/kuhsaft/page.rb', line 59
def without_self
self.class.where 'id != ?', id
end
|