Sha256: acdb9444cb963864757f588c416cae8a9bbf544bb019b856246975299a05a0db

Contents?: true

Size: 1001 Bytes

Versions: 7

Compression:

Stored size: 1001 Bytes

Contents

module PufferPages
  module Liquid
    class PageDrop < ::Liquid::Drop

      def initialize page, request = nil
        @page, @request = page, request
      end

      (%w(name title description keywords created_at updated_at) + Page.statuses.map{|s| "#{s}?"}).each do |attribute|
        define_method attribute do
          @page.send(attribute)
        end
      end

      def parent
        @parent ||= self.class.new(@page.parent, @request)
      end

      %w(children ancestors).each do |attribute|
        define_method attribute do
          instance_variable_get("@#{attribute}") || instance_variable_set("@#{attribute}", @page.send(attribute).map{ |page| self.class.new(page, @request)})
        end
      end

      def ancestors?
        !@page.root?
      end

      def children?
        @page.children.present?
      end

      def path
        @page.location
      end

      def url
        @url ||= @request.protocol + @request.host_with_port + path
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
puffer_pages-0.0.7 lib/puffer_pages/liquid/page_drop.rb
puffer_pages-0.0.6 lib/puffer_pages/liquid/page_drop.rb
puffer_pages-0.0.5 lib/puffer_pages/liquid/page_drop.rb
puffer_pages-0.0.4 lib/puffer_pages/liquid/page_drop.rb
puffer_pages-0.0.3 lib/puffer_pages/liquid/page_drop.rb
puffer_pages-0.0.2 lib/puffer_pages/liquid/page_drop.rb
puffer_pages-0.0.1 lib/puffer_pages/liquid/page_drop.rb