Class Page
In: app/models/page.rb
Parent: ActiveRecord::Base

Methods

Public Class methods

[Source]

     # File app/models/page.rb, line 245
245:   def self.find_live_by_path(path)
246:     published.not_archived.first(:conditions => {:path => path})
247:   end

Public Instance methods

[Source]

    # File app/models/page.rb, line 56
56:   def after_build_new_version(new_version)
57:     copy_connectors(
58:       :from_version_number => @copy_connectors_from_version || (new_version.version - 1),
59:       :to_version_number => new_version.version
60:     )
61:     @copy_connectors_from_version = nil
62:     true
63:   end

Publish all

[Source]

    # File app/models/page.rb, line 66
66:   def after_publish
67:     self.reload # Get's the correct version number loaded
68:     self.connectors.for_page_version(self.version).all(:order => "position").each do |c| 
69:       if c.connectable_type.constantize.publishable? && con = c.connectable
70:         con.publish
71:       end
72:     end
73:   end

[Source]

     # File app/models/page.rb, line 221
221:   def ancestors
222:     section_node.ancestors
223:   end

[Source]

     # File app/models/page.rb, line 194
194:   def append_leading_slash_to_path
195:     if path.blank?
196:       self.path = "/"
197:     elsif path[0,1] != "/"
198:       self.path = "/#{path}"
199:     end
200:   end

[Source]

     # File app/models/page.rb, line 266
266:   def assigned_to
267:     current_task ? current_task.assigned_to : nil
268:   end

[Source]

     # File app/models/page.rb, line 270
270:   def assigned_to?(user)
271:     assigned_to == user
272:   end

Returns the number of connectables in the given container for this version of this page

[Source]

     # File app/models/page.rb, line 241
241:   def connectable_count_for_container(container)
242:     connectors.for_page_version(version).in_container(container.to_s).count
243:   end

Returns true if the block attached to each connector in the given container are published

[Source]

     # File app/models/page.rb, line 234
234:   def container_published?(container)
235:     connectors.for_page_version(draft.version).in_container(container.to_s).all? do |c| 
236:       c.connectable_type.constantize.publishable? ? c.connectable.live? : true
237:     end
238:   end

[Source]

     # File app/models/page.rb, line 75
 75:   def copy_connectors(options={})
 76:     connectors.for_page_version(options[:from_version_number]).all(:order => "connectors.container, connectors.position").each do |c|
 77:       # The connector won't have a connectable if it has been deleted
 78:       # Also need to see if the draft has been deleted,
 79:       # in which case we are in the process of deleting it
 80:       if c.should_be_copied?
 81:         connectable = c.connectable_type.constantize.versioned? ? c.connectable.as_of_version(c.connectable_version) : c.connectable
 82:       
 83:         #If we are copying connectors from a previous version, that means we are reverting this page,
 84:         #in which case we should create a new version of the block, and connect this page to that block
 85:         if @copy_connectors_from_version && connectable.class.versioned? && (connectable.version != connectable.draft.version)
 86:           connectable = connectable.class.find(connectable.id)
 87:           connectable.updated_by_page = self
 88:           connectable.revert_to(c.connectable_version)
 89:         end      
 90:       
 91:         new_connector = connectors.build(
 92:           :page_version => options[:to_version_number], 
 93:           :connectable => connectable, 
 94:           :connectable_version => connectable.class.versioned? ? connectable.version : nil,         
 95:           :container => c.container, 
 96:           :position => c.position
 97:         )
 98:       end
 99:     end
100:     true
101:   end

[Source]

     # File app/models/page.rb, line 103
103:   def create_connector(connectable, container)
104:     transaction do
105:       raise "Connectable is nil" unless connectable
106:       raise "Container is required" if container.blank?
107:       update_attributes(
108:         :version_comment => "#{connectable} was added to the '#{container}' container",
109:         :publish_on_save => (
110:           published? && 
111:           connectable.connected_page && 
112:           (connectable.class.publishable? ? connectable.published? : true)))
113:       connectors.create(
114:         :page_version => draft.version,
115:         :connectable => connectable,
116:         :connectable_version => connectable.class.versioned? ? connectable.version : nil, 
117:         :container => container)      
118:     end
119:   end

[Source]

     # File app/models/page.rb, line 262
262:   def current_task
263:     tasks.incomplete.first
264:   end

[Source]

     # File app/models/page.rb, line 151
151:   def delete_connectors
152:     connectors.for_page_version(version).all.each{|c| c.destroy }
153:   end

[Source]

     # File app/models/page.rb, line 162
162:   def file_size
163:     "?"
164:   end

[Source]

     # File app/models/page.rb, line 225
225:   def in_section?(section_or_section_name)
226:     sec = section_or_section_name.is_a?(String) ? 
227:       Section.first(:conditions => {:name => section_or_section_name}) : 
228:       section_or_section_name
229:     fn = lambda{|s| s ? (s == sec || fn.call(s.parent)) : false}
230:     fn.call(section)
231:   end

[Source]

     # File app/models/page.rb, line 208
208:   def layout
209:     template_file_name && "templates/#{template_file_name.split('.').first}"
210:   end

[Source]

     # File app/models/page.rb, line 121
121:   def move_connector(connector, direction)
122:     transaction do
123:       raise "Connector is nil" unless connector
124:       raise "Direction is nil" unless direction
125:       orientation = direction[/_/] ? "#{direction.sub('_', ' the ')} of" : "#{direction} within"
126:       update_attributes(:version_comment => "#{connector.connectable} was moved #{orientation} the '#{connector.container}' container")
127:       connectors.for_page_version(draft.version).like(connector).first.send("move_#{direction}")
128:     end    
129:   end

[Source]

     # File app/models/page.rb, line 249
249:   def name_with_section_path
250:     a = ancestors
251:     (a[1..a.size].map{|a| a.name} + [name]).join(" / ")
252:   end

[Source]

     # File app/models/page.rb, line 190
190:   def page_title
191:     title.blank? ? name : title
192:   end

[Source]

     # File app/models/page.rb, line 202
202:   def path_not_reserved
203:     if Cms.reserved_paths.include?(path)
204:       errors.add(:path, "is invalid, '#{path}' a reserved path")
205:     end
206:   end

[Source]

     # File app/models/page.rb, line 186
186:   def public?
187:     section ? section.public? : false
188:   end

[Source]

     # File app/models/page.rb, line 137
137:   def remove_connector(connector)
138:     transaction do
139:       raise "Connector is nil" unless connector
140:       update_attributes(:version_comment => "#{connector.connectable} was removed from the '#{connector.container}' container")
141:       
142:       #The logic of this is to go ahead and let the container get copied forward, then delete the new connector
143:       if new_connector = connectors.for_page_version(draft.version).like(connector).first
144:         new_connector.destroy
145:       else
146:         raise "Error occurred while trying to remove connector #{connector.id}"
147:       end
148:     end
149:   end

This is done to let copy_connectors know which version to pull from copy_connectors will get called later as an after_update callback

[Source]

     # File app/models/page.rb, line 157
157:   def revert_to(version)
158:     @copy_connectors_from_version = version
159:     super(version)
160:   end

[Source]

     # File app/models/page.rb, line 170
170:   def section
171:     section_node ? section_node.section : nil
172:   end

[Source]

     # File app/models/page.rb, line 178
178:   def section=(sec)
179:     if section_node
180:       section_node.move_to_end(sec)
181:     else
182:       build_section_node(:node => self, :section => sec)
183:     end      
184:   end

[Source]

     # File app/models/page.rb, line 166
166:   def section_id
167:     section ? section.id : nil
168:   end

[Source]

     # File app/models/page.rb, line 174
174:   def section_id=(sec_id)
175:     self.section = Section.find(sec_id)
176:   end

This will be nil if it is a file system based template

[Source]

     # File app/models/page.rb, line 213
213:   def template
214:     PageTemplate.find_by_file_name(template_file_name)
215:   end

[Source]

     # File app/models/page.rb, line 217
217:   def template_name
218:     template_file_name && PageTemplate.display_name(template_file_name)
219:   end

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.

[Source]

     # File app/models/page.rb, line 257
257:   def top_level_section
258:     a = ancestors
259:     (a.size > 0 && ancestors[1]) ? ancestors[1] : Section.root.first
260:   end

[Validate]