metalsmith-less
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -9,3 +9,3 @@ var _ = require('lodash') | ||
var MAP_RE = /less/g | ||
var INPUT = 'input' | ||
var INPUT_SOURCE = 'input' | ||
@@ -22,14 +22,24 @@ module.exports = plugin | ||
return function (files, metalsmith, done) { | ||
var paths = Object.keys(files).filter(function(path){ | ||
var paths = Object.keys(files).filter(function (path) { | ||
return multimatch(path, pattern).length > 0 | ||
}) | ||
async.each(paths, convert.bind(null, parser, useDefaultSourceMap, renderOptions, files), done) | ||
var iterator = convert.bind(null, { | ||
files: files, | ||
parser: parser, | ||
renderOptions: renderOptions, | ||
useDefaultSourceMap: useDefaultSourceMap | ||
}) | ||
async.each(paths, iterator, done) | ||
} | ||
} | ||
function convert(parser, useDefaultSourceMap, renderOptions, files, filePath, done) { | ||
function convert(options, filePath, done) { | ||
var files = options.files | ||
var parser = options.parser | ||
var renderOptions = options.renderOptions | ||
var useDefaultSourceMap = options.useDefaultSourceMap | ||
var data = files[filePath] | ||
parser.parse(data.contents.toString(), function(err, tree){ | ||
parser.parse(data.contents.toString(), function (err, tree) { | ||
if (err) return done(err) | ||
var destination = map(filePath) | ||
var destination = filePath.replace(MAP_RE, 'css') | ||
var sourceMapDestination | ||
@@ -50,4 +60,5 @@ var sourceMap | ||
writeSourceMap: function (res) { | ||
// This method is invoked synchronously during `tree.toCSS()`. | ||
var sm = JSON.parse(res) | ||
var inputIndex = sm.sources.indexOf(INPUT) | ||
var inputIndex = sm.sources.indexOf(INPUT_SOURCE) | ||
if (inputIndex) sm.sources[inputIndex] = 'src/' + filePath | ||
@@ -71,5 +82,1 @@ sourceMap = JSON.stringify(sm) | ||
} | ||
function map(filePath) { | ||
return filePath.replace(MAP_RE, 'css') | ||
} |
{ | ||
"name": "metalsmith-less", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "A LESS plugin for Metalsmith", | ||
"main": "./lib/", | ||
"scripts": { | ||
"jshint": "./node_modules/.bin/jshint ./lib/ ./test/", | ||
"test": "npm run jshint && ./node_modules/.bin/mocha --reporter spec --grep ''" | ||
"style": "./node_modules/.bin/crispy ./lib/ ./test/", | ||
"test": "npm run style && ./node_modules/.bin/mocha --reporter spec --grep ''" | ||
}, | ||
@@ -29,29 +29,6 @@ "keywords": [ | ||
"assert-dir-equal": "^1.0.1", | ||
"jshint": "^2.5.5", | ||
"crispy": "^2.0.0", | ||
"metalsmith": "^0.11.0", | ||
"mocha": "^1.21.4" | ||
}, | ||
"jshintConfig": { | ||
"asi": true, | ||
"boss": true, | ||
"eqeqeq": true, | ||
"expr": true, | ||
"immed": true, | ||
"latedef": "nofunc", | ||
"laxbreak": true, | ||
"laxcomma": true, | ||
"loopfunc": true, | ||
"newcap": true, | ||
"node": true, | ||
"predef": [ | ||
"describe", | ||
"it" | ||
], | ||
"quotmark": "single", | ||
"scripturl": true, | ||
"sub": true, | ||
"trailing": true, | ||
"undef": true, | ||
"unused": true | ||
} | ||
} |
@@ -5,15 +5,15 @@ var assertDir = require('assert-dir-equal') | ||
describe('metalsmith-less', function(){ | ||
describe('metalsmith-less', function () { | ||
it('should convert less to css', function(done){ | ||
it('should convert less to css', function (done) { | ||
(new Metalsmith('test/fixtures/basic')) | ||
.use(less()) | ||
.build(function(err){ | ||
.build(function (err) { | ||
if (err) return done(err) | ||
assertDir('test/fixtures/basic/expected', 'test/fixtures/basic/build') | ||
return done(null) | ||
}) | ||
}) | ||
}) | ||
it('should convert imported files', function(done){ | ||
it('should convert imported files', function (done) { | ||
(new Metalsmith('test/fixtures/import')) | ||
@@ -26,10 +26,10 @@ .use(less({ | ||
})) | ||
.build(function(err){ | ||
.build(function (err) { | ||
if (err) return done(err) | ||
assertDir('test/fixtures/import/expected', 'test/fixtures/import/build') | ||
return done(null) | ||
}) | ||
}) | ||
}) | ||
it('should create source map', function(done){ | ||
it('should create source map', function (done) { | ||
(new Metalsmith('test/fixtures/source-map')) | ||
@@ -43,9 +43,10 @@ .use(less({ | ||
})) | ||
.build(function(err){ | ||
.build(function (err) { | ||
if (err) return done(err) | ||
assertDir('test/fixtures/source-map/expected', 'test/fixtures/source-map/build') | ||
return done(null) | ||
}) | ||
}) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
135
8774