module CSSMinCli

CSSMinCli

Command line runner for CSSMin library. For more details on CSSMin, please check github.com/rgrove/cssmin

Author

Jan Ferko (mailto: jan.ferko3@gmail.com)

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

github.com/iref/cssmin-cli

Public Class Methods

resolve_destination(destination) click to toggle source

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.

# File lib/cssmin_cli.rb, line 90
def self.resolve_destination(destination)
  return $stdout unless destination
  File.open(destination, "w")
end
resolve_source(options) click to toggle source

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.

# File lib/cssmin_cli.rb, line 75
def self.resolve_source(options)
  if options[:inline]
    options[:inline]
  elsif options[:source]
    IO.read(options[:source])
  end
end
run(options) click to toggle source

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.

# File lib/cssmin_cli.rb, line 52
def self.run(options)
  destination = resolve_destination(options[:destination])
  source = resolve_source(options)

  return false unless source

  minified = CSSMin::minify(source)

  destination.write(minified)
  destination.close

  return true
end