This repository was archived by the owner on Nov 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompiler.rake
More file actions
58 lines (44 loc) · 1.47 KB
/
compiler.rake
File metadata and controls
58 lines (44 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
unless defined? Rails
require 'pathname'
require 'sprockets'
require 'yui/compressor'
namespace :assets do
def write_asset(target,asset)
path_for(asset).tap do |path|
filename = target.join(path)
FileUtils.mkdir_p File.dirname(filename)
puts "Generating #{asset.logical_path} -> #{filename}"
asset.write_to(filename)
asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/
end
end
def path_for(asset)
asset.logical_path =~ /\.html$/ ? asset.logical_path : asset.digest_path
end
def compile_path?(logical_path)
/(?:\/|\\|\A)application\.(css|js)$/ =~ logical_path ||
logical_path =~ /\.html$/
end
desc "Compile all the assets named in config.assets.precompile"
task :compile do
require $ROOT.join("lib/rack_application")
app = RackApplication.new($ROOT)
env = app.assets
env.js_compressor = YUI::JavaScriptCompressor.new(munge: true,
optimize: true)
# env.css_compressor = YUI::CssCompressor.new
target = app.public_path
system "rm -rf #{target}/*"
manifest = {}
env.each_logical_path do |logical_path|
next unless compile_path?(logical_path)
if asset = env.find_asset(logical_path)
manifest[logical_path] = write_asset(target,asset)
end
end
File.open("#{target}/manifest.yml", 'wb') do |f|
YAML.dump(manifest, f)
end
end
end
end