Skip to content

Commit

Permalink
v0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
zetorama committed Feb 26, 2014
1 parent f41926c commit 4d720e6
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions xt.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ define(['module', 'text', 'deferred'], function (module, text, dfr) {
parent.pop();
parent = parent.join('/');

console.warn('resolveRelativePath', parentFile, path);

if (dirs[0] === '.') {
// The same dir
dirs.shift();
Expand Down Expand Up @@ -260,11 +262,12 @@ define(['module', 'text', 'deferred'], function (module, text, dfr) {
var plugin = this,
dfr = new Deferred(),
remain = urls.length,
ids = urls.slice(),
ids = {},
onError = function onFetchError(err) {
var k, id;
for (k = ids.length; k--;) {
id = ids[k];
var k, url, id;
for (k = urls.length; k--;) {
url = urls[k];
id = ids[url];
if (loading[id]) {
loading[id].reject(err);
delete loading[id];
Expand All @@ -275,19 +278,23 @@ define(['module', 'text', 'deferred'], function (module, text, dfr) {
},
checkDone = function checkFetchDone() {
var files = [],
k, l, id;
k, l, url, id;

if (!--remain) {
for (k = 0, l = ids.length; k < l; k++) {
id = ids[k];
for (k = 0, l = urls.length; k < l; k++) {
url = urls[k];
id = ids[url];
files.push(loaded[id]);
}

dfr.resolveWith(null, files);
}
},
onLoad = function(id, content) {
var data = plugin.parseContent(content, id, req, config);
onLoad = function(url, content) {
var id = ids[url],
data = plugin.parseContent(content, url, req, config);

data.id = id;

plugin.process(data, req, config)
.done(function(template) {
Expand All @@ -300,9 +307,9 @@ define(['module', 'text', 'deferred'], function (module, text, dfr) {
})
.fail(onError);
},
getOnLoad = function(id) {
getOnLoad = function(url) {
var closure = function(content) {
onLoad(id, content);
onLoad(url, content);
};

closure.error = onError;
Expand All @@ -313,17 +320,17 @@ define(['module', 'text', 'deferred'], function (module, text, dfr) {
for (k = remain; k--;) {
url = urls[k];
id = req.toUrl(url);
ids[k] = id;
ids[url] = id;

if (loaded[id]) {
checkDone(id);
checkDone();
} else if (loading[id]) {
loading[id]
.done(checkDone)
.fail(onError);
} else {
loading[id] = new Deferred();
text.load(url, req, getOnLoad(id), config);
text.load(url, req, getOnLoad(url), config);
}
}

Expand All @@ -333,7 +340,7 @@ define(['module', 'text', 'deferred'], function (module, text, dfr) {
parseContent: function(content, url, req, config) {
var plugin = this,
data = {
id: req.toUrl(url),
url: url,
partials: {},
wrappers: {},
wrapMap: {},
Expand Down

0 comments on commit 4d720e6

Please sign in to comment.