lib/linner.rb in linner-0.1.5 vs lib/linner.rb in linner-0.2.0

- old
+ new

@@ -23,50 +23,48 @@ @env ||= Environment.new root.join("config.yml") end def perform(compile: false) environment.files.each do |config| - Thread.new {concat(config).each {|asset| asset.compress if compile; asset.write}}.join - Thread.new {copy(config)}.join + concat(config, compile) + copy(config) end end private - def concat(config) - assets = [] - config["concat"].each do |dest, regex| - Thread.new do - dest = Asset.new(File.join environment.public_folder, dest) - dest.content = "" - Dir.glob(regex).uniq.sort_by_before_and_after(config["order"]["before"], config["order"]["after"]).each do |m| - asset = Asset.new(m) - content = asset.content - if asset.wrappable? - content = asset.wrap - end - dest.content << content + def concat(config, compile) + config["concat"].map do |dest, regex| + matches = Dir.glob(regex).uniq.order_by(before:config["order"]["before"], after:config["order"]["after"]) + dest = Asset.new(File.join environment.public_folder, dest) + dest.content = "" + cached = matches.select do |path| + mtime = File.mtime(path).to_i + mtime == cache[path] ? false : cache[path] = mtime + end + next if cached.empty? + matches.each do |m| + asset = Asset.new(m) + content = asset.content + if asset.wrappable? + content = asset.wrap end - assets << dest - end.join + dest.content << content + end + dest.compress if compile + dest.write end - assets end def copy(config) config["copy"].each do |dest, regex| - Thread.new do - Dir.glob(regex).each do |path| - mtime = File.mtime(path).to_i - if cache[path] - next if mtime == cache[path] - else - cache[path] = mtime - end - logical_path = Asset.new(path).logical_path - dest_path = File.join(environment.public_folder, dest, logical_path) - FileUtils.mkdir_p File.dirname(dest_path) - FileUtils.cp_r path, dest_path - end - end.join + Dir.glob(regex).each do |path| + mtime = File.mtime(path).to_i + next if cache[path] == mtime + cache[path] = mtime + logical_path = Asset.new(path).logical_path + dest_path = File.join(environment.public_folder, dest, logical_path) + FileUtils.mkdir_p File.dirname(dest_path) + FileUtils.cp_r path, dest_path + end end end end