mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
41c0681fb7
This leaves Ripper tracker as an optional view dependency tracker, but uses the current ERBTracker by default. Eventually the default can change to the Ripper tracker, but this makes it an optional update for now
40 lines
962 B
Ruby
40 lines
962 B
Ruby
# frozen_string_literal: true
|
|
|
|
require "concurrent/map"
|
|
require "action_view/path_set"
|
|
require "action_view/render_parser"
|
|
|
|
module ActionView
|
|
class DependencyTracker # :nodoc:
|
|
extend ActiveSupport::Autoload
|
|
|
|
autoload :ERBTracker
|
|
autoload :RipperTracker
|
|
|
|
@trackers = Concurrent::Map.new
|
|
|
|
def self.find_dependencies(name, template, view_paths = nil)
|
|
tracker = @trackers[template.handler]
|
|
return [] unless tracker
|
|
|
|
tracker.call(name, template, view_paths)
|
|
end
|
|
|
|
def self.register_tracker(extension, tracker)
|
|
handler = Template.handler_for_extension(extension)
|
|
if tracker.respond_to?(:supports_view_paths?)
|
|
@trackers[handler] = tracker
|
|
else
|
|
@trackers[handler] = lambda { |name, template, _|
|
|
tracker.call(name, template)
|
|
}
|
|
end
|
|
end
|
|
|
|
def self.remove_tracker(handler)
|
|
@trackers.delete(handler)
|
|
end
|
|
|
|
register_tracker :erb, ERBTracker
|
|
end
|
|
end
|