2 * node-sass: lib/render.js
5 var chalk = require('chalk'),
7 mkdirp = require('mkdirp'),
8 path = require('path'),
14 * @param {Object} options
15 * @param {Object} emitter
19 module.exports = function(options, emitter) {
21 includePaths: options.includePath,
22 omitSourceMapUrl: options.omitSourceMapUrl,
23 indentedSyntax: options.indentedSyntax,
24 outFile: options.dest,
25 outputStyle: options.outputStyle,
26 precision: options.precision,
27 sourceComments: options.sourceComments,
28 sourceMapEmbed: options.sourceMapEmbed,
29 sourceMapContents: options.sourceMapContents,
30 sourceMap: options.sourceMap,
31 sourceMapRoot: options.sourceMapRoot,
32 importer: options.importer,
33 functions: options.functions,
34 indentWidth: options.indentWidth,
35 indentType: options.indentType,
36 linefeed: options.linefeed
40 renderOptions.data = options.data;
41 } else if (options.src) {
42 renderOptions.file = options.src;
45 var sourceMap = options.sourceMap;
46 var destination = options.dest;
47 var stdin = options.stdin;
49 var success = function(result) {
51 var done = function() {
57 if (!destination || stdin) {
58 emitter.emit('log', result.css.toString());
60 if (sourceMap && !options.sourceMapEmbed) {
61 emitter.emit('log', result.map.toString());
67 emitter.emit('warn', chalk.green('Rendering Complete, saving .css file...'));
69 mkdirp(path.dirname(destination), function(err) {
71 return emitter.emit('error', chalk.red(err));
74 fs.writeFile(destination, result.css.toString(), function(err) {
76 return emitter.emit('error', chalk.red(err));
79 emitter.emit('warn', chalk.green('Wrote CSS to ' + destination));
80 emitter.emit('write', err, destination, result.css.toString());
88 mkdirp(path.dirname(sourceMap), function(err) {
90 return emitter.emit('error', chalk.red(err));
92 fs.writeFile(sourceMap, result.map, function(err) {
94 return emitter.emit('error', chalk.red('Error' + err));
97 emitter.emit('warn', chalk.green('Wrote Source Map to ' + sourceMap));
98 emitter.emit('write-source-map', err, sourceMap, result.map);
104 emitter.emit('render', result.css.toString());
107 var error = function(error) {
108 emitter.emit('error', chalk.red(JSON.stringify(error, null, 2)));
111 var renderCallback = function(err, result) {
120 sass.render(renderOptions, renderCallback);