-
Notifications
You must be signed in to change notification settings - Fork 9
/
plugin.coffee
46 lines (34 loc) · 1.36 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
36
37
38
39
40
41
42
43
44
45
46
child_process = require 'child_process'
path = require 'path'
fs = require 'fs'
module.exports = (wintersmith, callback) ->
options = wintersmith.config.sass or {}
exec_opts = options.exec_opts or {}
class SassPlugin extends wintersmith.ContentPlugin
constructor: (@_filename, @_source) ->
getFilename: ->
@_filename.relative.replace /sass|scss$/g, 'css'
getView: ->
return (env, locals, contents, templates, callback) =>
if path.basename(@_filename.full).charAt(0) == '_'
callback null
else
command = [@_filename.full]
if @_source.search(/(\$compressed:)([ ]*)(true[;\n])/ig) isnt -1
command.unshift('-t', 'compressed')
if @_source.search(/(\$compass:)([ ]*)(true[;\n])/ig) isnt -1
command.unshift('--compass')
onComplete = (error, stdout, stderr) ->
if error
callback error
else
callback null, new Buffer stdout
c = child_process.execFile 'sass', command, exec_opts, onComplete
SassPlugin.fromFile = (filename, callback) ->
fs.readFile filename.full, (error, buffer) ->
if error
callback error
else
callback null, new SassPlugin filename, buffer.toString()
wintersmith.registerContentPlugin 'styles', '**/*.*(scss|sass)', SassPlugin
callback()