diff options
author | Daniel Schierbeck <dasch@zendesk.com> | 2013-02-20 16:42:30 +0100 |
---|---|---|
committer | Daniel Schierbeck <dasch@zendesk.com> | 2013-02-20 16:42:30 +0100 |
commit | ec23296eb607d7974c7281d520b543640024418f (patch) | |
tree | e8247f22ca8a79567b0e4313c62db05bacdcb95a /actionpack | |
parent | 50703703b4af9730d8e32b69a28ebed877d1b96a (diff) | |
download | rails-ec23296eb607d7974c7281d520b543640024418f.tar.gz rails-ec23296eb607d7974c7281d520b543640024418f.tar.bz2 rails-ec23296eb607d7974c7281d520b543640024418f.zip |
Register trackers on extensions, not handlers
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/dependency_tracker.rb | 17 | ||||
-rw-r--r-- | actionpack/test/template/dependency_tracker_test.rb | 9 | ||||
-rw-r--r-- | actionpack/test/template/digestor_test.rb | 2 |
3 files changed, 17 insertions, 11 deletions
diff --git a/actionpack/lib/action_view/dependency_tracker.rb b/actionpack/lib/action_view/dependency_tracker.rb index 0f380b0ff1..3de5cd150b 100644 --- a/actionpack/lib/action_view/dependency_tracker.rb +++ b/actionpack/lib/action_view/dependency_tracker.rb @@ -14,7 +14,8 @@ module ActionView end end - def self.register_tracker(handler, tracker) + def self.register_tracker(extension, tracker) + handler = Template.handler_for_extension(extension) @trackers[handler] = tracker end @@ -42,26 +43,30 @@ module ActionView /x def self.call(name, template) - new(name, template).call + new(name, template).dependencies end def initialize(name, template) @name, @template = name, template end - def call + def dependencies render_dependencies + explicit_dependencies end private attr_reader :name, :template + def source + template.source + end + def directory name.split("/")[0..-2].join("/") end def render_dependencies - template.source.scan(RENDER_DEPENDENCY). + source.scan(RENDER_DEPENDENCY). collect(&:second).uniq. # render(@topic) => render("topics/topic") @@ -77,10 +82,10 @@ module ActionView end def explicit_dependencies - template.source.scan(EXPLICIT_DEPENDENCY).flatten.uniq + source.scan(EXPLICIT_DEPENDENCY).flatten.uniq end end - register_tracker Template::Handlers::ERB, ERBTracker + register_tracker :erb, ERBTracker end end diff --git a/actionpack/test/template/dependency_tracker_test.rb b/actionpack/test/template/dependency_tracker_test.rb index 714e2d6b29..9c68afbdbd 100644 --- a/actionpack/test/template/dependency_tracker_test.rb +++ b/actionpack/test/template/dependency_tracker_test.rb @@ -2,8 +2,8 @@ require 'abstract_unit' require 'action_view/dependency_tracker' class DependencyTrackerTest < ActionView::TestCase - Neckbeard = Class.new - Bowtie = Class.new + Neckbeard = lambda {|template| template.source } + Bowtie = lambda {|template| template.source } class NeckbeardTracker def self.call(name, template) @@ -24,11 +24,12 @@ class DependencyTrackerTest < ActionView::TestCase end def setup - tracker.register_tracker(Neckbeard, NeckbeardTracker) + ActionView::Template.register_template_handler :neckbeard, Neckbeard + tracker.register_tracker(:neckbeard, NeckbeardTracker) end def teardown - tracker.remove_tracker(Neckbeard) + tracker.remove_tracker(:neckbeard) end def test_finds_tracker_by_template_handler diff --git a/actionpack/test/template/digestor_test.rb b/actionpack/test/template/digestor_test.rb index 272ffec26e..e29cecabc0 100644 --- a/actionpack/test/template/digestor_test.rb +++ b/actionpack/test/template/digestor_test.rb @@ -6,7 +6,7 @@ class FixtureTemplate def initialize(template_path) @source = File.read(template_path) - @handler = ActionView::Template::Handlers::ERB + @handler = ActionView::Template.handler_for_extension(:erb) rescue Errno::ENOENT raise ActionView::MissingTemplate.new([], "", [], true, []) end |