lib/spinebox/compiler.rb in spinebox-0.0.14 vs lib/spinebox/compiler.rb in spinebox-0.0.15

- old
+ new

@@ -1,8 +1,10 @@ module Spinebox module Compiler + require "digest" + # Compiles the assets and the views into the public folder def self.compile Spinebox.config.concatenate = true create_directories compile_javascripts @@ -17,27 +19,45 @@ Dir.mkdir "public/assets" unless File.directory?("public/assets") end def self.compile_javascripts asset = Spinebox.assets["application.js"] - asset.write_to(File.join("public/assets", asset.logical_path)) + path = File.join("public/assets", asset.logical_path) + + write_asset!(asset, path) if asset_updated?(asset, path) end def self.compile_stylesheets asset = Spinebox.assets["application.css"] - asset.write_to(File.join("public/assets", asset.logical_path)) + path = File.join("public/assets", asset.logical_path) + + write_asset!(asset, path) if asset_updated?(asset, path) end def self.compile_views Spinebox.views.each_logical_path do |logical_path| next if logical_path.start_with?("_") asset = Spinebox.views[logical_path] - asset.write_to(File.join("public", asset.logical_path)) + path = File.join("public", asset.logical_path) + + write_asset!(asset, path) if asset_updated?(asset, path) end end def self.copy_images - FileUtils.cp_r "app/assets/images/.", "public/assets" + FileUtils.cp_r "app/assets/images/.", "public/assets", :preserve => true + end + + def self.asset_updated?(asset, path) + return true unless File.exists?(path) + Digest::SHA2.file(path).hexdigest != Digest::SHA2.hexdigest(asset.to_s) + end + + def self.write_asset!(asset, path) + asset.write_to(path) + time = Time.now + File.utime(time, time, path) + puts path end end end \ No newline at end of file