Skip to content
Browse files

Fixed a number of bugs i must of overlooked.

  • Loading branch information...
1 parent 7e53cbd commit 25c87eb34c338e96278f0a002347a98cc4e6576e Oliver Morgan committed Aug 29, 2010
Showing with 9 additions and 4 deletions.
  1. +9 −4 index.js
View
13 index.js
@@ -1,18 +1,21 @@
var Script = process.binding('evals').Script;
-exports = function(data, sandbox) {
+exports.render = function(data, sandbox) {
// Default sanbox to an empty object
sandbox = sandbox || {};
+ // Parrot can only process strings
+ data = data.toString();
+
// Escape double quoted strings and default to print
data = 'print("' + data.replace(/"/gm, '\\"') + '");';
// Compile the input into executable javascript
data = data.replace(/:\s*%>/gm, '{ %>')
- .replace(/<%=\s*(.+)\s*%>/gm, '") print($1); print("')
- .replace(/<%\s*end(if|while|for|switch);*\s*/gmi, '}')
- .replace(/<%\s*(.+)\s*%>/gm, '"); $1; print("')
+ .replace(/<%=\s*(.+)\s*%>/gm, '"); print($1); print("')
+ .replace(/<%\s*end(if|while|for|switch);*\s*%>/gmi, '"); } print("')
+ .replace(/<%\s*(.+)\s*%>/gm, '"); $1 print("')
.replace(/(\r\n|\r|\n)/gmi, '\\$1');
// Get ready to take the output data
@@ -25,6 +28,8 @@ exports = function(data, sandbox) {
output += data;
}
+ console.log(data);
+
// Execute the script, rendering the template
Script.runInNewContext(data, sandbox);

0 comments on commit 25c87eb

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