Class: Page
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from SectionNode
#move_after, #move_before, #move_to, #move_to_beginning, #move_to_end, #node, #page?, #path, #public?, #root?, #section?, #visible?
Class Method Details
.find_live_by_path(path) ⇒ Object
249
250
251
|
# File 'app/models/page.rb', line 249
def self.find_live_by_path(path)
published.not_archived.first(:conditions => {:path => path})
end
|
.versioned_columns ⇒ Object
303
304
305
306
|
# File 'app/models/page.rb', line 303
def self.versioned_columns
@versioned_columns ||= (self.new.attributes.keys -
(%w[ancestry lock_version position version_comment created_at updated_at created_by_id updated_by_id type] + [version_foreign_key]))
end
|
Instance Method Details
#after_build_new_version(new_version) ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'app/models/page.rb', line 59
def after_build_new_version(new_version)
copy_connectors(
:from_version_number => @copy_connectors_from_version || (new_version.version - 1),
:to_version_number => new_version.version
)
@copy_connectors_from_version = nil
true
end
|
#after_publish ⇒ Object
69
70
71
72
73
74
75
76
|
# File 'app/models/page.rb', line 69
def after_publish
self.reload self.connectors.for_page_version(self.version).all(:order => "position").each do |c|
if c.connectable_type.constantize.publishable? && con = c.connectable
con.publish
end
end
end
|
#ancestors ⇒ Object
225
226
227
|
# File 'app/models/page.rb', line 225
def ancestors
section_node.ancestors
end
|
#append_leading_slash_to_path ⇒ Object
198
199
200
201
202
203
204
|
# File 'app/models/page.rb', line 198
def append_leading_slash_to_path
if path.blank?
self.path = "/"
elsif path[0,1] != "/"
self.path = "/#{path}"
end
end
|
#assigned_to ⇒ Object
270
271
272
|
# File 'app/models/page.rb', line 270
def assigned_to
current_task ? current_task.assigned_to : nil
end
|
#assigned_to?(user) ⇒ Boolean
274
275
276
|
# File 'app/models/page.rb', line 274
def assigned_to?(user)
assigned_to == user
end
|
#connectable_count_for_container(container) ⇒ Object
Returns the number of connectables in the given container for this version of this page
245
246
247
|
# File 'app/models/page.rb', line 245
def connectable_count_for_container(container)
connectors.for_page_version(version).in_container(container.to_s).count
end
|
#container_published?(container) ⇒ Boolean
Returns true if the block attached to each connector in the given container are published
238
239
240
241
242
|
# File 'app/models/page.rb', line 238
def container_published?(container)
connectors.for_page_version(draft.version).in_container(container.to_s).all? do |c|
c.connectable_type.constantize.publishable? ? c.connectable.live? : true
end
end
|
#copy_connectors(options = {}) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'app/models/page.rb', line 78
def copy_connectors(options={})
connectors.for_page_version(options[:from_version_number]).all(:order => "connectors.container, connectors.position").each do |c|
if c.should_be_copied?
connectable = c.connectable_type.constantize.versioned? ? c.connectable.as_of_version(c.connectable_version) : c.connectable
if @copy_connectors_from_version && connectable.class.versioned? && (connectable.version != connectable.draft.version)
connectable = connectable.class.find(connectable.id)
connectable.updated_by_page = self
connectable.revert_to(c.connectable_version)
end
new_connector = connectors.build(
:page_version => options[:to_version_number],
:connectable => connectable,
:connectable_version => connectable.class.versioned? ? connectable.version : nil,
:container => c.container,
:position => c.position
)
end
end
true
end
|
#create_connector(connectable, container) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'app/models/page.rb', line 106
def create_connector(connectable, container)
transaction do
raise "Connectable is nil" unless connectable
raise "Container is required" if container.blank?
update_attributes(
:version_comment => "#{connectable} was added to the '#{container}' container",
:publish_on_save => (
published? &&
connectable.connected_page &&
(connectable.class.publishable? ? connectable.published? : true)))
connectors.create(
:page_version => draft.version,
:connectable => connectable,
:connectable_version => connectable.class.versioned? ? connectable.version : nil,
:container => container)
end
end
|
#current_task ⇒ Object
266
267
268
|
# File 'app/models/page.rb', line 266
def current_task
tasks.incomplete.first
end
|
#delete_connectors ⇒ Object
154
155
156
|
# File 'app/models/page.rb', line 154
def delete_connectors
connectors.for_page_version(version).all.each{|c| c.destroy }
end
|
#file_size ⇒ Object
165
166
167
|
# File 'app/models/page.rb', line 165
def file_size
"?"
end
|
#in_section?(section_or_section_name) ⇒ Boolean
229
230
231
232
233
234
235
|
# File 'app/models/page.rb', line 229
def in_section?(section_or_section_name)
sec = section_or_section_name.is_a?(String) ?
Section.first(:conditions => {:name => section_or_section_name}) :
section_or_section_name
fn = lambda{|s| s ? (s == sec || fn.call(s.parent)) : false}
fn.call(section)
end
|
#layout ⇒ Object
212
213
214
|
# File 'app/models/page.rb', line 212
def layout
template_file_name && "templates/#{template_file_name.split('.').first}"
end
|
#move_connector(connector, direction) ⇒ Object
124
125
126
127
128
129
130
131
132
|
# File 'app/models/page.rb', line 124
def move_connector(connector, direction)
transaction do
raise "Connector is nil" unless connector
raise "Direction is nil" unless direction
orientation = direction[/_/] ? "#{direction.sub('_', ' the ')} of" : "#{direction} within"
update_attributes(:version_comment => "#{connector.connectable} was moved #{orientation} the '#{connector.container}' container")
connectors.for_page_version(draft.version).like(connector).first.send("move_#{direction}")
end
end
|
#name_with_section_path ⇒ Object
253
254
255
256
|
# File 'app/models/page.rb', line 253
def name_with_section_path
a = ancestors
(a[1..a.size].map{|a| a.name} + [name]).join(" / ")
end
|
#page_title ⇒ Object
moved to section
def public?
section ? section.public? : false
end
194
195
196
|
# File 'app/models/page.rb', line 194
def page_title
title.blank? ? name : title
end
|
#path_not_reserved ⇒ Object
206
207
208
209
210
|
# File 'app/models/page.rb', line 206
def path_not_reserved
if Cms.reserved_paths.include?(path)
errors.add(:path, "is invalid, '#{path}' a reserved path")
end
end
|
#remove_connector(connector) ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'app/models/page.rb', line 140
def remove_connector(connector)
transaction do
raise "Connector is nil" unless connector
update_attributes(:version_comment => "#{connector.connectable} was removed from the '#{connector.container}' container")
if new_connector = connectors.for_page_version(draft.version).like(connector).first
new_connector.destroy
else
raise "Error occurred while trying to remove connector #{connector.id}"
end
end
end
|
#revert_to(version) ⇒ Object
This is done to let copy_connectors know which version to pull from copy_connectors will get called later as an after_update callback
160
161
162
163
|
# File 'app/models/page.rb', line 160
def revert_to(version)
@copy_connectors_from_version = version
super(version)
end
|
#section ⇒ Object
173
174
175
|
# File 'app/models/page.rb', line 173
def section
section_node ? section_node.section : nil
end
|
#section=(sec) ⇒ Object
181
182
183
184
185
186
187
|
# File 'app/models/page.rb', line 181
def section=(sec)
if section_node
section_node.move_to_end(sec)
else
build_section_node(:node => self, :section => sec)
end
end
|
#section_id ⇒ Object
169
170
171
|
# File 'app/models/page.rb', line 169
def section_id
section ? section.id : nil
end
|
#section_id=(sec_id) ⇒ Object
177
178
179
|
# File 'app/models/page.rb', line 177
def section_id=(sec_id)
self.section = Section.find(sec_id)
end
|
#status ⇒ Object
299
300
301
|
# File 'app/models/page.rb', line 299
def status
"asd" end
|
#template ⇒ Object
This will be nil if it is a file system based template
217
218
219
|
# File 'app/models/page.rb', line 217
def template
PageTemplate.find_by_file_name(template_file_name)
end
|
#template_name ⇒ Object
221
222
223
|
# File 'app/models/page.rb', line 221
def template_name
template_file_name && PageTemplate.display_name(template_file_name)
end
|
#top_level_section ⇒ Object
This will return the “top level section” for a page, which is the section directly below the root (a.k.a My Site) that this page is in. If this page is in root, then this will return root.
261
262
263
264
|
# File 'app/models/page.rb', line 261
def top_level_section
a = ancestors
(a.size > 0 && ancestors[1]) ? ancestors[1] : Section.root.first
end
|