Module: Locomotive::Extensions::Page::Tree::ClassMethods

Defined in:
app/models/locomotive/extensions/page/tree.rb

Instance Method Summary collapse

Instance Method Details

#_quick_tree(current_page, pages) ⇒ Object

:nodoc:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/models/locomotive/extensions/page/tree.rb', line 71

def _quick_tree(current_page, pages)
  i, children = 0, []

  while !pages.empty?
    page = pages[i]

    break if page.nil?

    if page.parent_id == current_page.id
      page = pages.delete_at(i)

      children << _quick_tree(page, pages)
    else
      i += 1
    end
  end

  current_page.instance_variable_set(:@children, children || [])

  current_page
end

#quick_tree(site, minimal_attributes = true) ⇒ Array

Returns the tree of pages from the site with the most minimal amount of queries. This method should only be used for read-only purpose since the mongodb returns the minimal set of required attributes to build the tree.

Parameters:

Returns:

  • (Array)

    The first array of pages (depth = 0)



58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/locomotive/extensions/page/tree.rb', line 58

def quick_tree(site, minimal_attributes = true)
  pages = (minimal_attributes ? site.pages.unscoped.minimal_attributes : site.pages.unscoped).order_by(:depth.asc, :position.asc).to_a

  tmp = []

  while !pages.empty?
    tmp << _quick_tree(pages.delete_at(0), pages)
  end

  tmp
end