Sha256: 95ae2bc63fd4a58c4d84bb2d992b26fe6f18b6392dee68bf5e4d66f0384ac2f3

Contents?: true

Size: 1.14 KB

Versions: 48

Compression:

Stored size: 1.14 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}" }
        when /^alchemy\/elements\/_(\w+)/
          ingredient_types($1).map { |type|
            "alchemy/ingredients/_#{type.underscore}_view"
          }.uniq
        else
          ActionView::DependencyTracker::ERBTracker.call(@name, @template)
        end
      end

      private

      def ingredient_types(name)
        element = Element.definitions.detect { |e| e["name"] == name }
        return [] unless element

        element.fetch("ingredients", []).collect { |c| c["type"] }
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
alchemy_cms-7.3.4 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-7.3.3 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-7.3.2 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-7.2.7 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-7.3.1 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-7.3.0 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-7.2.6 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-7.2.5 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-7.1.12 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-7.0.15 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-7.2.4 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-7.1.11 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-7.2.3 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-7.1.10 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-7.2.2 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-7.1.9 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-7.0.14 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-7.2.1 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-7.0.13 lib/alchemy/cache_digests/template_tracker.rb
alchemy_cms-7.1.8 lib/alchemy/cache_digests/template_tracker.rb