Class: Atreides::Page

Inherits:
Base
  • Object
show all
Includes:
Base::AasmStates, Base::Taggable, Base::Validation, Extendable
Defined in:
app/models/atreides/page.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base::Validation

included

Methods included from Base::AasmStates

included

Methods included from Base::Taggable

included

Methods inherited from Base

#dom_id, #to_param

Class Method Details

.base_classObject



53
54
55
# File 'app/models/atreides/page.rb', line 53

def base_class
  self
end

Instance Method Details

#childrenObject



74
75
76
# File 'app/models/atreides/page.rb', line 74

def children
  @children ||= self.class.find_all_by_parent_id(id)
end

#parentObject



78
79
80
# File 'app/models/atreides/page.rb', line 78

def parent
  @parent ||= parent_of
end

#parentsObject



82
83
84
85
86
87
88
89
90
91
92
# File 'app/models/atreides/page.rb', line 82

def parents
  @parents ||= []
  return @parents unless @parents.empty?

  prnt = self
  while prnt.parent_id?
    prnt = parent_of(prnt)
    @parents << prnt
  end
  @parents
end

#rootObject



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

def root()
  return @root unless @root.nil?
  prnt = self.parent || self
  while prnt.parent_id?
    prnt = parent_of(prnt)
  end
  @root = prnt
end

#thumbnail(size = :thumb) ⇒ Object

Instance Methods



62
63
64
65
66
67
68
69
70
71
# File 'app/models/atreides/page.rb', line 62

def thumbnail(size = :thumb)
  # Find the first thumbnail image
  url = nil
  url = photos.first.image.url(size) unless photos.empty?

  # FIXME: THIS NEEDS TO BE MOVED TO A VIEW/PRESENTER/DECORATOR
  # asset_path('atreides/missing_thumb.png')

  url || "/images/missing_thumb.png"
end

#update_slugObject



44
45
46
47
# File 'app/models/atreides/page.rb', line 44

def update_slug
  # Set slug if not set or changed
  self.slug = title.to_s.parameterize if !slug? or (!new_record? && title_changed?)
end