Module: JSMin Private
- Defined in:
- lib/hanami/assets/compressors/jsmin.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
JSMin
Ruby implementation of Douglas Crockford’s JavaScript minifier, JSMin.
- Author
-
Ryan Grove ([email protected])
- Version
-
1.0.1 (2008-11-10)
- Copyright
-
Copyright © 2008 Ryan Grove. All rights reserved.
- Website
Example
require 'rubygems'
require 'jsmin'
File.open('example.js', 'r') {|file| puts JSMin.minify(file) }
Defined Under Namespace
Classes: ParseError
Constant Summary collapse
- CHR_APOS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"'".freeze
- CHR_ASTERISK =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'*'.freeze
- CHR_BACKSLASH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'\\'.freeze
- CHR_CR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"\r".freeze
- CHR_FRONTSLASH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'/'.freeze
- CHR_LF =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"\n".freeze
- CHR_QUOTE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'"'.freeze
- CHR_SPACE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
' '.freeze
- ORD_LF =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
?\n
- ORD_SPACE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
?\
- ORD_TILDE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
?~
Class Method Summary collapse
-
.minify(input) ⇒ Object
private
Reads JavaScript from input (which can be a String or an IO object) and returns a String containing minified JS.
- .raise(err) ⇒ Object private
Class Method Details
.minify(input) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reads JavaScript from input (which can be a String or an IO object) and returns a String containing minified JS.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/hanami/assets/compressors/jsmin.rb', line 82 def minify(input) @js = StringScanner.new(input.is_a?(IO) ? input.read : input.to_s) @source = input.is_a?(IO) ? input.inspect : input.to_s[0..100] @line = 1 @a = "\n" @b = nil @lookahead = nil @output = '' action_get while !@a.nil? do case @a when CHR_SPACE if alphanum?(@b) action_output else action_copy end when CHR_LF if @b == CHR_SPACE action_get elsif @b =~ /[{\[\(+-]/ action_output else if alphanum?(@b) action_output else action_copy end end else if @b == CHR_SPACE if alphanum?(@a) action_output else action_get end elsif @b == CHR_LF if @a =~ /[}\]\)\\"+-]/ action_output else if alphanum?(@a) action_output else action_get end end else action_output end end end @output end |
.raise(err) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
76 77 78 |
# File 'lib/hanami/assets/compressors/jsmin.rb', line 76 def raise(err) super ParseError.new(err, @source, @line) end |