Skip to content

Commit

Permalink
Revert "partials can now also be resolved relative to the containing …
Browse files Browse the repository at this point in the history
…template, this makes using Mu without setting the global root and just using absolute paths easier"

This reverts commit 4aad0f9.

Conflicts:

	lib/mu.js
  • Loading branch information
raycmorgan committed Jun 4, 2012
1 parent 1056b53 commit f239c9c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 76 deletions.
39 changes: 6 additions & 33 deletions lib/mu.js
Expand Up @@ -11,34 +11,9 @@ var mu = module.exports = {};
mu.root = process.cwd(); mu.root = process.cwd();
mu.cache = {}; mu.cache = {};


mu.fs = function (filename, dirname, callback) { mu.fs = function (filename, callback) {
// dirname is optional, so we shift the arguments if it is omitted filename = filename.indexOf('/') === 0 || filename.indexOf(':\\') === 1 ? filename : path.join(mu.root, filename);
if (!callback) { fs.readFile(filename, 'utf8', callback);
callback = dirname;
dirname = undefined;
}

var filenames = [];
if (filename.indexOf('/') === 0 || filename.indexOf(':\\') === 1) {
filenames.push(filename);
} else {
filenames.push(path.join(mu.root, filename));
if (dirname) {
filenames.push(path.join(dirname, filename));
}
}

(function next() {
var file = filenames.shift();
if (file) {
fs.readFile(file, 'utf8', function (err, contents) {
if (err) next();
else callback(undefined, contents, file);
});
} else {
callback(new Error('file_not_found'));
}
}());
} }


/** /**
Expand All @@ -49,14 +24,12 @@ mu.fs = function (filename, dirname, callback) {
* starts with a '/', the file is assumed to be absolute, else it is * starts with a '/', the file is assumed to be absolute, else it is
* relative to mu.root. * relative to mu.root.
* @param {Function(err, Parsed)} callback The function to call when the file has been compiled. * @param {Function(err, Parsed)} callback The function to call when the file has been compiled.
* @param {Object} unique
* @param {String} dirname Directory to use for relative filename lookups.
*/ */
mu.compile = function(filename, callback, unique, dirname) { mu.compile = function(filename, callback, unique) {
var parsed, var parsed,
unique = unique || {}; unique = unique || {};


mu.fs(filename, dirname, function (err, contents, found) { mu.fs(filename, function (err, contents) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
Expand All @@ -71,7 +44,7 @@ mu.compile = function(filename, callback, unique, dirname) {
} }


if (i < parsed.partials.length) { if (i < parsed.partials.length) {
mu.compile(parsed.partials[i], next, unique, path.dirname(found)); mu.compile(parsed.partials[i], next, unique);
i++; i++;


} else { } else {
Expand Down
43 changes: 0 additions & 43 deletions test/run_examples_test_no_root.js

This file was deleted.

0 comments on commit f239c9c

Please sign in to comment.