Skip to content
Browse files

Rename fileName to filename

  • Loading branch information...
1 parent c0cafc5 commit e8ef61dbd99d0014e62a440cf2e2e56cb99f6332 @curvedmark committed Mar 25, 2013
View
64 bin/roole
@@ -67,45 +67,45 @@ function compileStdin(callback) {
});
}
-function resolveFiles(filePaths, dirPath) {
+function resolveFiles(filenames, dirname) {
var files = [];
- filePaths.forEach(function(filePath) {
- var stat = fs.statSync(filePath);
+ filenames.forEach(function(filename) {
+ var stat = fs.statSync(filename);
if (stat.isFile()) {
var file = {
- path: filePath,
- content: fs.readFileSync(filePath, 'utf8')
+ name: filename,
+ content: fs.readFileSync(filename, 'utf8')
};
if (!program.out) {
- file.outputPath = file.path;
+ file.outputName = file.name;
} else {
- if (!dirPath) {
- var base = path.basename(file.path);
- file.outputPath = path.join(program.out, base);
+ if (!dirname) {
+ var base = path.basename(file.name);
+ file.outputName = path.join(program.out, base);
} else {
- var subpath = path.relative(dirPath, file.path);
- file.outputPath = path.join(program.out, subpath);
+ var relpath = path.relative(dirname, file.name);
+ file.outputName = path.join(program.out, relpath);
}
}
- file.outputPath = file.outputPath.replace(/\.roo$|$/, '.css');
+ file.outputName = file.outputName.replace(/\.roo$|$/, '.css');
files.push(file);
} else if (stat.isDirectory()) {
- var dir = filePath;
- var filePaths = fs.readdirSync(dir);
- filePaths = filePaths.map(function(filePath) {
- return path.join(dir, filePath);
- }).filter(function(filePath) {
- var stat = fs.statSync(filePath);
+ var dir = filename;
+ var filenames = fs.readdirSync(dir);
+ filenames = filenames.map(function(filename) {
+ return path.join(dir, filename);
+ }).filter(function(filename) {
+ var stat = fs.statSync(filename);
if (stat.isFile()) {
- var hasExt = /\.roo$/.test(filePath);
+ var hasExt = /\.roo$/.test(filename);
return hasExt;
}
return stat.isDirectory();
});
- files = files.concat(resolveFiles(filePaths, dirPath || filePath));
+ files = files.concat(resolveFiles(filenames, dirname || filename));
}
});
return files;
@@ -125,7 +125,7 @@ function compileFiles(files, callback) {
}
function compileFile(file, callback) {
- options.fileName = file.path;
+ options.filename = file.name;
roole.compile(file.content, options, function(error, css) {
if (error) {
throw error;
@@ -146,29 +146,29 @@ function writeFiles(files) {
function writeFile(file, watching) {
if (!file.compiledContent && !program.force) {
if (!program.watch) {
- console.log('INFO:', file.path, 'compiles to empty string, not writing to file');
+ console.log('INFO:', file.name, 'compiles to empty string, not writing to file');
} else if (watching) {
- console.log(' compiled', file.path, 'to empty string, not writing to file');
+ console.log(' compiled', file.name, 'to empty string, not writing to file');
}
} else {
- var dir = path.dirname(file.outputPath);
+ var dir = path.dirname(file.outputName);
if (!existsSync(dir)) { mkdirp.sync(dir); }
- fs.writeFileSync(file.outputPath, file.compiledContent);
+ fs.writeFileSync(file.outputName, file.compiledContent);
if (program.watch && watching) {
- console.log(' compiled', file.path, 'to', file.outputPath);
+ console.log(' compiled', file.name, 'to', file.outputName);
}
}
}
function watchFiles(files) {
- program.args.forEach(function(filePath) {
- var stat = fs.statSync(filePath);
- if (stat.isDirectory() && filePath.slice(-1) !== '/') {
- filePath += '/';
+ program.args.forEach(function(filename) {
+ var stat = fs.statSync(filename);
+ if (stat.isDirectory() && filename.slice(-1) !== '/') {
+ filename += '/';
}
- console.log(' watching', filePath);
+ console.log(' watching', filename);
});
files.forEach(function(file) {
@@ -177,7 +177,7 @@ function watchFiles(files) {
}
function watchFile(file) {
- fs.watchFile(file.path, {interval: 100}, function(curr, prev) {
+ fs.watchFile(file.name, {interval: 100}, function(curr, prev) {
if (curr.mtime <= prev.mtime) {
return;
}
View
2 lib/browser.js
@@ -33,7 +33,7 @@ Array.prototype.forEach.call(elements, function(element) {
throw error;
}
- options.fileName = url;
+ options.filename = url;
roole.compile(content, options, function(error, css) {
if (error) {
displayError(error.message);
View
4 lib/err.js
@@ -6,13 +6,13 @@
'use strict';
/* exported Err */
-var Err = module.exports = function(message, node, fileName) {
+var Err = module.exports = function(message, node, filename) {
var error = new Error(message);
error.line = node.loc.line;
error.column = node.loc.column;
error.offset = node.loc.offset;
- error.fileName = fileName;
+ error.filename = filename;
return error;
};
View
6 lib/evaluator/node/arithmetic.js
@@ -104,7 +104,7 @@ Evaluator.prototype.visitArithmetic = function(arithmeticNode) {
case 'dimension / percentage':
var divisor = rightNode.children[0];
if (!divisor) {
- throw Err('divide by zero', rightNode, this.fileName);
+ throw Err('divide by zero', rightNode, this.filename);
}
var leftClone = Node.clone(leftNode);
@@ -115,7 +115,7 @@ Evaluator.prototype.visitArithmetic = function(arithmeticNode) {
case 'number / percentage':
var divisor = rightNode.children[0];
if (!divisor) {
- throw Err('divide by zero', rightNode, this.fileName);
+ throw Err('divide by zero', rightNode, this.filename);
}
var rightClone = Node.clone(rightNode);
@@ -136,5 +136,5 @@ Evaluator.prototype.visitArithmetic = function(arithmeticNode) {
return leftClone;
}
- throw Err("unsupported binary operation: '" + leftNode.type + "' " + operator + " '" + rightNode.type + "'", leftNode, this.fileName);
+ throw Err("unsupported binary operation: '" + leftNode.type + "' " + operator + " '" + rightNode.type + "'", leftNode, this.filename);
};
View
2 lib/evaluator/node/call.js
@@ -14,7 +14,7 @@ Evaluator.prototype.visitCall = function(callNode) {
}
if (functionNode.type !== 'function') {
- throw Err("'" + functionNode.type + "' is not a 'function'", functionNode, this.fileName);
+ throw Err("'" + functionNode.type + "' is not a 'function'", functionNode, this.filename);
}
this.scope.add();
View
2 lib/evaluator/node/classSelector.js
@@ -8,7 +8,7 @@ Evaluator.prototype.visitClassSelector = function(classSelectorNode) {
var valueNode = classSelectorNode.children[0];
if (valueNode.type !== 'identifier') {
- throw Err("'" + valueNode.type + "' can not be used in class selector", valueNode, this.fileName);
+ throw Err("'" + valueNode.type + "' can not be used in class selector", valueNode, this.filename);
}
var value = valueNode.children[0];
View
4 lib/evaluator/node/for.js
@@ -10,11 +10,11 @@ Evaluator.prototype.visitFor = function(forNode) {
if (stepNode) {
stepNumber = Node.toNumber(stepNode);
if (stepNumber === null) {
- throw Err("step number must be a numberic value", stepNode, this.fileName);
+ throw Err("step number must be a numberic value", stepNode, this.filename);
}
if (!stepNumber) {
- throw Err("step number is not allowed to be zero", stepNode, this.fileName);
+ throw Err("step number is not allowed to be zero", stepNode, this.filename);
}
}
View
2 lib/evaluator/node/identifier.js
@@ -10,7 +10,7 @@ Evaluator.prototype.visitIdentifier = function(identifierNode) {
var value = childNodes.map(function(childNode) {
var value = Node.toString(childNode);
if (value === null) {
- throw Err("'" + childNode.type + "' is not allowed to be interpolated in 'identifier'", childNode, this.fileName);
+ throw Err("'" + childNode.type + "' is not allowed to be interpolated in 'identifier'", childNode, this.filename);
}
return value;
View
2 lib/evaluator/node/mediaQueryInterpolation.js
@@ -15,7 +15,7 @@ Evaluator.prototype.visitMediaInterpolation = function(mediaInterpolationNode) {
var value = valueNode.children[0].trim();
var options = {
- fileName: this.fileName,
+ filename: this.filename,
startRule: 'mediaQuery',
loc: valueNode.loc
};
View
4 lib/evaluator/node/module.js
@@ -10,13 +10,13 @@ Evaluator.prototype.visitModule = function(moduleNode) {
var nameNode = this.visit(moduleNode.children[0]);
var name = Node.toString(nameNode);
if (name === null) {
- throw Err("'" + nameNode.type + "' can not be used as a module name" , nameNode, this.fileName);
+ throw Err("'" + nameNode.type + "' can not be used as a module name" , nameNode, this.filename);
}
var separatorNode = this.visit(moduleNode.children[1]);
var separator = separatorNode ? Node.toString(separatorNode) : '-';
if (separator === null) {
- throw Err("'" + separatorNode.type + "' can not be used as a module name separator" , separatorNode, this.fileName);
+ throw Err("'" + separatorNode.type + "' can not be used as a module name separator" , separatorNode, this.filename);
}
this.parentModuleName = parentModuleName + name + separator;
View
2 lib/evaluator/node/range.js
@@ -18,6 +18,6 @@ Evaluator.prototype.visitRange = function(rangeNode) {
}
if (invalidNode) {
- throw Err("only numberic values are allowed in 'range'", invalidNode, this.fileName);
+ throw Err("only numberic values are allowed in 'range'", invalidNode, this.filename);
}
};
View
2 lib/evaluator/node/return.js
@@ -5,7 +5,7 @@ var Evaluator = require('../evaluator');
Evaluator.prototype.visitReturn = function(returnNode) {
if (!this.insideFunction) {
- throw Err('@return is only allowed inside @function', returnNode, this.fileName);
+ throw Err('@return is only allowed inside @function', returnNode, this.filename);
}
if (!this.insideMixin) {
View
6 lib/evaluator/node/root.js
@@ -3,10 +3,10 @@
var Evaluator = require('../evaluator');
Evaluator.prototype.visitRoot = function(rootNode) {
- var fileName = this.fileName;
- this.fileName = rootNode.fileName;
+ var filename = this.filename;
+ this.filename = rootNode.filename;
this.visit(rootNode.children);
- this.fileName = fileName;
+ this.filename = filename;
};
View
2 lib/evaluator/node/selectorInterpolation.js
@@ -14,7 +14,7 @@ Evaluator.prototype.visitSelectorInterpolation = function(selectorInterpolationN
var value = valueNode.children[0].trim();
var options = {
- fileName: this.fileName,
+ filename: this.filename,
startRule: 'selector',
loc: valueNode.loc
};
View
2 lib/evaluator/node/string.js
@@ -13,7 +13,7 @@ Evaluator.prototype.visitString = function(stringNode) {
var value = childNodes.map(function(childNode) {
var value = Node.toString(childNode);
if (value === null) {
- throw Err("'" + childNode.type + "' is not allowed to be interpolated in 'string'", childNode, this.fileName);
+ throw Err("'" + childNode.type + "' is not allowed to be interpolated in 'string'", childNode, this.filename);
}
if (childNode.type === 'string') {
View
2 lib/evaluator/node/unary.js
@@ -28,5 +28,5 @@ Evaluator.prototype.visitUnary = function(unaryNode) {
return operandClone;
}
- throw Err("unsupported unary operation: " + operator + "'" + operandNode.type + "'", unaryNode, this.fileName);
+ throw Err("unsupported unary operation: " + operator + "'" + operandNode.type + "'", unaryNode, this.filename);
};
View
2 lib/evaluator/node/variable.js
@@ -9,7 +9,7 @@ Evaluator.prototype.visitVariable = function(variableNode) {
var valueNode = this.scope.resolve(variableName);
if (!valueNode) {
- throw Err('$' + variableName + ' is undefined', variableNode, this.fileName);
+ throw Err('$' + variableName + ' is undefined', variableNode, this.filename);
}
valueNode = Node.clone(valueNode, false);
View
4 lib/extender/node/ampersandSelector.js
@@ -6,7 +6,7 @@ var Extender = require('../extender');
Extender.prototype.visitAmpersandSelector = function(ampersandSelectorNode) {
if (!this.parentSelector) {
- throw Err("& selector is not allowed at the top level", ampersandSelectorNode, this.fileName);
+ throw Err("& selector is not allowed at the top level", ampersandSelectorNode, this.filename);
}
this.hasAmpersandSelector = true;
@@ -20,7 +20,7 @@ Extender.prototype.visitAmpersandSelector = function(ampersandSelectorNode) {
case 'typeSelector':
break;
default:
- throw Err("parent selector '" + lastNode.type + "' is not allowed to be appended", ampersandSelectorNode, this.fileName);
+ throw Err("parent selector '" + lastNode.type + "' is not allowed to be appended", ampersandSelectorNode, this.filename);
}
var lastClone = Node.clone(lastNode);
View
6 lib/extender/node/root.js
@@ -3,14 +3,14 @@
var Extender = require('../extender');
Extender.prototype.visitRoot = function(rootNode) {
- var fileName = this.fileName;
- this.fileName = rootNode.fileName;
+ var filename = this.filename;
+ this.filename = rootNode.filename;
var extendBoundaryNode = this.extendBoundaryNode;
this.extendBoundaryNode = rootNode;
this.visit(rootNode.children);
- this.fileName = fileName;
+ this.filename = filename;
this.extendBoundaryNode = extendBoundaryNode;
};
View
2 lib/extender/node/selector.js
@@ -16,7 +16,7 @@ Extender.prototype.visitSelector = function(selectorNode) {
var startWithCombinator = firstNode.type === 'combinator';
if (startWithCombinator) {
if (!this.parentSelector) {
- throw Err("selector starting with a combinator is not allowed at the top level", firstNode, this.fileName);
+ throw Err("selector starting with a combinator is not allowed at the top level", firstNode, this.filename);
}
selectorNode.children = this.parentSelector.children.concat(selectorNode.children);
View
4 lib/formatter.js
@@ -15,7 +15,7 @@ formatter.format = function(error, input) {
var lineNumber = error.line;
var columnNumber = error.column;
- var fileName = error.fileName;
+ var filename = error.filename;
var lines = input.split(/\r\n|[\r\n]/);
var siblingLineSize = 4;
var startLineNumber = Math.max(lineNumber - siblingLineSize, 1);
@@ -53,6 +53,6 @@ formatter.format = function(error, input) {
}, '');
return message +
- '\n\n ' + '(' + (fileName ? fileName + ' ' : '') + error.line + ':' + error.column + ')' +
+ '\n\n ' + '(' + (filename ? filename + ' ' : '') + error.line + ':' + error.column + ')' +
'\n' + context;
};
View
30 lib/importer/importer.js
@@ -46,12 +46,12 @@ Importer.prototype.visitRuleList = Importer.prototype.visitNode;
Importer.prototype.visitNode = _.noop;
Importer.prototype.visitRoot = function(rootNode) {
- var fileName = this.fileName;
- this.fileName = rootNode.fileName;
+ var filename = this.filename;
+ this.filename = rootNode.filename;
this.visit(rootNode.children);
- this.fileName = fileName;
+ this.filename = filename;
};
Importer.prototype.visitImport = function(importNode) {
@@ -65,33 +65,33 @@ Importer.prototype.visitImport = function(importNode) {
return;
}
- var fileName = urlNode.children[0];
- if (/^\w+:\/\//.test(fileName)) {
+ var filename = urlNode.children[0];
+ if (/^\w+:\/\//.test(filename)) {
return;
}
- if (!/\.[a-z]+$/i.test(fileName)) {
- fileName += '.roo';
+ if (!/\.[a-z]+$/i.test(filename)) {
+ filename += '.roo';
}
- fileName = _.joinPaths(_.dirname(this.fileName), fileName);
+ filename = _.joinPaths(_.dirname(this.filename), filename);
- if (this.imported[fileName]) {
+ if (this.imported[filename]) {
return null;
}
- this.imported[fileName] = true;
+ this.imported[filename] = true;
- var content = this.imports[fileName];
+ var content = this.imports[filename];
if (typeof content === 'string') {
- var ast = parser.parse(content, {fileName: fileName});
+ var ast = parser.parse(content, {filename: filename});
return this.visit(ast);
}
++this.importing;
var callback = this.callback;
- loader.load(fileName, function(error, content) {
+ loader.load(filename, function(error, content) {
if (this.hasError) {
return;
}
@@ -103,8 +103,8 @@ Importer.prototype.visitImport = function(importNode) {
var rootNode;
try {
- this.imports[fileName] = content;
- rootNode = parser.parse(content, {fileName: fileName});
+ this.imports[filename] = content;
+ rootNode = parser.parse(content, {filename: filename});
this.visit(rootNode);
} catch (error) {
this.hasError = true;
View
2 lib/normalizer/node/media.js
@@ -34,7 +34,7 @@ Normalizer.prototype.visitMedia = function(mediaNode) {
if (propertyNodes.length) {
if (!this.parentSelectorList) {
- throw Err("@media containing properties is not allowed at the top level", mediaNode, this.fileName);
+ throw Err("@media containing properties is not allowed at the top level", mediaNode, this.filename);
}
var firstPropertyNode = propertyNodes[0];
View
6 lib/normalizer/node/root.js
@@ -6,13 +6,13 @@ Normalizer.prototype.visitRoot = function(rootNode) {
var parentRoot = this.parentRoot;
this.parentRoot = rootNode;
- var fileName = this.fileName;
- this.fileName = rootNode.fileName;
+ var filename = this.filename;
+ this.filename = rootNode.filename;
var childNodes = this.visit(rootNode.children);
this.parentRoot = parentRoot;
- this.fileName = fileName;
+ this.filename = filename;
if (parentRoot && !childNodes.length) {
return null;
View
6 lib/parser/index.js
@@ -4,11 +4,11 @@ var generatedParser = require('./generatedParser');
var parser = exports;
parser.parse = function(input, options) {
- var fileName = options.fileName;
+ var filename = options.filename;
try {
var ast = generatedParser.parse(input, options);
- if (ast.type === 'root') { ast.fileName = fileName; }
+ if (ast.type === 'root') { ast.filename = filename; }
return ast;
} catch(error) {
@@ -27,7 +27,7 @@ parser.parse = function(input, options) {
}
}
error.message = "unexpected " + found;
- error.fileName = fileName;
+ error.filename = filename;
if (options.loc) {
error.line = options.loc.line;
View
6 lib/roole.js
@@ -26,17 +26,17 @@ roole.compile = function(input, options, callback) {
options = {};
}
- if (options.fileName == null) { options.fileName = ''; }
+ if (options.filename == null) { options.filename = ''; }
if (options.imports == null) { options.imports = {}; }
if (options.prettyError == null) { options.prettyError = defaults.prettyError; }
- options.imports[options.fileName] = input;
+ options.imports[options.filename] = input;
if (options.prettyError) {
var _callback = callback;
callback = function(error, ast) {
if (error && error.line) {
- input = options.imports[error.fileName];
+ input = options.imports[error.filename];
error.message = formatter.format(error, input);
}
View
34 test/assert.js
@@ -67,7 +67,7 @@ assert.failAt = function(options, input, loc) {
}
}
- if (!loc.fileName) { loc.fileName = ''; }
+ if (!loc.filename) { loc.filename = ''; }
var called = false;
roole.compile(input, options, function(error) {
@@ -93,8 +93,8 @@ assert.failAt = function(options, input, loc) {
throw error;
}
- if (error.fileName !== loc.fileName) {
- var message = 'error has file path ' + error.fileName + ' instead of ' + loc.fileName;
+ if (error.filename !== loc.filename) {
+ var message = 'error has file path ' + error.filename + ' instead of ' + loc.filename;
error.message = message + ':\n\n' + error.message;
throw error;
}
@@ -123,15 +123,15 @@ assert.run = function(cmd, input, output) {
};
if (input.files) {
- for (var fileName in input.files) {
- var fileContent = input.files[fileName];
- fileName = path.join(dir, fileName);
+ for (var filename in input.files) {
+ var fileContent = input.files[filename];
+ filename = path.join(dir, filename);
- if (existsSync(fileName)) {
- return callback(new Error("'" + fileName + "' already exists"));
+ if (existsSync(filename)) {
+ return callback(new Error("'" + filename + "' already exists"));
}
- var fileDir = path.dirname(fileName);
+ var fileDir = path.dirname(filename);
if (!existsSync(fileDir)) {
mkdirp.sync(fileDir);
}
@@ -140,7 +140,7 @@ assert.run = function(cmd, input, output) {
fileContent = fileContent.join('\n');
}
- fs.writeFileSync(fileName, fileContent);
+ fs.writeFileSync(filename, fileContent);
}
}
@@ -160,26 +160,26 @@ assert.run = function(cmd, input, output) {
return callback(new Error('stdout is\n"""\n' + stdout + '\n"""\n\ninstead of\n\n"""\n' + output.stdout + '\n"""'));
}
} else if (output.files) {
- for (var fileName in output.files) {
- var fileContent = output.files[fileName];
- fileName = path.join(dir, fileName);
+ for (var filename in output.files) {
+ var fileContent = output.files[filename];
+ filename = path.join(dir, filename);
if (fileContent === null) {
- if (existsSync(fileName)) {
- return callback(new Error('"' + fileName + '" is created, which is not supposed to be'));
+ if (existsSync(filename)) {
+ return callback(new Error('"' + filename + '" is created, which is not supposed to be'));
}
continue;
}
- var realContent = fs.readFileSync(fileName, 'utf8');
+ var realContent = fs.readFileSync(filename, 'utf8');
if (Array.isArray(fileContent)) {
fileContent = fileContent.join('\n');
}
if (realContent !== fileContent) {
- return callback(new Error('"' + fileName + '" is\n"""\n' + realContent + '\n"""\n\ninstead of\n\n"""\n' + fileContent + '\n"""'));
+ return callback(new Error('"' + filename + '" is\n"""\n' + realContent + '\n"""\n\ninstead of\n\n"""\n' + fileContent + '\n"""'));
}
}
}
View
2 test/unit/import.js
@@ -218,5 +218,5 @@ test('not allow importing file has syntax error', function() {
]
}}, [
'@import "base";',
- ], {line: 1, column: 7, fileName: 'base.roo'});
+ ], {line: 1, column: 7, filename: 'base.roo'});
});

0 comments on commit e8ef61d

Please sign in to comment.
Something went wrong with that request. Please try again.