Permalink
Browse files

Revert "partials can now also be resolved relative to the containing …

…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...
1 parent 1056b53 commit f239c9cd0ae397a5171f5d01968c54b5076b90d4 @raycmorgan committed Jun 4, 2012
Showing with 6 additions and 76 deletions.
  1. +6 −33 lib/mu.js
  2. +0 −43 test/run_examples_test_no_root.js
View
@@ -11,34 +11,9 @@ var mu = module.exports = {};
mu.root = process.cwd();
mu.cache = {};
-mu.fs = function (filename, dirname, callback) {
- // dirname is optional, so we shift the arguments if it is omitted
- if (!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'));
- }
- }());
+mu.fs = function (filename, callback) {
+ filename = filename.indexOf('/') === 0 || filename.indexOf(':\\') === 1 ? filename : path.join(mu.root, filename);
+ fs.readFile(filename, 'utf8', callback);
}
/**
@@ -49,14 +24,12 @@ mu.fs = function (filename, dirname, callback) {
* starts with a '/', the file is assumed to be absolute, else it is
* relative to mu.root.
* @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,
unique = unique || {};
- mu.fs(filename, dirname, function (err, contents, found) {
+ mu.fs(filename, function (err, contents) {
if (err) {
return callback(err);
}
@@ -71,7 +44,7 @@ mu.compile = function(filename, callback, unique, dirname) {
}
if (i < parsed.partials.length) {
- mu.compile(parsed.partials[i], next, unique, path.dirname(found));
+ mu.compile(parsed.partials[i], next, unique);
i++;
} else {
@@ -1,43 +0,0 @@
-var assert = require('assert'),
- fs = require('fs'),
- path = require('path'),
- mu = require('../lib/mu');
-
-// This tests if Mu also works without using the mu.root variable, and only supplying absolute paths.
-
-mu.root = '/tmp/nonexistant';
-
-[
- 'boolean',
- 'carriage_return',
- 'comments',
- 'complex',
- 'deep_partial',
- // 'delimiters',
- 'error_not_found',
- 'escaped',
- 'hash_instead_of_array',
- 'inverted',
- 'partial',
- 'recursion_with_same_names',
- 'reuse_of_enumerables',
- 'simple',
- 'twice',
- 'two_in_a_row',
- 'unescaped'
-].forEach(function (name) {
- var js = fs.readFileSync(path.join(__dirname, 'examples', name + '.js')).toString(),
- text = fs.readFileSync(path.join(__dirname, 'examples', name + '.txt')).toString();
-
- js = eval('(' + js + ')');
-
- var buffer = '';
-
- mu.compileAndRender(path.join(__dirname, 'examples', name + '.html'), js)
- .on('data', function (c) { buffer += c.toString(); })
- .on('end', function () {
- console.log("Testing: " + name);
- assert.equal(buffer, text);
- console.log(name + ' passed\n');
- });
-});

0 comments on commit f239c9c

Please sign in to comment.