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]
|
# @return [void]
|
||||||
def queue_current_paths
|
def queue_current_paths
|
||||||
@cleaning_queue = []
|
@cleaning_queue = []
|
||||||
Find.find(@destination) do |path|
|
return unless File.exist?(@destination)
|
||||||
next if path.match(/\/\./) && !path.match(/\.htaccess/)
|
|
||||||
unless path == destination
|
paths = ::Middleman::Util.all_files_under(@destination)
|
||||||
@cleaning_queue << Pathname.new(path)
|
@cleaning_queue += paths.select do |path|
|
||||||
|
!path.to_s.match(/\/\./) || path.to_s.match(/\.htaccess/)
|
||||||
end
|
end
|
||||||
end if File.exist?(@destination)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Actually build the app
|
# Actually build the app
|
||||||
|
|
|
@ -10,7 +10,7 @@ module Middleman
|
||||||
def registered(app)
|
def registered(app)
|
||||||
# Setup a default helpers paths
|
# Setup a default helpers paths
|
||||||
app.set :helpers_dir, "helpers"
|
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|
|
app.set :helpers_filename_to_module_name_proc, Proc.new { |filename|
|
||||||
basename = File.basename(filename, File.extname(filename))
|
basename = File.basename(filename, File.extname(filename))
|
||||||
basename.camelcase
|
basename.camelcase
|
||||||
|
|
|
@ -112,9 +112,8 @@ module Middleman
|
||||||
glob = "#{path}**/*"
|
glob = "#{path}**/*"
|
||||||
subset = @known_paths.select { |p| p.fnmatch(glob) }
|
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
|
full_path = path + filepath
|
||||||
next if full_path.directory?
|
|
||||||
|
|
||||||
if only_new
|
if only_new
|
||||||
next if subset.include?(full_path)
|
next if subset.include?(full_path)
|
||||||
|
|
|
@ -75,6 +75,21 @@ module Middleman
|
||||||
end
|
end
|
||||||
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
|
# Simple shared cache implementation
|
||||||
class Cache
|
class Cache
|
||||||
# Initialize
|
# Initialize
|
||||||
|
|
|
@ -20,14 +20,16 @@ module Middleman::Extensions
|
||||||
def registered(app, options={})
|
def registered(app, options={})
|
||||||
exts = options[:exts] || %w(.js .css .html .htm)
|
exts = options[:exts] || %w(.js .css .html .htm)
|
||||||
|
|
||||||
app.send :include, InstanceMethods
|
|
||||||
|
|
||||||
app.after_build do |builder|
|
app.after_build do |builder|
|
||||||
Find.find(self.class.inst.build_dir) do |path|
|
|
||||||
next if File.directory? path
|
paths = ::Middleman::Util.all_files_under(self.class.inst.build_dir)
|
||||||
if exts.include? File.extname(path)
|
paths.each do |path|
|
||||||
new_size = gzip_file(path, builder)
|
next unless exts.include? path.extname
|
||||||
end
|
|
||||||
|
output_filename, old_size, new_size = Middleman::Extensions::Gzip.gzip_file(path.to_s)
|
||||||
|
|
||||||
|
size_change_word = (old_size - new_size) > 0 ? 'smaller' : 'larger'
|
||||||
|
builder.say_status :gzip, "#{output_filename} (#{number_to_human_size((old_size - new_size).abs)} #{size_change_word})"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -35,8 +37,7 @@ module Middleman::Extensions
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
def self.gzip_file(path)
|
||||||
def gzip_file(path, builder)
|
|
||||||
input_file = File.open(path, 'r').read
|
input_file = File.open(path, 'r').read
|
||||||
output_filename = path + '.gz'
|
output_filename = path + '.gz'
|
||||||
input_file_time = File.mtime(path)
|
input_file_time = File.mtime(path)
|
||||||
|
@ -62,10 +63,7 @@ module Middleman::Extensions
|
||||||
old_size = File.size(path)
|
old_size = File.size(path)
|
||||||
new_size = File.size(output_filename)
|
new_size = File.size(output_filename)
|
||||||
|
|
||||||
size_change_word = (old_size - new_size) > 0 ? 'smaller' : 'larger'
|
[output_filename, old_size, new_size]
|
||||||
|
|
||||||
builder.say_status :gzip, "#{output_filename} (#{number_to_human_size((old_size - new_size).abs)} #{size_change_word})"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue