Module: CSSMinCli
- Defined in:
- lib/cssmin_cli.rb
Overview
CSSMinCli
Command line runner for CSSMin library. For more details on CSSMin, please check github.com/rgrove/cssmin
- Author
-
Jan Ferko (mailto: [email protected])
- Version
-
1.0 (2014-04-24)
- Copyright
-
Copyright © 2014 Jan Ferko. All rights reserved.
- License
-
New BSD License (opensource.org/licenses/BSD-3-Clause)
- Website
Class Method Summary collapse
-
.resolve_destination(destination) ⇒ Object
Resolves destination where minified CSS should be stored.
-
.resolve_source(options) ⇒ Object
Resolves CSS source for given options.
-
.run(options) ⇒ Object
Runs minifier for given options.
Class Method Details
.resolve_destination(destination) ⇒ Object
Resolves destination where minified CSS should be stored.
Params: destination - path to file, where minified css should be stored. Defaults to STDOUT
Returns opened IO object.
90 91 92 93 |
# File 'lib/cssmin_cli.rb', line 90 def self.resolve_destination(destination) return $stdout unless destination File.open(destination, "w") end |
.resolve_source(options) ⇒ Object
Resolves CSS source for given options. Inline option has precedence over source option.
Supported options are:
source - Path to CSS source file
inline - String containing CSS
Returns string, that contains loaded css from source or nil if invalid options hash was provided.
75 76 77 78 79 80 81 |
# File 'lib/cssmin_cli.rb', line 75 def self.resolve_source() if [:inline] [:inline] elsif [:source] IO.read([:source]) end end |
.run(options) ⇒ Object
Runs minifier for given options.
Currently supported options are:
source - CSS source file
inline - String containing CSS
destination - File, where to store minified CSS. Default is stdout.
Returns true if css was successfully minified and stored, otherwise false.
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cssmin_cli.rb', line 52 def self.run() destination = resolve_destination([:destination]) source = resolve_source() return false unless source minified = CSSMin::minify(source) destination.write(minified) destination.close return true end |