-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Reintroduce the option for multiple compiled stylesheets. * Allow for multiple extensions with --style option. * Simplify precompiler scripts.
- Loading branch information
Showing
6 changed files
with
140 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,30 @@ | ||
var fs = require('fs'), | ||
compilerPath = __dirname + '/precompilers/', | ||
|
||
init = function (compilerPath) { | ||
var precomp = { | ||
mask: '', | ||
count: '', | ||
compilers: {} | ||
}; | ||
|
||
// Read all files from compilerPath | ||
// fs.readdir(compilerPath, function (err, files) { | ||
var files = fs.readdirSync(compilerPath); | ||
|
||
for(var i in files) if (files.hasOwnProperty(i)) { | ||
|
||
var filePath = compilerPath + files[i], | ||
module = require(filePath); | ||
|
||
// If the file is a valid compiler include it | ||
if (module.name && module.ext && module.render) { | ||
|
||
precomp.compilers[module.ext] = module; | ||
precomp.mask += '|\\.' + module.ext; | ||
precomp.count++; | ||
|
||
// Otherwise throw an error | ||
} else { | ||
throw new Error('Invalid precompiler: ' + filePath); | ||
} | ||
} | ||
|
||
precomp.mask = new RegExp(precomp.mask.substring(1) + '|\\.css'); | ||
|
||
return precomp; | ||
path = require('path'), | ||
compilerPath = __dirname + '/precompilers/'; | ||
|
||
var precomp = { | ||
mask: '', | ||
count: 0, | ||
compilers: {} | ||
}; | ||
|
||
// Read all files from compilerPath | ||
var files = fs.readdirSync(compilerPath); | ||
|
||
files.forEach(function(filename) { | ||
var filePath = path.resolve(compilerPath, filename), | ||
module = require(filePath); | ||
|
||
if (module.name && module.extensions && module.render) { | ||
precomp.compilers[module.name] = module; | ||
precomp.mask += '|\\.' | ||
precomp.mask += module.extensions.join('|\\.'); | ||
precomp.count += 1; | ||
} else { | ||
throw new Error('Invalid precompiler: ' + filePath); | ||
} | ||
}) | ||
|
||
precomp.mask = new RegExp(precomp.mask.substring(1) + '|\\.css'); | ||
|
||
module.exports = init(compilerPath) | ||
module.exports = precomp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,20 @@ | ||
var fs = require('fs'), | ||
less = require('less'), | ||
lessCompile = module.exports = {}; | ||
|
||
lessCompile = { | ||
// Name of the stylesheet language | ||
lessCompile.name = 'LESS'; | ||
|
||
// Name of the stylesheet language | ||
name: 'LESS', | ||
// File extension for that language | ||
lessCompile.extensions = ['less']; | ||
|
||
// File extension for that language | ||
ext: 'less', | ||
|
||
// CLI parameter | ||
param: 'l', | ||
|
||
/** | ||
* Compiles the passed file to css and passes | ||
* the resulting css to the given callback | ||
* | ||
* @param {String} file The file to compile | ||
* @param {Function} cb callback(css) | ||
*/ | ||
render: function (file, cb) { | ||
less.render("@import '" + file + "';", function (err, css) { | ||
if (err) { | ||
throw err; | ||
} | ||
cb(css); | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = lessCompile; | ||
/** | ||
* Compiles the passed file to css and passes | ||
* the resulting css to the given callback | ||
* | ||
* @param {String} file The file to compile | ||
* @param {Function} callback (err, css) | ||
*/ | ||
lessCompile.render = function (file, callback) { | ||
less.render("@import '" + file + "';", callback); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,24 @@ | ||
var fs = require('fs'), | ||
sass = require('sass'), | ||
sassCompile = module.exports = {}; | ||
|
||
sassCompile = { | ||
// Name of the stylesheet language | ||
sassCompile.name = 'SASS'; | ||
|
||
// Name of the stylesheet language | ||
name: 'SASS', | ||
// File extension for that language | ||
sassCompile.extensions = ['sass']; | ||
|
||
// File extension for that language | ||
ext: 'sass', | ||
|
||
/** | ||
* Compiles the passed file to css and passes | ||
* the resulting css to the given callback | ||
* | ||
* @param {String} file The file to compile | ||
* @param {Function} cb callback(css) | ||
*/ | ||
render: function (file, cb) { | ||
// sass.render("@import '" + file + "';", function (err, css) { | ||
// if (err) { | ||
// throw new Error(err); | ||
// } | ||
// cb(css); | ||
// }); | ||
var css = sass.render("@import '" + file + "';"); | ||
cb(css); | ||
} | ||
}; | ||
|
||
module.exports = sassCompile; | ||
/** | ||
* Compiles the passed file to css and passes | ||
* the resulting css to the given callback | ||
* | ||
* @param {String} file The file to compile | ||
* @param {Function} callback (err, css) | ||
*/ | ||
sassCompile.render = function (file, callback) { | ||
try { | ||
callback(null, sass.render("@import '" + file + "';")); | ||
} catch(e) { | ||
return callback(e) | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,20 @@ | ||
var fs = require('fs'), | ||
stylus = require('stylus'), | ||
stylusCompile = module.exports = {}; | ||
|
||
stylusCompile = { | ||
// Name of the stylesheet language | ||
stylusCompile.name = 'Stylus'; | ||
|
||
// Name of the stylesheet language | ||
name: 'Stylus', | ||
// File extension for that language | ||
stylusCompile.extensions = ['styl', 'stylus']; | ||
|
||
// File extension for that language | ||
ext: 'styl', | ||
|
||
// CLI parameter | ||
param: 's', | ||
|
||
/** | ||
* Compiles the passed file to css and passes | ||
* the resulting css to the given callback | ||
* | ||
* @param {String} file The file to compile | ||
* @param {Function} cb callback(css) | ||
*/ | ||
render: function (file, cb) { | ||
stylus.render("@import '" + file + "';", function (err, css) { | ||
if (err) { | ||
throw err; | ||
} | ||
cb(css); | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = stylusCompile; | ||
/** | ||
* Compiles the passed file to css and passes | ||
* the resulting css to the given callback | ||
* | ||
* @param {String} file The file to compile | ||
* @param {Function} callback (err, css) | ||
*/ | ||
stylusCompile.render = function (file, callback) { | ||
stylus.render("@import '" + file + "';", callback); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters