Permalink
Browse files

Refactored `blade.Runtime.include` and fixed `runtime-meteor.js` to f…

…ix file includes (fixes #154)

Push to 3.0.3
  • Loading branch information...
1 parent 68afeec commit 30e8c96e19afbda6c03d07250c4cc2fa63daec76 @bminer committed Mar 17, 2013
Showing with 20 additions and 19 deletions.
  1. +16 −17 lib/runtime.js
  2. +2 −0 meteor/runtime-meteor.js
  3. +1 −1 package.json
  4. +1 −1 smart.json
View
@@ -332,16 +332,13 @@
}
};
- runtime.include = function(relFilename, info) {
+ var includeFields = ["inc", "base", "rel", "filename", "line", "col", "source", "locals"];
+ runtime._beforeInclude = function(relFilename, info) {
//Save template-specific information
- var pInc = info.inc,
- pBase = info.base,
- pRel = info.rel,
- pFilename = info.filename,
- pLine = info.line,
- pCol = info.col,
- pSource = info.source,
- pLocals = info.locals;
+ var old = {};
+ includeFields.forEach(function(field) {
+ old[field] = info[field];
+ });
info.inc = true;
//If exposing locals, the included view gets its own set of locals
if(arguments.length > 2)
@@ -350,6 +347,10 @@
for(var i = 2; i < arguments.length; i += 2)
info.locals[arguments[i]] = arguments[i+1];
}
+ return old;
+ };
+ runtime.include = function(relFilename, info) {
+ var old = runtime._beforeInclude.apply(this, arguments);
//Now load the template and render it
var sync = runtime.loadTemplate(info.base, info.rel + "/" + relFilename,
runtime.compileOptions, function(err, tmpl) {
@@ -358,19 +359,17 @@
//This is run after the template has been rendered
if(err) throw err;
//Now, restore template-specific information
- info.inc = pInc;
- info.base = pBase;
- info.rel = pRel;
- info.filename = pFilename;
- info.line = pLine;
- info.col = pCol;
- info.source = pSource;
- info.locals = pLocals;
+ runtime._afterInclude(old, info);
}, info);
});
if(!sync) throw new Error("Included file [" + info.rel + "/" + relFilename +
"] could not be loaded synchronously!");
};
+ runtime._afterInclude = function(old, info) {
+ includeFields.forEach(function(field) {
+ info[field] = old[field];
+ });
+ };
/* Defines a function, storing it in __.func */
runtime.func = function(funcName, func, info) {
View
@@ -22,6 +22,7 @@
blade.Runtime.include = function(relFilename, info) {
//Save old info
var oldIncludeInfo = blade._includeInfo,
+ old = blade.Runtime._beforeInclude.apply(this, arguments),
bufLength = info.length,
branchLabel = info.filename + ":" + info.line + ":inc:" + relFilename;
//expose `info` to the raw_func generated by `package.js`
@@ -50,6 +51,7 @@
}
//else... just use whatever is in `info` (non-reactive HTML)
blade._includeInfo = oldIncludeInfo;
+ blade.Runtime._afterInclude(old, info);
};
//Use Spark as the live update engine
View
@@ -15,7 +15,7 @@
"live binding",
"meteor"
],
- "version": "3.0.2",
+ "version": "3.0.3",
"homepage": "https://github.com/bminer/node-blade",
"repository": {
"type": "git",
View
@@ -3,7 +3,7 @@
"author": "Blake Miner <miner.blake@gmail.com> (http://www.blakeminer.com/)",
"description": "Blade - HTML Template Compiler, inspired by Jade & Haml",
"homepage": "https://github.com/bminer/node-blade",
- "version": "3.0.2",
+ "version": "3.0.3",
"git": "https://github.com/bminer/node-blade.git",
"packages": {
}

0 comments on commit 30e8c96

Please sign in to comment.