class ActionView::Digestor

Parent:
Object

Public Class Methods

digest(name:, finder:, dependencies: []) Show source
# File actionview/lib/action_view/digestor.rb, line 22
def digest(name,, finder,, dependencies: [])
  dependencies ||= []
  cache_key = [ name, finder.rendered_format, dependencies ].flatten.compact.join('.')

  # this is a correctly done double-checked locking idiom
  # (Concurrent::Map's lookups have volatile semantics)
  finder.digest_cache[cache_key] || @@digest_mutex.synchronize do
    finder.digest_cache.fetch(cache_key) do # re-check under lock
      partial = name.include?("/_")
      root = tree(name, finder, partial)
      dependencies.each do |injected_dep|
        root.children << Injected.new(injected_dep, nil, nil)
      end
      finder.digest_cache[cache_key] = root.digest(finder)
    end
  end
end

Supported options:

  • name - Template name

  • finder - An instance of ActionView::LookupContext

  • dependencies - An array of dependent views

  • partial - Specifies whether the template is a partial

logger() Show source
# File actionview/lib/action_view/digestor.rb, line 40
def logger
  ActionView::Base.logger || NullLogger
end
tree(name, finder, partial = false, seen = {}) Show source
# File actionview/lib/action_view/digestor.rb, line 45
def tree(name, finder, partial = false, seen = {})
  logical_name = name.gsub(%r|/_|, "/")

  options = {}
  options[:formats] = [finder.rendered_format] if finder.rendered_format

  if template = finder.disable_cache { finder.find_all(logical_name, [], partial, [], options).first }
    finder.rendered_format ||= template.formats.first

    if node = seen[template.identifier] # handle cycles in the tree
      node
    else
      node = seen[template.identifier] = Node.create(name, logical_name, template, partial)

      deps = DependencyTracker.find_dependencies(name, template, finder.view_paths)
      deps.uniq { |n| n.gsub(%r|/_|, "/") }.each do |dep_file|
        node.children << tree(dep_file, finder, true, seen)
      end
      node
    end
  else
    logger.error "  '#{name}' file doesn't exist, so no dependencies"
    logger.error "  Couldn't find template for digesting: #{name}"
    seen[name] ||= Missing.new(name, logical_name, nil)
  end
end

Create a dependency tree for template named name.

© 2004–2018 David Heinemeier Hansson
Licensed under the MIT License.