Swappable JavaScript minification engines.
Public class methods
jsmin
(input_string)
JavaScript minification engine that simply uses the JSMin gem, a Ruby port of Crockford’s JSMin.
Sources:
[show source]
# File lib/asset_hat/js.rb, line 79 79: def self.jsmin(input_string) 80: JSMin.minify(input_string) 81: end
weak
(input_string)
Barebones JavaScript minification engine that:
- Skips leading/trailing whitespace for each line, excluding line breaks; and
- Removes one-line comments that had no actual code on that line.
[show source]
# File lib/asset_hat/js.rb, line 48 48: def self.weak(input_string) 49: input = StringIO.new(input_string) 50: output = StringIO.new 51: 52: input.each do |line| 53: # Remove indentation and trailing whitespace 54: line.strip! 55: next if line.blank? 56: 57: # Skip single-line comments 58: next if !(line =~ /^\/\//).nil? 59: # TODO: Also skip single-line comments that began mid-line, but not 60: # inside a string or regex 61: 62: # TODO: Skip multi-line comments 63: # - Should not strip from within a string or regex 64: # - Should not strip comments that begin with `/*!` (e.g., licenses) 65: 66: output.write(line + "\n") 67: end 68: 69: output.rewind 70: output.read 71: end