Class: Page
Defined Under Namespace
Classes: MissingRootPageError
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
included
Methods included from LocalTime
#adjust_time
included, #render_tag, #tag_descriptions, #tags
Instance Attribute Details
Returns the value of attribute request.
36
37
38
|
# File 'app/models/page.rb', line 36
def request
@request
end
|
Returns the value of attribute response.
36
37
38
|
# File 'app/models/page.rb', line 36
def response
@response
end
|
Class Method Details
.descendant_class(class_name) ⇒ Object
230
231
232
233
234
235
236
237
|
# File 'app/models/page.rb', line 230
def descendant_class(class_name)
raise ArgumentError.new("argument must be a valid descendant of Page") unless is_descendant_class_name?(class_name)
if ["", nil, "Page"].include?(class_name)
Page
else
class_name.constantize
end
end
|
.display_name(string = nil) ⇒ Object
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
# File 'app/models/page.rb', line 180
def display_name(string = nil)
if string
@display_name = string
else
@display_name ||= begin
n = name.to_s
n.sub!(/^(.+?)Page$/, '\1')
n.gsub!(/([A-Z])/, ' \1')
n.strip
end
end
@display_name = @display_name + " - not installed" if missing? && @display_name !~ /not installed/
@display_name
end
|
.display_name=(string) ⇒ Object
194
195
196
|
# File 'app/models/page.rb', line 194
def display_name=(string)
display_name(string)
end
|
.find_by_url(url, live = true) ⇒ Object
174
175
176
177
178
|
# File 'app/models/page.rb', line 174
def find_by_url(url, live = true)
root = find_by_parent_id(nil)
raise MissingRootPageError unless root
root.find_by_url(url, live)
end
|
.is_descendant_class_name?(class_name) ⇒ Boolean
226
227
228
|
# File 'app/models/page.rb', line 226
def is_descendant_class_name?(class_name)
(Page.descendants.map(&:to_s) + [nil, "", "Page"]).include?(class_name)
end
|
.load_subclasses ⇒ Object
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
# File 'app/models/page.rb', line 198
def load_subclasses
([RADIANT_ROOT] + Radiant::Extension.descendants.map(&:root)).each do |path|
Dir["#{path}/app/models/*_page.rb"].each do |page|
$1.camelize.constantize if page =~ %r{/([^/]+)\.rb}
end
end
if ActiveRecord::Base.connection.tables.include?('pages') && Page.column_names.include?('class_name') Page.connection.select_values("SELECT DISTINCT class_name FROM pages WHERE class_name <> '' AND class_name IS NOT NULL").each do |p|
begin
p.constantize
rescue NameError, LoadError
eval(%Q{class #{p} < Page; def self.missing?; true end end}, TOPLEVEL_BINDING)
end
end
end
end
|
.missing? ⇒ Boolean
239
240
241
|
# File 'app/models/page.rb', line 239
def missing?
false
end
|
.new_with_defaults(config = Radiant::Config) ⇒ Object
215
216
217
218
219
220
221
222
223
224
|
# File 'app/models/page.rb', line 215
def new_with_defaults(config = Radiant::Config)
default_parts = config['defaults.page.parts'].to_s.strip.split(/\s*,\s*/)
page = new
default_parts.each do |name|
page.parts << PagePart.new(:name => name, :filter_id => config['defaults.page.filter'])
end
default_status = config['defaults.page.status']
page.status = Status[default_status] if default_status
page
end
|
Instance Method Details
#cache? ⇒ Boolean
57
58
59
|
# File 'app/models/page.rb', line 57
def cache?
true
end
|
#child_url(child) ⇒ Object
61
62
63
|
# File 'app/models/page.rb', line 61
def child_url(child)
clean_url(url + '/' + child.slug)
end
|
#description ⇒ Object
49
50
51
|
# File 'app/models/page.rb', line 49
def description
self["description"]
end
|
#description=(value) ⇒ Object
53
54
55
|
# File 'app/models/page.rb', line 53
def description=(value)
self["description"] = value
end
|
#find_by_url(url, live = true, clean = true) ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'app/models/page.rb', line 145
def find_by_url(url, live = true, clean = true)
return nil if virtual?
url = clean_url(url) if clean
my_url = self.url
if (my_url == url) && (not live or published?)
self
elsif (url =~ /^#{Regexp.quote(my_url)}([^\/]*)/)
slug_child = children.find_by_slug($1)
if slug_child
found = slug_child.find_by_url(url, live, clean)
return found if found
end
children.each do |child|
found = child.find_by_url(url, live, clean)
return found if found
end
file_not_found_types = ([FileNotFoundPage] + FileNotFoundPage.descendants)
file_not_found_names = file_not_found_types.collect { |x| x.name }
condition = (['class_name = ?'] * file_not_found_names.length).join(' or ')
condition = "status_id = #{Status[:published].id} and (#{condition})" if live
children.find(:first, :conditions => [condition] + file_not_found_names)
end
end
|
#has_or_inherits_part?(name) ⇒ Boolean
82
83
84
|
# File 'app/models/page.rb', line 82
def has_or_inherits_part?(name)
has_part?(name) || inherits_part?(name)
end
|
#has_part?(name) ⇒ Boolean
78
79
80
|
# File 'app/models/page.rb', line 78
def has_part?(name)
!part(name).nil?
end
|
65
66
67
68
|
# File 'app/models/page.rb', line 65
def
{ }
end
|
#inherits_part?(name) ⇒ Boolean
86
87
88
|
# File 'app/models/page.rb', line 86
def inherits_part?(name)
!has_part?(name) && self.ancestors.any? { |page| page.has_part?(name) }
end
|
#layout_with_inheritance ⇒ Object
40
41
42
43
44
45
46
|
# File 'app/models/page.rb', line 40
def layout_with_inheritance
unless layout_without_inheritance
parent.layout if parent?
else
layout_without_inheritance
end
end
|
#part(name) ⇒ Object
70
71
72
73
74
75
76
|
# File 'app/models/page.rb', line 70
def part(name)
if new_record? or parts.to_a.any?(&:new_record?)
parts.to_a.find {|p| p.name == name.to_s }
else
parts.find_by_name name.to_s
end
end
|
#process(request, response) ⇒ Object
109
110
111
112
113
114
115
116
117
118
|
# File 'app/models/page.rb', line 109
def process(request, response)
@request, @response = request, response
if layout
content_type = layout.content_type.to_s.strip
@response.['Content-Type'] = content_type unless content_type.empty?
end
.each { |k,v| @response.[k] = v }
@response.body = render
@response.status = response_code
end
|
#published? ⇒ Boolean
90
91
92
|
# File 'app/models/page.rb', line 90
def published?
status == Status[:published]
end
|
124
125
126
127
128
129
130
|
# File 'app/models/page.rb', line 124
def render
if layout
parse_object(layout)
else
render_part(:body)
end
end
|
#render_part(part_name) ⇒ Object
132
133
134
135
136
137
138
139
|
# File 'app/models/page.rb', line 132
def render_part(part_name)
part = part(part_name)
if part
parse_object(part)
else
''
end
end
|
#render_snippet(snippet) ⇒ Object
141
142
143
|
# File 'app/models/page.rb', line 141
def render_snippet(snippet)
parse_object(snippet)
end
|
#response_code ⇒ Object
120
121
122
|
# File 'app/models/page.rb', line 120
def response_code
200
end
|
94
95
96
|
# File 'app/models/page.rb', line 94
def status
Status.find(self.status_id)
end
|
#status=(value) ⇒ Object
97
98
99
|
# File 'app/models/page.rb', line 97
def status=(value)
self.status_id = value.id
end
|
#to_xml(options = {}, &block) ⇒ Object
169
170
171
|
# File 'app/models/page.rb', line 169
def to_xml(options={}, &block)
super(options.reverse_merge(:include => :parts), &block)
end
|
101
102
103
104
105
106
107
|
# File 'app/models/page.rb', line 101
def url
if parent?
parent.child_url(self)
else
clean_url(slug)
end
end
|