Class: Hanami::Assets::Compressors::BuiltinStylesheet Private
- Inherits:
-
Stylesheet
- Object
- Abstract
- Stylesheet
- Hanami::Assets::Compressors::BuiltinStylesheet
- Defined in:
- lib/hanami/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.
" ".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.
"".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.
"}\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.
"".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.
" {".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.
"}".freeze
Instance Method Summary collapse
- #compress(filename) ⇒ Object private
Methods inherited from Stylesheet
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.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/hanami/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 |