Class: Kuhsaft::Page

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BrickList

included, #renders_own_childs?, #to_brick_item_id, #to_brick_list_id, #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



29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/kuhsaft/page.rb', line 29

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

.find_by_url(url) ⇒ Object



41
42
43
# File 'app/models/kuhsaft/page.rb', line 41

def find_by_url(url)
  send "find_by_#{locale_attr(:url)}", url
end

.flat_tree(pages = nil) ⇒ Object



25
26
27
# File 'app/models/kuhsaft/page.rb', line 25

def flat_tree(pages = nil)
  arrange_as_array
end

Instance Method Details

#brick_list_typeObject



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

def brick_list_type
  'Kuhsaft::Page'
end

#collect_fulltextObject



96
97
98
# File 'app/models/kuhsaft/page.rb', line 96

def collect_fulltext
  self.fulltext =[super, title.to_s, keywords.to_s, description.to_s].join(' ')
end

#create_slugObject



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

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

#create_urlObject



78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/models/kuhsaft/page.rb', line 78

def create_url
  return if redirect?

  complete_slug = ''
  if parent.present?
    complete_slug << parent.url.to_s
  else
    complete_slug = "#{I18n.locale}"
  end
  complete_slug << "/#{self.slug}" unless navigation?
  self.url = complete_slug
end


66
67
68
69
70
71
72
73
74
75
76
# File 'app/models/kuhsaft/page.rb', line 66

def link
  if bricks.count == 0 && children.count > 0
    children.first.link
  else
    if redirect?
      url
    else
      "/#{url}"
    end
  end
end

Returns:

  • (Boolean)


58
59
60
# File 'app/models/kuhsaft/page.rb', line 58

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

#nesting_nameObject



100
101
102
103
104
# File 'app/models/kuhsaft/page.rb', line 100

def nesting_name
  num_dashes = parent_pages.size
  num_dashes = 0 if num_dashes < 0
  "#{'-' * num_dashes} #{self.title}".strip
end

#parent_pagesObject



62
63
64
# File 'app/models/kuhsaft/page.rb', line 62

def parent_pages
  ancestors
end

#published?Boolean

Returns:

  • (Boolean)


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

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

#redirect?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'app/models/kuhsaft/page.rb', line 54

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

#to_style_classObject



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

def to_style_class
  'kuhsaft-page'
end

#without_selfObject



46
47
48
# File 'app/models/kuhsaft/page.rb', line 46

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