| 
									
										
										
										
											2012-04-05 20:59:01 +08:00
										 |  |  | require = require("../require-polyfill")(require.valueOf()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var fs = require("fs"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = function(template, filesReq, stdout, prefix) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var regexp = new RegExp("\\{\\{" + (prefix ? prefix+":" : "") + "([^:\\}]+)\\}\\}", "g") | 
					
						
							| 
									
										
										
										
											2012-05-07 03:07:24 +08:00
										 |  |  | 	var cwd = process.cwd(); | 
					
						
							|  |  |  | 	cwd = cwd.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); | 
					
						
							|  |  |  | 	cwd = new RegExp(cwd, "g"); | 
					
						
							| 
									
										
										
										
											2012-04-05 20:59:01 +08:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	return template.replace(regexp, function(match) { | 
					
						
							|  |  |  | 		match = match.substr(2 + (prefix ? prefix.length+1 : 0), match.length - 4 - (prefix ? prefix.length+1 : 0)); | 
					
						
							|  |  |  | 		if(match === "stdout") | 
					
						
							|  |  |  | 			return stdout; | 
					
						
							|  |  |  | 		return filesReq("./" + match); | 
					
						
							| 
									
										
										
										
											2012-05-07 03:07:24 +08:00
										 |  |  | 	}).replace(cwd, "."); | 
					
						
							| 
									
										
										
										
											2012-04-05 20:59:01 +08:00
										 |  |  | 	 | 
					
						
							|  |  |  | } |