-
Notifications
You must be signed in to change notification settings - Fork 1
/
plugin.coffee
35 lines (27 loc) · 1.08 KB
/
plugin.coffee
1
2
3
4
5
6
7
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
cleancss = require 'clean-css'
path = require 'path'
fs = require 'fs'
module.exports = (wintersmith, callback) ->
logger = wintersmith.logger
class CleanCssPlugin extends wintersmith.ContentPlugin
constructor: (@_filename, @_text) ->
getFilename: ->
@_filename.relative
getView: -> (env, locals, contents, templates, callback) ->
if @_filename.relative.indexOf('.min.css') is -1
try
logger.verbose "CleanCss #{@_filename.relative}"
css = cleancss.process(@_text)
callback null, new Buffer(css)
catch error
callback error
else
callback null, new Buffer @_text
CleanCssPlugin.fromFile = (filename, callback) ->
fs.readFile filename.full, (error, buffer) ->
if error
callback error
else
callback null, new CleanCssPlugin filename, buffer.toString()
wintersmith.registerContentPlugin 'style', '**/*.css', CleanCssPlugin
callback() # tell the plugin manager we are done