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.0.0.rc9 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.0.0.rc8 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.0.0.rc6 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.0.0.rc4 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.0.0.rc3 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.0.0.rc2 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.0.0.rc1 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.0.0.pre.beta.3 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.0.0.pre.beta.2 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.0.0.pre.beta.1 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.0.0.pre.alpha.3 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.0.0.pre.alpha.2 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.0.0.pre.alpha.1 lib/locomotive/steam/liquid/tags/fetch_page.rb
locomotivecms_steam-1.0.0.pre.alpha lib/locomotive/steam/liquid/tags/fetch_page.rb