Skip to content
This repository
Browse code

Fixed a buffering issue and parrot now preserves line breaks.

  • Loading branch information...
commit 5045c5d3289ec1dfccfeb0daf4343865ffb0c378 1 parent 0d29590
authored

Showing 1 changed file with 9 additions and 7 deletions. Show diff stats Hide diff stats

  1. 16  index.js
16  index.js
@@ -27,7 +27,7 @@ var crypto = require('crypto'),
27 27
     cache  = { };
28 28
 
29 29
 // Defines parrot's version
30  
-exports.version = '0.2.1';
  30
+exports.version = '0.2.2';
31 31
 
32 32
 // Global configuration
33 33
 exports.config = {
@@ -74,8 +74,9 @@ exports.render = function(data, config, onprint) {
74 74
     }
75 75
     else {
76 76
 
77  
-        // Set the cache configuration if none is defiend
78  
-        config.cache = config.cache || exports.config.cache;
  77
+        // Set the cache and buffer configuration if none is defiend
  78
+        config.cache  = config.cache  || exports.config.cache;
  79
+		config.buffer = config.buffer || exports.config.buffer; 
79 80
 
80 81
         if (config.tags === undefined) {
81 82
 
@@ -127,7 +128,7 @@ exports.render = function(data, config, onprint) {
127 128
         if ( ! config.buffer && typeof onprint === 'function') {
128 129
 
129 130
             // Call the function with the data chunk
130  
-            onprint.call(this, chunk);
  131
+            onprint(chunk);
131 132
         }
132 133
 
133 134
         // Append any data to the output buffer
@@ -155,8 +156,9 @@ exports.render = function(data, config, onprint) {
155 156
         .replace(new RegExp(st + '=\\s*(.+)\\s*' + et, 'gm'), '"); print($1); print("')
156 157
         .replace(new RegExp(st + '\\s*end(if|while|for|switch);*\\s*' + et, 'gmi'), '"); } print("')
157 158
         .replace(new RegExp(st + '\\s*(.+)\\s*' + et, 'gm'), '"); $1 print("')
158  
-        .replace(/(\r\n|\r|\n)/gmi, '\\$1');
159  
-
  159
+        .replace(/\n/gm, '\\n')
  160
+		.replace(/\r/gm, '\\r');
  161
+	
160 162
     // Execute the script, rendering the template
161 163
     Script.runInNewContext(data, config.sandbox);
162 164
 
@@ -179,7 +181,7 @@ exports.render = function(data, config, onprint) {
179 181
     if (config.buffer && typeof onprint == 'function') {
180 182
 
181 183
         // Return the output value
182  
-        return onprint.call(this, output);
  184
+        return onprint(output);
183 185
     }
184 186
 
185 187
     // Return the output

0 notes on commit 5045c5d

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