Sha256: 2dda4156ac5cc4d47a383ae5bfe4a82785119949225c518b5e45de302505f2fd

Contents?: true

Size: 1.01 KB

Versions: 6

Compression:

Stored size: 1.01 KB

Contents

# encoding: UTF-8

module Spontaneous::Model::Core
  module PageSearch
    extend Spontaneous::Concern

    module ClassMethods
      # An uncached test for the existance of a site home/root page.
      def has_root?
        content_model.filter(:path => Spontaneous::SLASH).count > 0
      end

      def root
        path(Spontaneous::SLASH)
      end

      def id(id)
        first_visible("id:#{id}", :id => id)
      end

      def uid(uid)
        first_visible("uid:#{uid}", :uid => uid)
      end

      def path(path)
        first_visible("path:#{path}", :path => path)
      end

      def first_visible(cache_key, params)
        mapper.with_cache(cache_key) {
          page = content_model.first(params)
          # don't want to return nil if a page matching the params exists but is hidden
          # if we return blank we force searches via other routes (such as aliased pages)
          return false if page and mapper.visible_only? and page.hidden?
          page
        }
      end
    end # ClassMethods
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta10 lib/spontaneous/model/core/page_search.rb
spontaneous-0.2.0.beta9 lib/spontaneous/model/core/page_search.rb
spontaneous-0.2.0.beta8 lib/spontaneous/model/core/page_search.rb
spontaneous-0.2.0.beta7 lib/spontaneous/model/core/page_search.rb
spontaneous-0.2.0.beta6 lib/spontaneous/model/core/page_search.rb
spontaneous-0.2.0.beta5 lib/spontaneous/model/core/page_search.rb