Comparing version 1.0.1 to 1.1.0
74
cli.js
@@ -9,13 +9,18 @@ #!/usr/bin/env node | ||
for(var i = 2; i < process.argv.length; i++) { | ||
var file = process.argv[i]; | ||
function render(input, outputFile, directory, callback) { | ||
var buffers = []; | ||
fs.readFile(file, "utf8", function(error, content) { | ||
if(error) { | ||
console.error(error); | ||
process.exit(1); | ||
input.on("error", callback); | ||
output.on("error", callback); | ||
input.on("readable", function() { | ||
var part = input.read(); | ||
if(part) { | ||
buffers.push(part); | ||
} | ||
}); | ||
var directory = path.dirname(path.resolve(file)); | ||
var outputFile = path.join(directory, path.basename(file, ".leaf") + ".html"); | ||
input.on("end", function() { | ||
var content = Buffer.concat(buffers).toString("utf8"); | ||
@@ -28,12 +33,4 @@ var template = razorleaf.compile(content, { | ||
fs.writeFile(outputFile, template(), { | ||
encoding: "utf8", | ||
mode: 0x180 | ||
}, function(error) { | ||
if(error) { | ||
console.error(error); | ||
process.exit(1); | ||
} | ||
console.log("Rendered %s as %s", file, outputFile); | ||
output.write(template(), function() { | ||
callback(null, output); | ||
}); | ||
@@ -43,2 +40,43 @@ }); | ||
function renderedStdin(error) { | ||
if(error) { | ||
console.error(error); | ||
process.exit(1); | ||
} | ||
} | ||
function renderedFile(error, output) { | ||
output.close(); | ||
if(error) { | ||
console.error(error); | ||
process.exit(1); | ||
} | ||
} | ||
for(var i = 2; i < process.argv.length; i++) { | ||
var file = process.argv[i]; | ||
var input; | ||
var output; | ||
var directory; | ||
var callback; | ||
if(file === "-") { | ||
directory = process.cwd(); | ||
input = process.stdin; | ||
output = process.stdout; | ||
callback = renderedStdin; | ||
} else { | ||
directory = path.dirname(path.resolve(file)); | ||
input = fs.createReadStream(file); | ||
var outputFile = path.join(directory, path.basename(file, ".leaf") + ".html"); | ||
output = fs.createWriteStream(outputFile, {mode: 0x180}); | ||
callback = renderedFile; | ||
console.error("Rendering %s as %s", file, outputFile); | ||
} | ||
render(input, output, directory, callback); | ||
} | ||
// vim:ft=javascript |
@@ -180,3 +180,3 @@ "use strict"; | ||
function compile(tree) { | ||
function compile(tree, options) { | ||
var context = { | ||
@@ -192,4 +192,3 @@ content: new OutputBuffer(), | ||
var compiled = new Function( | ||
"__util, data", | ||
var code = | ||
context.scope.code + | ||
@@ -199,4 +198,9 @@ "\n__output = '';\n" + | ||
"\nreturn __output;" | ||
); | ||
var compiled = new Function("__util, data", code); | ||
if(options.debug) { | ||
console.log(code); | ||
} | ||
return function(data) { | ||
@@ -203,0 +207,0 @@ return compiled(utilities, data); |
{ | ||
"name": "razorleaf", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"main": "razorleaf.js", | ||
@@ -23,3 +23,3 @@ "files": [ | ||
"type": "git", | ||
"url": "git://github.com/campersander/razorleaf" | ||
"url": "https://github.com/campersander/razorleaf" | ||
}, | ||
@@ -26,0 +26,0 @@ "bugs": { |
@@ -79,6 +79,7 @@ "use strict"; | ||
options = options || {}; | ||
tree = loadExtends(tree, [], options); | ||
loadIncludes(tree, [], options); | ||
return compiler.compile(tree); | ||
return compiler.compile(tree, options); | ||
} | ||
@@ -85,0 +86,0 @@ |
@@ -44,3 +44,3 @@ [![Build Status](https://travis-ci.org/campersander/razorleaf.png)](https://travis-ci.org/campersander/razorleaf) | ||
```html | ||
-->A string <-- | ||
--> A string <-- | ||
A string containing "double-quotes" | ||
@@ -47,0 +47,0 @@ ``` |
"use strict"; | ||
var amp = /&/g; | ||
var quot = /"/g; | ||
var lt = /</g; | ||
var gt = />/g; | ||
var utilities = { | ||
escapeAttributeValue: function(value) { | ||
return ("" + value).replace(/&/g, "&") | ||
.replace(/"/g, """); | ||
return ("" + value).replace(amp, "&") | ||
.replace(quot, """); | ||
}, | ||
escapeContent: function(content) { | ||
return ("" + content).replace(/&/g, "&") | ||
.replace(/</g, "<") | ||
.replace(/>/g, ">"); | ||
return ("" + content).replace(amp, "&") | ||
.replace(lt, "<") | ||
.replace(gt, ">"); | ||
} | ||
@@ -13,0 +18,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
28122
897