Sha256: e2bfac013de49b92ca686197bcde54c75cf8b46302384fefc385ef2ed1d93d83

Contents?: true

Size: 1013 Bytes

Versions: 54

Compression:

Stored size: 1013 Bytes

Contents

module Locomotive
  module Steam
    module Liquid
      module Tags

        # Fetch a page from its handle and assign it to a liquid variable.
        #
        # Usage:
        #
        # {% fetch_page about_us as a_page %}
        # <p>{{ a_page.title }}</p>
        #
        class FetchPage < ::Liquid::Tag

          Syntax = /(#{::Liquid::VariableSignature}+)\s+as\s+(#{::Liquid::VariableSignature}+)/o

          def initialize(tag_name, markup, options)
            if markup =~ Syntax
              @handle, @var = $1, $2
            else
              raise SyntaxError.new("Syntax Error in 'fetch_page' - Valid syntax: fetch_page page_handle as variable")
            end

            super
          end

          def render(context)
            page = context.registers[:repositories].page.by_handle(@handle)
            context.scopes.last[@var] = page
            ''
          end
        end

        ::Liquid::Template.register_tag('fetch_page'.freeze, FetchPage)
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
locomotivecms_steam-1.8.0.alpha2 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.8.0.alpha1 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.7.1 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.7.0 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.6.1 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.6.0 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.6.0.rc1 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.6.0.beta1 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.5.3 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.5.2 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.5.1 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.5.0 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.5.0.rc1 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.5.0.rc0 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.5.0.beta3 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.5.0.beta2 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.5.0.beta1 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.4.1 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.4.0 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.4.0.rc2 lib/locomotive/steam/liquid/tags/fetch_page.rb