Sha256: 278169e89538b06c1cb6d3b4ad633ecf50e06dbb14ffe78cc3bd8ef77e607a8b

Contents?: true

Size: 1.29 KB

Versions: 12

Compression:

Stored size: 1.29 KB

Contents

module Rabl
  # DependencyTracker for ActionView to support cache digest
  class Tracker
    # Matches:
    #   extends "categories/show"
    EXTENDS_DEPENDENCY = /
      extends\s*              # extends, followed by optional whitespace
      \(?                     # start an optional parenthesis for the extends call
      \s*["']([a-z_\/\.]+)    # the template name itself
    /x

    # Matches:
    #   partial "categories/show"
    PARTIAL_DEPENDENCY = /
      partial\s*              # partial, followed by optional whitespace
      \(?                     # start an optional parenthesis for the partial call
      \s*["']([a-z_\/\.]+)    # the template name itself
    /x

    def self.call(name, template)
      new(name, template).dependencies
    end

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

    def dependencies
      (extends_dependencies + partial_dependencies).uniq
    end

    attr_reader :name, :template
    private :name, :template

    private

      def source
        template.source
      end

      def directory
        name.split("/")[0..-2].join("/")
      end

      def extends_dependencies
        source.scan(EXTENDS_DEPENDENCY).flatten
      end

      def partial_dependencies
        source.scan(PARTIAL_DEPENDENCY).flatten
      end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rabl-0.10.1 lib/rabl/tracker.rb
rabl-0.10.0 lib/rabl/tracker.rb
rabl-0.9.4.pre1 lib/rabl/tracker.rb
rabl-0.9.3 lib/rabl/tracker.rb
rabl-0.9.3.pre1 lib/rabl/tracker.rb
rabl-0.9.2 lib/rabl/tracker.rb
rabl-0.9.1 lib/rabl/tracker.rb
rabl-0.9.0 lib/rabl/tracker.rb
rabl-0.9.0.pre4 lib/rabl/tracker.rb
rabl-0.9.0.pre3 lib/rabl/tracker.rb
rabl-0.9.0.pre2 lib/rabl/tracker.rb
rabl-0.9.0.pre lib/rabl/tracker.rb