diff --git a/lib/dry/view/path.rb b/lib/dry/view/path.rb index 968114c6..c8000f6a 100644 --- a/lib/dry/view/path.rb +++ b/lib/dry/view/path.rb @@ -9,14 +9,16 @@ class Path attr_reader :dir, :root - def initialize(dir, options = {}) + def initialize(dir, root: dir) @dir = Pathname(dir) - @root = Pathname(options.fetch(:root, dir)) + @root = root end - def lookup(name, format) + def lookup(name, format, include_shared: true) fetch_or_store(dir, root, name, format) do - template?(name, format) || template?("shared/#{name}", format) || !root? && chdir('..').lookup(name, format) + template?(name, format) || + (include_shared && template?("shared/#{name}", format)) || + !root? && chdir('..').lookup(name, format) end end diff --git a/lib/dry/view/renderer.rb b/lib/dry/view/renderer.rb index 12a7271f..80e04be3 100644 --- a/lib/dry/view/renderer.rb +++ b/lib/dry/view/renderer.rb @@ -50,7 +50,7 @@ def chdir(dirname) def lookup(name) paths.inject(false) { |_, path| - result = path.lookup(name, format) + result = path.lookup(name, format, include_shared: false) break result if result } end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 831a475c..83f8d68f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -30,6 +30,19 @@ def self.remove_constants config.after do Test.remove_constants end + + config.after do + [ + Dry::View, + Dry::View::PartBuilder, + Dry::View::Path, + Dry::View::Renderer, + Dry::View::ScopeBuilder, + Dry::View::Tilt, + ].each do |klass| + klass.cache.clear + end + end end RSpec::Matchers.define :part_including do |data| diff --git a/spec/unit/renderer_spec.rb b/spec/unit/renderer_spec.rb index e22679e1..dcce1a23 100644 --- a/spec/unit/renderer_spec.rb +++ b/spec/unit/renderer_spec.rb @@ -17,11 +17,13 @@ expect(renderer.template(:hello, scope)).to eql('