Skip to content

Commit

Permalink
Less renderer needs to be run in the path of the less files. Also the
Browse files Browse the repository at this point in the history
renderer is async, so we need to wait until all less is compiled
  • Loading branch information
Tom van Klinken committed Apr 26, 2013
1 parent 9a4d7f8 commit 9065aef
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions lib/huddle.js
@@ -1,10 +1,10 @@
var htmlparser = require('htmlparser'),
fs = require('fs'),
path = require('path'),
extend = require('xtend'),
uglifyjs = require('uglify-js'),
cleancss = require('clean-css'),
less = require('less');

/**
* A library to retrieve CSS and Javascript references from an HTML file and
* pack and compress those files.
Expand Down Expand Up @@ -292,21 +292,39 @@ function Huddle(options) {
data;
for (i in self._stylesheets) {
data = '';
toWait=0;
for (j in self._stylesheets[i]) {
if (self._stylesheets[i][j] === 'text/less') {
less.render(fs.readFileSync(j, 'utf8'), function (e, css) {
oldCwd = process.cwd()
f = path.resolve(j);
process.chdir(path.dirname(f));
toWait++;
less.render(fs.readFileSync(f, 'utf8'), function (e, css) {
data += css;
toWait--;
});
process.chdir(oldCwd);
} else {
data += fs.readFileSync(j, 'utf8');
}
}
fs.writeFileSync(i + '.css',
cleancss.process(data, {
keepSpecialComments: 0,
removeEmpty: true
}),
'utf8');

function checkRender()
{
if (toWait==0)
{
fs.writeFileSync(i + '.css',
cleancss.process(data, {
keepSpecialComments: 0,
removeEmpty: true
}),'utf8');
} else {
setTimeout(checkRender, 100)
}
}
checkRender();


}
}
}
Expand Down

0 comments on commit 9065aef

Please sign in to comment.