UNPKG

karma-slim-preprocessor-with-binary-option

Version:

A Karma plugin. Compile slim files to html on the fly

42 lines (31 loc) 1.08 kB
var util = require('util'); var spawn = require('child_process').spawn; var createSlimPreprocessor = function(logger, config) { config = typeof config === 'object' ? config : {}; var log = logger.create('preprocessor.slim'); var slimrb = config.slimrb || 'slimrb'; return function(content, file, done) { var child, html, origPath; log.debug('Processing "%s".', file.originalPath); origPath = file.originalPath; html = ''; child = spawn(slimrb, [origPath]); child.on('error', function (error) { if (error.code === 'ENOENT') { log.error('It does not appear as though `slimrb` is installed. Try running `bundle install` in your project.'); done(''); } }); child.stdout.on('data', function (buf) { html += String(buf); }); child.stdout.on('close', function (buf) { done(html); }); child.stderr.on('data', function (buf) { throw String(buf); }); }; }; createSlimPreprocessor.$inject = ['logger', 'config.slimPreprocessor']; module.exports = createSlimPreprocessor;