Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a7ca555
Showing
12 changed files
with
158 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
language: node_js | ||
node_js: | ||
- "0.10" |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
var Promise = typeof Promise === 'undefined' ? require('promise') : Promise, | ||
promisify = require('promisify-node'), | ||
globby = require('globby'), | ||
path = require('path'), | ||
eol = require('os').EOL, | ||
globbyPromise = promisify(globby); | ||
|
||
function isLess(file) { | ||
return path.extname(file) === '.less'; | ||
} | ||
|
||
function processPaths(paths) { | ||
return paths.filter(function(path) { | ||
if(!isLess(path)) { | ||
console.warn('Here is non-less file: ' + path + ', ignored'); | ||
return false; | ||
} | ||
return true; | ||
}); | ||
} | ||
|
||
module.exports = { | ||
install: function(less, pluginManager) { | ||
function GlobFileManager() { | ||
|
||
} | ||
GlobFileManager.prototype = new less.FileManager(); | ||
GlobFileManager.prototype.constructor = GlobFileManager; | ||
GlobFileManager.prototype.supports = function(filename, currentDirectory, options, environment) { | ||
return (filename).indexOf('*') > -1; | ||
}; | ||
GlobFileManager.prototype.loadFile = function(filename, currentDirectory, options, environment) { | ||
var self = this; | ||
return Promise.all(options.paths.map(function(basePath) { | ||
return globbyPromise(path.join(currentDirectory, filename), {cwd: basePath}); | ||
})).then(function(paths) { | ||
paths = Array.prototype.concat.apply([], paths); | ||
paths = processPaths(paths); | ||
return Promise.all(paths.map(function(file) { | ||
return less.FileManager.prototype.loadFile.call(self, file, currentDirectory, options, environment); | ||
})); | ||
}).then(function(files) { | ||
return {contents: files.map(function(file) { | ||
return file.contents; | ||
}).join(eol), filename: filename}; | ||
}); | ||
}; | ||
GlobFileManager.prototype.loadFileSync = function(filename, currentDirectory, options, environment, encoding) { | ||
var paths = globby.sync(filename, {cwd: currentDirectory}); | ||
paths = processPaths(paths); | ||
return paths.map(function(file) { | ||
return less.FileManager.prototype.loadFileSync.call(this, path.basename(file), path.dirname(file), options, environment, encoding); | ||
}, this).join(eol); | ||
}; | ||
GlobFileManager.prototype.supportsSync = GlobFileManager.prototype.supports; | ||
pluginManager.addFileManager(new GlobFileManager()); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "less-glob", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"dependencies": { | ||
"globby": "^1.1.0", | ||
"promise": "^6.1.0", | ||
"promisify-node": "^0.1.5" | ||
}, | ||
"devDependencies": { | ||
"chai": "^1.10.0", | ||
"less": "^2.4.0", | ||
"mocha": "^2.1.0" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
@import "one/*.less"; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
@import "two/**"; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
@import "one/one"; |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* file:one-sub.less */ | ||
.one-sub { | ||
color: red; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* file:one.less */ | ||
.one { | ||
color: blue; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* file:resource.txt */ | ||
just text resource |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* file:two.less */ | ||
.two { | ||
font-size: 20px; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
var lessGlob = require('../'), | ||
less = require('less'), | ||
fs = require('fs'), | ||
expect = require('chai').expect; | ||
|
||
function readResource(filename) { | ||
return fs.readFileSync(filename, 'utf-8'); | ||
} | ||
|
||
function assertFilesToBeIncluded(output, files) { | ||
var pattern = "file:([\\w\\.\\-]+)", | ||
includes = output.match(new RegExp(pattern, 'g')); | ||
includes.forEach(function(include) { | ||
include = new RegExp(pattern).exec(include)[1]; | ||
expect(files).to.contain(include); | ||
files.splice(files.indexOf(include), 1); | ||
}); | ||
expect(files).to.have.length(0, 'all includes should be found'); | ||
} | ||
|
||
var options = { | ||
paths: ['test/fixtures'], | ||
plugins: [lessGlob] | ||
}; | ||
|
||
describe('less-glob', function() { | ||
it('should import files by glob', function(done) { | ||
less.render(readResource('test/fixtures/all-less.less'), options) | ||
.then(function(output) { | ||
assertFilesToBeIncluded(output.css, [ | ||
'one.less', | ||
'one-sub.less' | ||
]); | ||
}) | ||
.then(done, done); | ||
}); | ||
|
||
it('should ignore non-less files', function(done) { | ||
less.render(readResource('test/fixtures/include-non-less.less'), options) | ||
.then(function(output) { | ||
assertFilesToBeIncluded(output.css, [ | ||
'two.less' | ||
]); | ||
expect(output.css).to.not.contain('file:resource.txt'); | ||
}) | ||
.then(done, done); | ||
}); | ||
|
||
it('should not break standard imports', function(done) { | ||
less.render(readResource('test/fixtures/no-glob.less'), options) | ||
.then(function(output) { | ||
assertFilesToBeIncluded(output.css, [ | ||
'one.less' | ||
]); | ||
}) | ||
.then(done, done); | ||
}); | ||
}); |