Class: UzuUzu::Page

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource, DataMapper::Timestamps
Defined in:
lib/uzuuzu-cms/model/info.rb,
lib/uzuuzu-cms/model/page.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.page_id_tree(parent_page_id = nil) ⇒ Object



81
82
83
# File 'lib/uzuuzu-cms/model/page.rb', line 81

def self.page_id_tree(parent_page_id=nil)
  self.tree(:id, parent_page_id)
end

.page_name_tree(parent_page_id = nil) ⇒ Object



88
89
90
# File 'lib/uzuuzu-cms/model/page.rb', line 88

def self.page_name_tree(parent_page_id=nil)
  self.tree(:name, parent_page_id)
end

.tree(column = nil, parent_page_id = nil) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/uzuuzu-cms/model/page.rb', line 95

def self.tree(column=nil, parent_page_id=nil)
  ary = self.all(:parent_page_id => parent_page_id)
  return nil if ary.nil? or ary.length <= 0
  tree_map = {}
  ary.each do |record|
    child_tree = self.tree(column, record.id)
    if colomn
      key = record.send(column)
    else
      key = self
    end
    tree_map[key] = self.tree(column, record.id)
  end
  tree_map
end

Instance Method Details



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/uzuuzu-cms/model/page.rb', line 66

def breadcrumbs
  _breadcrumbs = []
  tree = reverse_look_up
  while(tree)
    tree.each do |key, value|
      _breadcrumbs.push({:id => key.id, :name => key.name})
      tree = value
    end
  end
  _breadcrumbs.reverse
end

#contents_render(options = {}, locals = {}) ⇒ Object



150
151
152
153
154
155
156
157
# File 'lib/uzuuzu-cms/model/page.rb', line 150

def contents_render(options={}, locals={})
  unless @contents_body
    @contents_body = contents.map do |content|
      content.render(options, locals)
    end.join("\n")
  end
  @contents_body
end

#css_urlsObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/uzuuzu-cms/model/page.rb', line 118

def css_urls
  value = []
  self.csses.each do |css|
    value << css
  end
  value += self.parent.abs_csses if self.parent
  value += self.layout_fix.csses if self.layout_fix
  value += ::UzuUzu.info.csses unless self.parent
  self.contents.each do |content|
    value += content.csses
  end
  value.map do |css|
    css.url
  end
end

#js_urlsObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/uzuuzu-cms/model/page.rb', line 134

def js_urls
  value = []
  self.javascripts.each do |js|
    value << js
  end
  value += self.parent.abs_javascripts if self.parent
  value += self.layout_fix.javascripts if self.layout_fix
  value += ::UzuUzu.info.javascripts unless self.parent
  self.contents.each do |content|
    value += content.javascripts
  end
  value.map do |js|
    js.url
  end
end

#layout_fixObject



111
112
113
114
115
116
# File 'lib/uzuuzu-cms/model/page.rb', line 111

def layout_fix
  value = self.layout
  value ||= self.parent.abs_layout if self.parent
  value ||= ::UzuUzu.info.layout
  value
end

#page_titleObject



159
160
161
# File 'lib/uzuuzu-cms/model/page.rb', line 159

def page_title
  "#{self.title} - #{::UzuUzu.info.title}"
end

#render(options = {}, locals = {}) ⇒ Object



163
164
165
# File 'lib/uzuuzu-cms/model/page.rb', line 163

def render(options={}, locals={})
  self.layout_fix.render(options, locals)
end

#reverse_look_up(column = nil) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/uzuuzu-cms/model/page.rb', line 56

def reverse_look_up(column=nil)
  if column
    key = self.send(column)
  else
    key = self
  end
  child_tree = parent.reverse_look_up(self) if parent
  {key => child_tree}
end