Skip to content

Commit

Permalink
Bug-fix: constructor handlers were sometimes not being loaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
theakman2 committed Mar 14, 2014
1 parent 5db0806 commit 0531b3c
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ When you `require` a module asynchronously, webant intelligently tries to includ

### Well tested

Webant is thoroughly tested with 170+ unit tests, most of which use a headless browser ([PhantomJS](http://phantomjs.org)) to ensure the module works in a browser environment as intended.
Webant is thoroughly tested with 180+ unit tests, most of which use a headless browser ([PhantomJS](http://phantomjs.org)) to ensure the module works in a browser environment as intended.

## Dynamic requires

Expand Down
18 changes: 7 additions & 11 deletions lib/util/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ function fetch(str) {
throw new Error("Handler '" + str + "' not found. " +
"Are you sure the package 'webant-handler-" + str + "' is installed?");
}
if (typeof handler === "function") {
handler = new handler();
}
return handler;
}

Expand Down Expand Up @@ -51,17 +54,10 @@ function populate(data,intoHandlers,intoAliases) {
} else if (Array.isArray(data[i])) {
handler = fetch(data[i][0]);
settings = data[i][1];
} else {
var h = data[i];
if (typeof h === "function") {
h = new h();
}
if (
(h.aliases && (typeof h.aliases === "object"))
|| (h.extensions && (typeof h.handle === "function"))
) {
handler = h;
}
} else if (typeof data[i] === "function") {
handler = new data[i]();
} else if (typeof data[i] === "object") {
handler = data[i];
}

if (handler) {
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webant",
"version": "4.3.2",
"version": "4.3.3",
"description": "Bringing CommonJS-style requires to the browser and more.",
"keywords": ["ant", "browser", "browserify", "build", "builder", "bundle", "bundler", "cjs", "commonjs", "deploy", "generator", "make", "modules", "package", "packager", "require", "requirejs", "web", "webant", "webmake"],
"author": "A Kazim",
Expand All @@ -15,7 +15,9 @@
},
"devDependencies": {
"shell-escape": "~0.0.1",
"tap": "~0.4.8"
"tap": "~0.4.8",
"webant-handler-text":"~2.0.0",
"webant-handler-dustjs":"~3.0.0"
},
"repository": "git://github.com/theakman2/node-modules-webant.git",
"bin": "./bin/webant",
Expand Down
6 changes: 6 additions & 0 deletions test/tests/webant-handlers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var webantTester = require("../lib/webant.js");

webantTester("handlers",1,{handlers:["dustjs","text"]},function(obj,data,done){
data.t.equivalent(obj,{a:"Dust file Bob here.",b:"I'm a text file!"});
done();
});
11 changes: 11 additions & 0 deletions test/webant/handlers/build/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/main.js"></script>
</head>
<body>

</body>
</html>
1 change: 1 addition & 0 deletions test/webant/handlers/src/a.dust
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dust file {name} here.
1 change: 1 addition & 0 deletions test/webant/handlers/src/b.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I'm a text file!
6 changes: 6 additions & 0 deletions test/webant/handlers/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var g = {};

g.a = require("./a.dust")({name:"Bob"});
g.b = require("./b.txt");

window.__global = g;

0 comments on commit 0531b3c

Please sign in to comment.