Methods
A
C
D
F
G
H
I
P
R
S
U
Included Modules
Attributes
[RW] is_root
[RW] parent_url
Class Public methods
arrange(root_page = nil)

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 => {}}

}}

# 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
clear_arranged_pages()
# 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
find_by_url(full_url)

class methods

# 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
homepage()
# File app/models/cardboard/page.rb, line 75
def self.homepage; self.root; end
root()
# 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
Instance Public methods
children()
# File app/models/cardboard/page.rb, line 164
def children
  Cardboard::Page.where(path: url)
end
depth()
# File app/models/cardboard/page.rb, line 172
def depth
  # root is depth 0
  split_path.size
end
get(field)

slideshow = @page.get(“slideshow”) slideshow.field(“image1”) slideshow.each{|p| p.field(“image”)} slideshow.get(“slide1”)

# 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
is_root=(val)
# File app/models/cardboard/page.rb, line 45
def is_root=(val)
  self.position_position = :first if val
end
parent()
# File app/models/cardboard/page.rb, line 132
def parent
  @parent ||= Cardboard::Page.find_by_url(path)
end
parent=(new_parent)
# 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
parent_id=(new_parent_id)
# 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
parent_url=(new_parent_url)
# 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
parent_url_options()

Get all other pages

# 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
root?()
# File app/models/cardboard/page.rb, line 77
def root?
  @root_id ||= Page.root.id
  @root_id == self.id
end
seo()

SEO children inherit their parent’s SEO settings (these can be overwritten)

# 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
seo=(hash)
# 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
siblings()
# File app/models/cardboard/page.rb, line 168
def siblings
  Cardboard::Page.where("path = ? AND id != ?", path, id)
end
slug=(value)

overwritten setters/getters

# 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
split_path()
# File app/models/cardboard/page.rb, line 127
def split_path
  # path.sub(/^\//,'').split("/") # "/path/" => ["path"]
  path[1..-1].split("/")
end
url()
# File app/models/cardboard/page.rb, line 122
def url
  return "/" if slug.blank? #|| self.root?
  "#{path}#{slug}/"
end
using_slug_backup=(value)
# File app/models/cardboard/page.rb, line 53
def using_slug_backup=(value)
  @using_slug_backup = value
end
using_slug_backup?()
# File app/models/cardboard/page.rb, line 49
def using_slug_backup?
  @using_slug_backup || false
end