Permalink
Browse files

Add getDependencies and test based on stylus-brunch

  • Loading branch information...
1 parent 2fc4322 commit 48f5c0fe688353223639827f5e4f190efa9f1574 @joakin joakin committed Mar 11, 2013
Showing with 61 additions and 0 deletions.
  1. +27 −0 src/index.coffee
  2. +34 −0 test/plugin_test.js
View
@@ -6,6 +6,8 @@ module.exports = class JadeCompiler
type: 'template'
extension: 'jade'
+ _dependencyRegExp: /^ *(?:include|extends) (.*)/
+
constructor: (@config) ->
return
@@ -26,3 +28,28 @@ module.exports = class JadeCompiler
include: [
(sysPath.join __dirname, '..', 'vendor', 'runtime.js')
]
+
+ getDependencies: (data, path, callback) =>
+ parent = sysPath.dirname path
+ dependencies = data
+ .split('\n')
+ .map (line) =>
+ line.match(@_dependencyRegExp)
+ .filter (match) =>
+ match?.length > 0
+ .map (match) =>
+ match[1]
+ .filter (path) =>
+ !!path
+ .map (path) =>
+ if sysPath.extname(path) isnt ".#{@extension}"
+ path + ".#{@extension}"
+ else
+ path
+ .map (path) =>
+ if path.charAt(0) is '/'
+ sysPath.join @config.paths.root, path[1..]
+ else
+ sysPath.join parent, path
+ process.nextTick =>
+ callback null, dependencies
View
@@ -1,4 +1,5 @@
var jade = require('jade');
+var sysPath = require('path');
describe('Plugin', function() {
var plugin;
@@ -25,4 +26,37 @@ describe('Plugin', function() {
done();
});
});
+
+
+ describe('getDependencies', function() {
+ it('should output valid deps', function(done) {
+ var content = "\
+include valid1\n\
+include valid1.jade\n\
+include ../../test/valid1\n\
+include ../../test/valid1.jade\n\
+extends valid2\n\
+extends valid2.jade\n\
+include ../../test/valid2\n\
+include ../../test/valid2.jade\n\
+";
+
+ var expected = [
+ sysPath.join('valid1.jade'),
+ sysPath.join('valid1.jade'),
+ sysPath.join('..', '..', 'test', 'valid1.jade'),
+ sysPath.join('..', '..', 'test', 'valid1.jade'),
+ sysPath.join('valid2.jade'),
+ sysPath.join('valid2.jade'),
+ sysPath.join('..', '..', 'test', 'valid2.jade'),
+ sysPath.join('..', '..', 'test', 'valid2.jade')
+ ];
+
+ plugin.getDependencies(content, 'template.jade', function(error, dependencies) {
+ expect(error).not.to.be.ok;
+ expect(dependencies).to.eql(expected);
+ done();
+ });
+ });
+ });
});

0 comments on commit 48f5c0f

Please sign in to comment.