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

View File

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

View File

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

View File

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