2017-07-23 11:36:41 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:48:35 -04:00
|
|
|
require "concurrent/map"
|
2017-10-21 09:21:02 -04:00
|
|
|
require "action_view/path_set"
|
2021-04-20 18:36:54 -04:00
|
|
|
require "action_view/render_parser"
|
2012-12-17 15:21:16 -05:00
|
|
|
|
2012-12-16 17:17:53 -05:00
|
|
|
module ActionView
|
2013-12-15 21:51:35 -05:00
|
|
|
class DependencyTracker # :nodoc:
|
2021-04-20 18:36:54 -04:00
|
|
|
extend ActiveSupport::Autoload
|
|
|
|
|
|
|
|
autoload :ERBTracker
|
|
|
|
autoload :RipperTracker
|
|
|
|
|
2015-09-19 09:56:26 -04:00
|
|
|
@trackers = Concurrent::Map.new
|
2012-12-16 17:38:46 -05:00
|
|
|
|
2015-07-15 17:32:45 -04:00
|
|
|
def self.find_dependencies(name, template, view_paths = nil)
|
2012-12-17 15:26:55 -05:00
|
|
|
tracker = @trackers[template.handler]
|
2016-02-10 17:42:09 -05:00
|
|
|
return [] unless tracker
|
2012-12-17 15:26:55 -05:00
|
|
|
|
2016-02-10 17:42:09 -05:00
|
|
|
tracker.call(name, template, view_paths)
|
2012-12-16 17:38:46 -05:00
|
|
|
end
|
|
|
|
|
2013-02-20 10:42:30 -05:00
|
|
|
def self.register_tracker(extension, tracker)
|
|
|
|
handler = Template.handler_for_extension(extension)
|
2016-02-10 17:42:09 -05:00
|
|
|
if tracker.respond_to?(:supports_view_paths?)
|
|
|
|
@trackers[handler] = tracker
|
|
|
|
else
|
|
|
|
@trackers[handler] = lambda { |name, template, _|
|
|
|
|
tracker.call(name, template)
|
|
|
|
}
|
|
|
|
end
|
2012-12-16 17:38:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.remove_tracker(handler)
|
|
|
|
@trackers.delete(handler)
|
2012-12-16 17:17:53 -05:00
|
|
|
end
|
|
|
|
|
2021-08-04 18:34:07 -04:00
|
|
|
register_tracker :erb, ERBTracker
|
2012-12-16 17:17:53 -05:00
|
|
|
end
|
|
|
|
end
|