Sha256: 7b81c0f7beff31364ae9d9d88b4cc23174d0e71d9e2a714280a42e2795d2bd85

Contents?: true

Size: 1.55 KB

Versions: 39

Compression:

Stored size: 1.55 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'
            @context[:parent_page] = @context[:cached_parent] || @context[:page].parent
          else
            locale = ::Mongoid::Fields::I18n.locale

            @context[:parent_page] = @context[:cached_pages].try(:[], @template_name) ||
              @context[:site].pages.where("fullpath.#{locale}" => @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?

          # force the page to restore the original version of its template (from the serialized version)
          @context[:parent_page].instance_variable_set(:@template, nil)

          parent_template
        end

      end

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

Version data entries

39 entries across 39 versions & 3 rubygems

Version Path
locomotive_cms-2.5.7 lib/locomotive/liquid/tags/extends.rb
locomotivecms-3.0.0.pre.alpha.2 lib/locomotive/previous_liquid/tags/extends.rb
locomotivecms-3.0.0.pre.alpha lib/locomotive/previous_liquid/tags/extends.rb
locomotive_cms-2.5.6 lib/locomotive/liquid/tags/extends.rb
locomotive_cms-2.5.6.rc2 lib/locomotive/liquid/tags/extends.rb
locomotive_cms-2.5.6.rc1 lib/locomotive/liquid/tags/extends.rb
locomotive_cms-2.5.5 lib/locomotive/liquid/tags/extends.rb
locomotive_cms-2.5.4 lib/locomotive/liquid/tags/extends.rb
locomotive_cms-2.5.3 lib/locomotive/liquid/tags/extends.rb
locomotive_cms-2.5.2 lib/locomotive/liquid/tags/extends.rb
locomotive_cms-2.5.1 lib/locomotive/liquid/tags/extends.rb
locomotive_cms-2.5.0 lib/locomotive/liquid/tags/extends.rb
locomotive_cms-2.5.0.rc3 lib/locomotive/liquid/tags/extends.rb
locomotive_cms-2.5.0.rc2 lib/locomotive/liquid/tags/extends.rb
locomotive_cms-2.5.0.rc1 lib/locomotive/liquid/tags/extends.rb
locomotive_cms-2.4.1 lib/locomotive/liquid/tags/extends.rb
locomotive_cms-2.4.0 lib/locomotive/liquid/tags/extends.rb
locomotive_cms-2.3.1 lib/locomotive/liquid/tags/extends.rb
locomotive_cms-2.3.0 lib/locomotive/liquid/tags/extends.rb
locomotive_cms-2.2.3 lib/locomotive/liquid/tags/extends.rb