Class: CSSMin
- Inherits:
-
Object
- Object
- CSSMin
- Defined in:
- lib/mack-asset_packager/cssmin.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
-
#initialize(content) ⇒ CSSMin
constructor
A new instance of CSSMin.
- #minimize ⇒ Object
Constructor Details
#initialize(content) ⇒ CSSMin
Returns a new instance of CSSMin.
4 5 6 |
# File 'lib/mack-asset_packager/cssmin.rb', line 4 def initialize(content) self.data = content end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/mack-asset_packager/cssmin.rb', line 3 def data @data end |
Instance Method Details
#minimize ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mack-asset_packager/cssmin.rb', line 8 def minimize # find all elements in between { and }, and remove \n and \t # self.data.scan(/\{([.|\s\S]*?)\}/).flatten.each do |elt| # str = elt.gsub("\n", "") # str = str.gsub("\t", "") # self.data.gsub!(elt, str) # end self.data = self.data.squeeze(" ").squeeze("\t").squeeze("\n") self.data.gsub!("\t", "") # remove comments in the form of /* ... */ self.data.gsub!(/\/\*[.|\s|\S]*?\*\//, "") # remove newline before and after { self.data.gsub!("\n\{", " \{") self.data.gsub!("\{\n", " \{") # remove newline after , self.data.gsub!(",\n", ", ") # remove spaces after/before ... self.data.gsub!(": ", ":") self.data.gsub!(" :", ":") self.data.gsub!(", ", ",") self.data.gsub!(" ,", ",") self.data.gsub!("; ", ";") self.data.gsub!(" ;", ";") self.data.gsub!(";\}", "\}") self.data.gsub!(" \}", "\}") self.data.gsub!("\{ ", "\{") self.data.gsub!(" \{", "\{") # remove all new line, but add one after } self.data.gsub!("\n", "") self.data.gsub!("\}", "\}\n") self.data = self.data.squeeze(" ").squeeze("\t").squeeze("\n").strip return self.data end |