Sha256: 3815444efe4794690bd90c398f67d1b3437638fb72e8c8066d476159283982a1

Contents?: true

Size: 1.24 KB

Versions: 16

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module Alchemy
  module CacheDigests
    class TemplateTracker
      def self.call(name, template)
        new(name, template).dependencies
      end

      def initialize(name, template)
        @name, @template = name, template
      end

      def dependencies
        case @name.to_s
        when /^alchemy\/pages\/show/
          PageLayout.all.map { |p| "alchemy/page_layouts/_#{p['name']}" }
        when /^alchemy\/page_layouts\/_(\w+)/
          page_layout = PageLayout.get($1)
          layout_elements = page_layout.fetch('elements', [])
          layout_elements.map { |name| "alchemy/elements/_#{name}_view" } +
            layout_elements.map { |name| "alchemy/elements/_#{name}" }
        when /^alchemy\/elements\/_(\w+)_view/, /^alchemy\/elements\/_(\w+)/
          essence_types($1).map { |name|
            "alchemy/essences/_#{name.underscore}_view"
          }.uniq
        else
          ActionView::DependencyTracker::ERBTracker.call(@name, @template)
        end
      end

      private

      def essence_types(name)
        element = Element.definitions.detect { |e| e['name'] == name }
        return [] unless element
        element.fetch('contents', []).collect { |c| c['type'] }
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
alchemy_cms-4.6.7 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-4.6.6 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-4.6.5 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-4.5.1 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-4.4.5 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-4.6.4 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-4.6.3 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-4.6.2 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-4.6.1 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-4.6.0 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-4.5.0 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-4.4.4 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-4.4.3 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-4.4.2 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-4.4.1 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-4.4.0 lib/alchemy/cache_digests/template_tracker.rb