Sha256: 7e61f503bfbdd2cb7d0fd6e44e3beb90b648d36d165d2bfefa349f54e4217888
Contents?: true
Size: 820 Bytes
Versions: 9
Compression:
Stored size: 820 Bytes
Contents
require "pathname" module Dry module View class Path include Dry::Equalizer(:dir, :root) attr_reader :dir, :root def initialize(dir, options = {}) @dir = Pathname(dir) @root = Pathname(options.fetch(:root, dir)) end def lookup(name, format) template?(name, format) || template?("shared/#{name}", format) || !root? && chdir('..').lookup(name, format) end def chdir(dirname) self.class.new(dir.join(dirname), root: root) end def to_s dir end private def root? dir == root end # Search for a template using a wildcard for the engine extension def template?(name, format) glob = dir.join("#{name}.#{format}.*") Dir[glob].first end end end end
Version data entries
9 entries across 9 versions & 1 rubygems