Add Middleman::Util.all_files_under to get a recursive listing of files beneath a path, follows symlinks. Fixes #515
This commit is contained in:
parent
b67d4e7c82
commit
4b03c5e2df
5 changed files with 57 additions and 45 deletions
|
@ -206,12 +206,12 @@ module Middleman::Cli
|
|||
# @return [void]
|
||||
def queue_current_paths
|
||||
@cleaning_queue = []
|
||||
Find.find(@destination) do |path|
|
||||
next if path.match(/\/\./) && !path.match(/\.htaccess/)
|
||||
unless path == destination
|
||||
@cleaning_queue << Pathname.new(path)
|
||||
end
|
||||
end if File.exist?(@destination)
|
||||
return unless File.exist?(@destination)
|
||||
|
||||
paths = ::Middleman::Util.all_files_under(@destination)
|
||||
@cleaning_queue += paths.select do |path|
|
||||
!path.to_s.match(/\/\./) || path.to_s.match(/\.htaccess/)
|
||||
end
|
||||
end
|
||||
|
||||
# Actually build the app
|
||||
|
|
|
@ -10,7 +10,7 @@ module Middleman
|
|||
def registered(app)
|
||||
# Setup a default helpers paths
|
||||
app.set :helpers_dir, "helpers"
|
||||
app.set :helpers_filename_glob, "**/*.rb"
|
||||
app.set :helpers_filename_glob, "**{,/*/**}/*.rb"
|
||||
app.set :helpers_filename_to_module_name_proc, Proc.new { |filename|
|
||||
basename = File.basename(filename, File.extname(filename))
|
||||
basename.camelcase
|
||||
|
|
|
@ -112,9 +112,8 @@ module Middleman
|
|||
glob = "#{path}**/*"
|
||||
subset = @known_paths.select { |p| p.fnmatch(glob) }
|
||||
|
||||
path.find do |filepath|
|
||||
::Middleman::Util.all_files_under(path).each do |filepath|
|
||||
full_path = path + filepath
|
||||
next if full_path.directory?
|
||||
|
||||
if only_new
|
||||
next if subset.include?(full_path)
|
||||
|
|
|
@ -74,6 +74,21 @@ module Middleman
|
|||
File.fnmatch(matcher.to_s, path)
|
||||
end
|
||||
end
|
||||
|
||||
# Get a recusive list of files inside a set of paths.
|
||||
# Works with symlinks.
|
||||
#
|
||||
# @param path A path string or Pathname
|
||||
# @return [Array] An array of filenames
|
||||
def self.all_files_under(*paths)
|
||||
paths.flatten!
|
||||
paths.map! { |p| Pathname(p) }
|
||||
files = paths.select { |p| p.file? }
|
||||
(paths - files).each do |dir|
|
||||
files << all_files_under(dir.children)
|
||||
end
|
||||
files.flatten
|
||||
end
|
||||
|
||||
# Simple shared cache implementation
|
||||
class Cache
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue