module Blix
manage your asset names
a config directory contains a file for each managed asset using its generic name. In the file is the unique stamp that is used to find the name of the latest version of the asset. config format consists of a filestamp part and md5 hash part
ensure that your config dir exists (default config/assets) ensure that you destination dir exists ( eg public/assets )
then use something like this to compile your assets...
ASSETS = ['main.js', 'main.css'] ASSETS.each do |name|
str = environment[name].to_s if File.extname(name) == ".css" engine = Sass::Engine.new(str, :syntax => :scss, :style => :compressed) str = engine.render end AssetManager.if_modified(name,str,:rewrite=>true) do |a| filename = File.join(ROOT,"www","assets",a.newname) puts "writing #{name} to #{filename}" File.write filename,str File.unlink File.join(ROOT,"www","assets",a.oldname) if a.oldname end
end
then within your erb template or whatever …
<script src=“<%= AssetManager.asset_path
('/assets/main.js',flag) %>” type=“text/javascript”></script>
where flag indicates if the static compiled version should be used ( ie with hash) or the plain name ( served by sprockets pipeline)