- A
- C
- D
- F
- G
- H
- I
- P
- R
- S
-
- seo,
- seo=,
- siblings,
- slug=,
- split_path
- U
- RankedModel
[RW] | is_root | |
[RW] | parent_url |
Arrange array of nodes into a nested hash of the form {node => children}, where children = {} if the node has no children
Example: {#<Cardboard::Page => {
#<Cardboard::Page => {} #<Cardboard::Page => {} #<Cardboard::Page => {#<Cardboard::Page => {}}
}}
Source: show
# File app/models/cardboard/page.rb, line 186 def self.arrange(root_page = nil) root_page = self.root if root_page.nil? @lock.synchronize do @_arranged_pages ||= {} @_arranged_pages[root_page.id.to_s] ||= begin pages = self.preordered.all pages.inject(ActiveSupport::OrderedHash.new) do |ordered_hash, page| (["/"] + page.split_path).inject(ordered_hash) do |insertion_hash, subpath| insertion_hash.each do |parent, children| insertion_hash = children if subpath == parent.slug end insertion_hash end[page] = ActiveSupport::OrderedHash.new ordered_hash end end end end
Source: show
# File app/models/cardboard/page.rb, line 207 def self.clear_arranged_pages # clear cache when a page change @lock.synchronize do @_arranged_pages = nil end end
class methods
Source: show
# File app/models/cardboard/page.rb, line 58 def self.find_by_url(full_url) path, slug = self.path_and_slug(full_url) page = self.where(path: path, slug: slug).first if slug && page.nil? #use arel instead of LIKE/ILIKE page = self.where(path: path).where(self.arel_table[:slugs_backup].matches("% #{slug}\n%")).first page.using_slug_backup = true if page end page end
Source: show
# File app/models/cardboard/page.rb, line 75 def self.homepage; self.root; end
Source: show
# File app/models/cardboard/page.rb, line 71 def self.root # Homepage is the highest position in the root path where(path: "/").rank(:position).first end
Source: show
# File app/models/cardboard/page.rb, line 164 def children Cardboard::Page.where(path: url) end
Source: show
# File app/models/cardboard/page.rb, line 172 def depth # root is depth 0 split_path.size end
slideshow = @page.get(“slideshow”) slideshow.field(“image1”) slideshow.each{|p| p.field(“image”)} slideshow.get(“slide1”)
Source: show
# File app/models/cardboard/page.rb, line 92 def get(field) f = field.split(".") parent_part = self.parts.where(identifier: f.first).first part = parent_part.try(:subparts) return nil unless part if parent_part.repeatable? raise "Part is repeatable, expected each loop" unless f.size == 1 part else f.size == 1 ? part.first : part.first.attr(f.last) end end
Source: show
# File app/models/cardboard/page.rb, line 45 def is_root=(val) self.position_position = :first if val end
Source: show
# File app/models/cardboard/page.rb, line 132 def parent @parent ||= Cardboard::Page.find_by_url(path) end
Source: show
# File app/models/cardboard/page.rb, line 151 def parent=(new_parent) return nil if new_parent && !new_parent.is_a?(Cardboard::Page) self.path = new_parent ? new_parent.url : "/" end
Source: show
# File app/models/cardboard/page.rb, line 156 def parent_id=(new_parent_id) self.parent = Cardboard::Page.where(identifier: new_parent_id).first end
Source: show
# File app/models/cardboard/page.rb, line 160 def parent_url=(new_parent_url) self.parent = Cardboard::Page.find_by_url(new_parent_url) end
Get all other pages
Source: show
# File app/models/cardboard/page.rb, line 137 def parent_url_options # @parent_url_options ||= begin Cardboard::Page.all.inject(["/"]) do |result, elm| result << elm.url unless elm.id == self.id result end.sort # end end
Source: show
# File app/models/cardboard/page.rb, line 77 def root? @root_id ||= Page.root.id @root_id == self.id end
SEO children inherit their parent’s SEO settings (these can be overwritten)
Source: show
# File app/models/cardboard/page.rb, line 107 def seo @_seo ||= begin seo = self.meta_seo seo = self.parent.seo.merge(seo) if parent seo = Page.root.seo.merge(seo) unless root? seo end end
Source: show
# File app/models/cardboard/page.rb, line 116 def seo=(hash) # to hash is important here for strong parameters self.meta_seo = hash.to_hash @_seo = nil end
Source: show
# File app/models/cardboard/page.rb, line 168 def siblings Cardboard::Page.where("path = ? AND id != ?", path, id) end
overwritten setters/getters
Source: show
# File app/models/cardboard/page.rb, line 40 def slug=(value) # the user can overwrite the auto generated slug self[:slug] = value.present? ? value.to_url : nil end
Source: show
# File app/models/cardboard/page.rb, line 127 def split_path # path.sub(/^\//,'').split("/") # "/path/" => ["path"] path[1..-1].split("/") end
Source: show
# File app/models/cardboard/page.rb, line 122 def url return "/" if slug.blank? #|| self.root? "#{path}#{slug}/" end