Sha256: 2f65719e9e65cb3caa326088c1f92a43b4e7067ddef38e267c39a04ecc736f4a
Contents?: true
Size: 1.45 KB
Versions: 157
Compression:
Stored size: 1.45 KB
Contents
# frozen_string_literal: true require 'active_support/core_ext/object/blank' require 'eac_ruby_utils/templates/directory' require 'eac_ruby_utils/templates/file' module EacRubyUtils module Templates class Searcher class << self def default @default ||= new end end def template(subpath, required = true) path = template_path(subpath) if path.blank? return nil unless required raise_template_not_found(subpath) end return ::EacRubyUtils::Templates::File.new(path) if ::File.file?(path) return ::EacRubyUtils::Templates::Directory.new(path) if ::File.directory?(path) raise 'Invalid branching' end # @return The absolute path of template if found, +nil+ otherwise. def template_path(subpath) included_paths.each do |included_path| r = search_template_in_included_path(included_path, subpath) return r if r end nil end def included_paths @included_paths ||= ::Set.new end private def raise_template_not_found(subpath) raise "Template not found for subpath \"#{subpath}\"" \ " (Included paths: #{included_paths.to_a.join(::File::PATH_SEPARATOR)})" end def search_template_in_included_path(included_path, subpath) path = ::File.join(included_path, subpath) ::File.exist?(path) ? path : nil end end end end
Version data entries
157 entries across 157 versions & 3 rubygems