Class: Kuhsaft::Page

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
BrickList, Orderable, Searchable, Translatable
Defined in:
app/models/kuhsaft/page.rb

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?

Methods included from Translatable

included, #locale_attr

Methods included from Orderable

included

Class Method Details

.arrange_as_array(options = {}, hash = nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'app/models/kuhsaft/page.rb', line 54

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

.flat_tree(pages = nil) ⇒ Object



50
51
52
# File 'app/models/kuhsaft/page.rb', line 50

def flat_tree(pages = nil)
  arrange_as_array
end

Instance Method Details

#allowed_brick_typesObject



144
145
146
# File 'app/models/kuhsaft/page.rb', line 144

def allowed_brick_types
  Kuhsaft::BrickType.enabled.pluck(:class_name) - ['Kuhsaft::AccordionItemBrick']
end

#brick_list_typeObject



136
137
138
# File 'app/models/kuhsaft/page.rb', line 136

def brick_list_type
  'Kuhsaft::Page'
end

#create_slugObject



125
126
127
128
# File 'app/models/kuhsaft/page.rb', line 125

def create_slug
  has_slug = title.present? && slug.blank?
  self.slug = title.downcase.parameterize if has_slug
end

#create_urlObject



121
122
123
# File 'app/models/kuhsaft/page.rb', line 121

def create_url
  self.url = url_with_locale[1..-1]
end


95
96
97
98
99
100
101
# File 'app/models/kuhsaft/page.rb', line 95

def link
  if bricks.count == 0 && children.count > 0
    children.first.link
  else
    url_with_locale
  end
end

Returns:

  • (Boolean)


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

def navigation?
  page_type == Kuhsaft::PageType::NAVIGATION
end

#nesting_nameObject



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} #{self.title}".strip
end

#parent_pagesObject



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

def parent_pages
  ancestors
end

#path_segmentsObject

TODO: needs naming and routing refactoring (url/locale/path/slug)



104
105
106
107
108
# File 'app/models/kuhsaft/page.rb', line 104

def path_segments
  paths = parent.present? ? parent.path_segments : []
  paths << slug unless navigation?
  paths
end

#published?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'app/models/kuhsaft/page.rb', line 71

def published?
  published == Kuhsaft::PublishState::PUBLISHED
end

#redirect?Boolean

Returns:

  • (Boolean)


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

def redirect?
  page_type == Kuhsaft::PageType::REDIRECT
end

#state_classObject



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

def state_class
  if published?
    'published'
  else
    'unpublished'
  end
end

#to_style_classObject



140
141
142
# File 'app/models/kuhsaft/page.rb', line 140

def to_style_class
  'kuhsaft-page'
end

#url_with_localeObject



114
115
116
117
118
119
# File 'app/models/kuhsaft/page.rb', line 114

def url_with_locale
  opts = { :locale => I18n.locale }
  url = url_without_locale
  opts[:url] = url if url.present?
  page_path(opts)
end

#url_without_localeObject



110
111
112
# File 'app/models/kuhsaft/page.rb', line 110

def url_without_locale
  path_segments.join('/')
end

#without_selfObject



67
68
69
# File 'app/models/kuhsaft/page.rb', line 67

def without_self
  Kuhsaft::Page.where('id != ?', self.id)
end