lib/linner.rb in linner-0.4.6 vs lib/linner.rb in linner-0.5.0

- old
+ new

@@ -3,10 +3,11 @@ require "linner/version" require "linner/command" require "linner/asset" require "linner/cache" require "linner/helper" +require "linner/bundler" require "linner/reactor" require "linner/wrapper" require "linner/template" require "linner/notifier" require "linner/compressor" @@ -64,17 +65,20 @@ end end def perform(*asset) env.groups.each do |config| + precompile(config) if config["precompile"] + end + env.groups.each do |config| copy(config) if config["copy"] concat(config) if config["concat"] end revision if compile? and env.revision end -private + private def concat(config) config["concat"].each_with_index do |pair, index| dest, pattern, order = pair.first, pair.last, config["order"]||[] matches = Dir.glob(pattern).sort_by(&:downcase).order_by(order) next if matches.select {|p| cache.miss? p}.empty? @@ -92,23 +96,37 @@ FileUtils.cp_r path, dest_path end end end + def precompile(config) + config["precompile"].each do |dest, pattern| + matches = Dir.glob(pattern).sort_by(&:downcase) + next if matches.select { |p| cache.miss? p }.empty? + write_template(dest, matches) + end + end + def revision dump_manifest [env.revision].flatten.each do |rev| file = File.join env.public_folder, rev.to_s next if not File.exist?(file) replace_attributes file end end - private + def write_template(dest, child_assets) + asset = Asset.new(File.join env.public_folder, dest) + content = child_assets.inject("") {|s, m| s << cache[m].content} + asset.content = Wrapper::Template.definition(content) + asset.compress if compile? + asset.write + end def write_asset(dest, child_assets) asset = Asset.new(File.join env.public_folder, dest) - definition = (asset.path == env.definition ? Wrapper.definition : "") + definition = (asset.path == env.definition ? Wrapper::Module.definition : "") asset.content = child_assets.inject(definition) {|s, m| s << cache[m].content} asset.compress if compile? asset.write end