Sha256: f35c9d0299a8cedead0c6f40ebe781f74daedcdfc25970cb31ebbdc8b0d1631e

Contents?: true

Size: 849 Bytes

Versions: 7

Compression:

Stored size: 849 Bytes

Contents

# encoding: UTF-8

module Spontaneous::Plugins::Site
  module Selectors
    extend ActiveSupport::Concern

    module ClassMethods
      def root
        Spontaneous::Page.root
      end

      def [](path_or_uid)
        case path_or_uid
        when Fixnum, /\A\d+\z/o
          by_id(path_or_uid)
        when /^\//o
          by_path(path_or_uid)
        when /^#/o
          by_uid(path_or_uid[1..-1])
        else
          by_uid(path_or_uid)
        end
      end

      def by_id(id)
        Spontaneous::Page[id]
      end

      def by_path(path)
        Spontaneous::Page.path(path)
      end

      def by_uid(uid)
        Spontaneous::Page.uid(uid)
      end

      def method_missing(method, *args)
        if page = self[method.to_s]
          page
        else
          super
        end
      end
    end # ClassMethods
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spontaneous-0.2.0.alpha7 lib/spontaneous/plugins/site/selectors.rb
spontaneous-0.2.0.alpha6 lib/spontaneous/plugins/site/selectors.rb
spontaneous-0.2.0.alpha5 lib/spontaneous/plugins/site/selectors.rb
spontaneous-0.2.0.alpha4 lib/spontaneous/plugins/site/selectors.rb
spontaneous-0.2.0.alpha3 lib/spontaneous/plugins/site/selectors.rb
spontaneous-0.2.0.alpha2 lib/spontaneous/plugins/site/selectors.rb
spontaneous-0.2.0.alpha1 lib/spontaneous/plugins/site/selectors.rb