Sha256: 688a4417971835ad6863b1b3553744df7bc6b2926f2bcf69d0943235b42e86e7

Contents?: true

Size: 1.7 KB

Versions: 3

Compression:

Stored size: 1.7 KB

Contents

module Locomotive
  module Liquid
    module Tags
      class Extends < ::Liquid::Extends

        def prepare_parsing
          super

          parent_page = @context[:parent_page]

          @context[:page].merge_editable_elements_from_page(parent_page)

          @context[:snippets] = parent_page.snippet_dependencies
          @context[:templates] = ([*parent_page.template_dependencies] + [parent_page.id]).compact
        end

        private

        def parse_parent_template
          if @template_name == 'parent'
            if @context[:cached_parent]
              @context[:parent_page] = @context[:cached_parent] #.clone # parent must not be modified

              @context[:cached_parent].instance_variable_set(:@template, nil) # force to reload the template
              @context[:cached_parent] = nil
            else
              @context[:parent_page] = @context[:page].parent
            end
          else
            @context[:parent_page] = @context[:cached_pages].try(:[], @template_name) ||
              @context[:site].pages.where(:fullpath => @template_name).first
          end

          raise PageNotFound.new("Page with fullpath '#{@template_name}' was not found") if @context[:parent_page].nil?

          # be sure to work with a copy of the parent template otherwise there will be conflicts
          parent_template = @context[:parent_page].template.try(:clone)

          raise PageNotTranslated.new("Page with fullpath '#{@template_name}' was not translated") if parent_template.nil?

          @context[:parent_page].instance_variable_set(:@template, parent_template)

          parent_template
        end

      end

      ::Liquid::Template.register_tag('extends', Extends)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
locomotive_cms-2.0.0.rc6 lib/locomotive/liquid/tags/extends.rb
locomotive_cms-2.0.0.rc5 lib/locomotive/liquid/tags/extends.rb
locomotive_cms-2.0.0.rc4 lib/locomotive/liquid/tags/extends.rb