Sha256: 1465d6f6926e0319e0d3f827aa65fc5c5a95162616c424e8232aee6a32993be9

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

# encoding: UTF-8

module Spontaneous::Model::Page
  module SiteMap
    extend Spontaneous::Concern

    # InstanceMethods
    def map_children
      self.children.map { |c| c.map_entry }
    end

    def map_entry
      shallow_map_entry.merge({
        :children => grouped_page_list(self.children),
        :generation => grouped_page_list(self.generation),
        :ancestors => self.ancestors.map {|c| c.shallow_map_entry }
      })
    end

    def grouped_page_list(pages)
      Hash.new { |hash, key| hash[key] = [] }.tap { |map|
        pages.each do |p|
          return {:Root => [p.shallow_map_entry]} if p.container.nil? # guard for site root
          map[p.container._prototype.title] << p.shallow_map_entry
        end
      }
    end

    def shallow_map_entry
      {
        :id => id,
        :title => fields.title.value,
        :path => path,
        :slug => slug,
        :type => self.class.ui_class,
        :type_id => self.class.schema_id,
        :children => self.children.length,
        :depth => depth
      }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta5 lib/spontaneous/model/page/site_map.rb
spontaneous-0.2.0.beta4 lib/spontaneous/model/page/site_map.rb
spontaneous-0.2.0.beta3 lib/spontaneous/model/page/site_map.rb
spontaneous-0.2.0.beta2 lib/spontaneous/model/page/site_map.rb
spontaneous-0.2.0.beta1 lib/spontaneous/model/page/site_map.rb