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
|
# File 'lib/minit.rb', line 5
def package type, globs, create
compressor = {:javascripts => JSMin, :stylesheets => CSSMin}[type]
extension = {:javascripts => 'js', :stylesheets => 'css'}[type]
include_method = {:javascripts => 'javascript_include_tag', :stylesheets => 'stylesheet_link_tag'}[type]
raise "package type unknown. Only :javascripts or :stylesheets supported." unless compressor && extension && include_method
package_name = "packaged.#{extension}"
return send(include_method, File.join('/assets', package_name)) if compress? && !create
files = []
includes = []
asset_path = File.join(Rails.root, 'public', type.to_s, '/')
file = File.open(File.join(Rails.root, 'public', 'assets', package_name), 'w') if (compress? && create)
globs.each do |glob|
Dir.glob(File.join(asset_path, glob)).each do |path|
next if files.include?(path)
files << path
if compress? && create
file.puts compressor.minify(File.read(path))
elsif !create
includes << path.gsub(asset_path, '')
end
end
end
file.close if file
end
|