lib/linner.rb in linner-0.1.0 vs lib/linner.rb in linner-0.1.1

- old
+ new

@@ -1,9 +1,9 @@ require "linner/version" require "linner/command" require "linner/asset" -require "linner/sort" +require "linner/helper" require "linner/environment" require "linner/wrapper" require "linner/template" require "linner/notifier" require "linner/compressor" @@ -14,32 +14,30 @@ def root @root ||= Pathname('.').expand_path end def environment - @env ||= Linner::Environment.new root.join("config.yml") + @env ||= Environment.new root.join("config.yml") end - def perform(options = {}) - compile = options[:compile] - environment.files.values.each do |config| + 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 end end private def concat(config) assets = [] - concat, before, after = environment.extract_by(config) - concat.each do |dist, regex| + config["concat"].each do |dist, regex| Thread.new do - dist = Linner::Asset.new(environment.public_folder.join(dist).to_path) + dist = Asset.new(File.join environment.public_folder, dist) + dist.content = "" matches = Dir.glob(File.join root, regex).uniq - matches.extend(Linner::Sort) - matches.sort(before: before, after: after).each do |m| - asset = Linner::Asset.new(m) + matches.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 dist.content << content @@ -49,16 +47,16 @@ end assets end def copy(config) - config["copy"].to_h.each do |dist, regex| + config["copy"].each do |dist, regex| Thread.new do matches = Dir.glob(File.join root, regex) matches.each do |path| - asset = Linner::Asset.new(path) + asset = Asset.new(path) asset.path = File.join(environment.public_folder, dist, asset.logical_path) - next if File.exist? asset.path and FileUtils.uptodate? path, [asset.path] + next if File.exist?(asset.path) and FileUtils.uptodate?(path, [asset.path]) asset.write end end.join end end