Return TemplatePaths from all_template_paths

This commit is contained in:
John Hawthorn 2021-04-28 16:48:18 -07:00
parent b6b1b6b27f
commit ef2cb32090
4 changed files with 23 additions and 15 deletions

View File

@ -161,20 +161,18 @@ module ActionView
return [] unless @view_paths
return [] if wildcard_dependencies.empty?
# Remove trailing "*"
prefixes = wildcard_dependencies.map { |query| query[0..-2] }
# Remove trailing "/*"
prefixes = wildcard_dependencies.map { |query| query[0..-3] }
@view_paths.flat_map(&:all_template_paths).uniq.select { |path|
prefixes.any? do |prefix|
path.start_with?(prefix) && !path.index("/", prefix.size)
end
}.sort
prefixes.include?(path.prefix)
}.map(&:to_s).sort
end
def explicit_dependencies
dependencies = source.scan(EXPLICIT_DEPENDENCY).flatten.uniq
wildcards, explicits = dependencies.partition { |dependency| dependency.end_with?("*") }
wildcards, explicits = dependencies.partition { |dependency| dependency.end_with?("/*") }
(explicits + resolve_directories(wildcards)).uniq
end

View File

@ -97,18 +97,17 @@ module ActionView
candidates = @error.paths.flat_map(&:all_template_paths).uniq
if @error.partial
candidates = candidates.grep(%r{_[^/]+\z})
candidates = candidates.select!(&:partial?)
else
candidates = candidates.grep_v(%r{_[^/]+\z})
candidates = candidates.reject!(&:partial?)
end
# Group by possible prefixes
files_by_dir = candidates.group_by do |x|
File.dirname(x)
end.transform_values do |files|
files_by_dir = candidates.group_by(&:prefix)
files_by_dir.transform_values! do |files|
files.map do |file|
# Remove directory
File.basename(file)
# Remove prefix
File.basename(file.to_s)
end
end

View File

@ -197,7 +197,9 @@ module ActionView
paths = template_glob("**/*")
paths.map do |filename|
filename.from(@path.size + 1).remove(/\.[^\/]*\z/)
end.uniq
end.uniq.map do |filename|
TemplatePath.parse(filename)
end
end
private

View File

@ -45,5 +45,14 @@ module ActionView
@virtual
end
alias :to_s :to_str
def hash
@virtual.hash
end
def eql?(other)
@virtual == other.virtual
end
alias :== :eql?
end
end