class GithubbishAssets::Packer
Public Class Methods
css()
click to toggle source
# File lib/githubbish_assets/packer.rb, line 33 def self.css pack(Rails.root + 'public/stylesheets', '.css') do |target, files| compress_with_yui(YUI::CssCompressor.new(:line_break => 0), files, target) end end
js()
click to toggle source
# File lib/githubbish_assets/packer.rb, line 5 def self.js case GithubbishAssets.js_compressor when :jsmin require 'vendor/js_minimizer' when :closure require 'closure-compiler' end pack(Rails.root + 'public/javascripts', '.js') do |target, files| case GithubbishAssets.js_compressor when :closure opts = { :js_output_file => target, :js => files } if GithubbishAssets.closure_source_map opts[:create_source_map] = "#{target}.map" end Closure::Compiler.new(opts).compile('') when :yui compress_with_yui(YUI::JavaScriptCompressor.new, files, target) else File.open(target, 'w+') do |f| f.puts GithubbishAssets::JSMinimizer.minimize_files(*files) end end end end
Private Class Methods
compress_with_yui(compressor, files, target)
click to toggle source
# File lib/githubbish_assets/packer.rb, line 64 def self.compress_with_yui(compressor, files, target) File.open(target, 'w') do |f| compressor.compress(MultiFile.new(files)) do |compressed| while buffer = compressed.read(4096) f.write(buffer) end end end end
get_top_level_directories(root_path)
click to toggle source
# File lib/githubbish_assets/packer.rb, line 60 def self.get_top_level_directories(root_path) root_path.children.select { |path| path.directory? } end
pack(path, ext) { |target, files| ... }
click to toggle source
# File lib/githubbish_assets/packer.rb, line 41 def self.pack(path, ext) targets = [] get_top_level_directories(path).each do |bundle_directory| bundle_name = bundle_directory.basename.to_s next if bundle_name == 'dev' || bundle_name =~ /^\./ files = RecursiveLister[bundle_directory, ext] next if files.empty? target = path + "bundle_#{bundle_name}#{ext}" yield target, files targets << target end targets end