Class: Lotus::Assets::Compressors::BuiltinStylesheet Private

Inherits:
Stylesheet show all
Defined in:
lib/lotus/assets/compressors/builtin_stylesheet.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Builtin compressor for stylesheet

This is a basic algorithm based on Scott Becker (@sbecker) work on asset_packager gem.

Copyright © 2006-2008 Scott Becker

Constant Summary collapse

SPACE_REPLACEMENT =

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.

Since:

  • 0.1.0

" ".freeze
COMMENTS_REPLACEMENT =

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.

Since:

  • 0.1.0

"".freeze
LINE_BREAKS_REPLACEMENT =

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.

Since:

  • 0.1.0

"}\n".freeze
LAST_BREAK_REPLACEMENT =

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.

Since:

  • 0.1.0

"".freeze
INSIDE_LEFT_BRACKET_REPLACEMENT =

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.

Since:

  • 0.1.0

" {".freeze
INSIDE_RIGHT_BRACKET_REPLACEMENT =

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.

Since:

  • 0.1.0

"}".freeze

Instance Method Summary collapse

Methods inherited from Stylesheet

for

Instance Method Details

#compress(filename) ⇒ 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.

Since:

  • 0.1.0


44
45
46
47
48
49
50
51
52
53
# File 'lib/lotus/assets/compressors/builtin_stylesheet.rb', line 44

def compress(filename)
  result = read(filename)
  result.gsub!(/\s+/,            SPACE_REPLACEMENT)                # collapse space
  result.gsub!(/\/\*(.*?)\*\/ /, COMMENTS_REPLACEMENT)             # remove comments - caution, might want to remove this if using css hacks
  result.gsub!(/\} /,            LINE_BREAKS_REPLACEMENT)          # add line breaks
  result.gsub!(/\n$/,            LAST_BREAK_REPLACEMENT)           # remove last break
  result.gsub!(/ \{ /,           INSIDE_LEFT_BRACKET_REPLACEMENT)  # trim inside brackets
  result.gsub!(/; \}/,           INSIDE_RIGHT_BRACKET_REPLACEMENT) # trim inside brackets
  result
end