Methods for minifying JavaScript.
Constants
ENGINES | = | [:weak, :jsmin] | A list of supported minification engine names. | |
VENDORS | = | Vendors::VENDORS | A list of supported 3rd-party JavaScript plugin/vendor names. |
Public class methods
min_filepath
(filepath)
Returns the expected path for the minified version of a JS asset:
AssetHat::JS.min_filepath('public/javascripts/bundles/application.js') # => 'public/javascripts/bundles/application.min.js'
[show source]
# File lib/asset_hat/js.rb, line 19 19: def self.min_filepath(filepath) 20: AssetHat.min_filepath(filepath, 'js') 21: end
minify
(input_string, options={})
Accepts a string of JS, and returns that JS minified. Options:
- engine
- Default is :jsmin; see Engines.jsmin. Allowed values are in ENGINES.
[show source]
# File lib/asset_hat/js.rb, line 28 28: def self.minify(input_string, options={}) 29: options.reverse_merge!(:engine => :jsmin) 30: 31: engine = options[:engine].to_sym 32: unless ENGINES.include?(engine) 33: raise %{ 34: Unknown JS minification engine '#{engine}'. 35: Allowed: #{ENGINES.map{ |e| "'#{e}'" }.join(', ')} 36: }.strip.gsub(/\s+/, ' ') and return 37: end 38: 39: AssetHat::JS::Engines.send(engine, input_string).strip 40: end