parent
ccf59fba2a
commit
608119e8ce
@ -1,14 +1,58 @@
|
|||||||
define(['text', 'libjs-jade'], function (text, jade) {
|
define(function() {
|
||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
return {
|
var jade = null,
|
||||||
load: function(name, req, onLoadNative, config) {
|
builds = {};
|
||||||
var onload = function(content) {
|
|
||||||
onLoadNative(jade.compileClient(content));
|
var fetchText = function() {
|
||||||
|
throw new Error("Environment not supported.");
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof process !== "undefined") {
|
||||||
|
var fs = require.nodeRequire("fs");
|
||||||
|
var jade = require.nodeRequire("jade");
|
||||||
|
fetchText = function(path, callback) {
|
||||||
|
callback(fs.readFileSync(path, "utf-8"));
|
||||||
|
};
|
||||||
|
} else if ((typeof window !== "undefined" && window.navigator && window.document) || typeof importScripts !== "undefined") {
|
||||||
|
fetchText = function (url, callback) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('GET', url, true);
|
||||||
|
xhr.onreadystatechange = function() {
|
||||||
|
if (xhr.readyState === 4) {
|
||||||
|
callback(xhr.responseText);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
xhr.send(null);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
|
||||||
|
fetchText: fetchText,
|
||||||
|
|
||||||
|
load: function(name, req, onload, config) {
|
||||||
|
var path = req.toUrl(name + ".jade");
|
||||||
|
fetchText(path, function(text) {
|
||||||
|
if (jade === null) {
|
||||||
|
req(["libjs-jade"], function(jade) {
|
||||||
|
onload(jade.compileClient(text));
|
||||||
|
onload(text);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
builds[name] = jade.compileClient(text);
|
||||||
|
onload(builds[name]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
text.load(name + ".jade", req, onload, config);
|
|
||||||
},
|
},
|
||||||
write: function() {}
|
write: function(plugin, name, write) {
|
||||||
|
if (builds.hasOwnProperty(name)) {
|
||||||
|
write("define('" + plugin + "!" + name +"', function () {" +
|
||||||
|
" var fn = " + builds[name] + ";" +
|
||||||
|
" return fn;" +
|
||||||
|
"});\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in new issue