Permalink
Browse files

Blade 3.0.0rc2 - Major bugfixes for Meteor support

`runtime.include` no longer handles liveUpdate stuff; this is now handled by
`runtime-meteor.js`

`runtime-meteor.js` exposes `info` Object when performing file includes via
`blade._includeInfo`. The Blade smart package now generates Template functions
that read `blade._includeInfo` and pass it into the template.  Then, as normal,
the Template function will return reactive HTML and modify `info` as an
intended side-effect. `runtime-meteor.js` has been modified to determine
whether or not the included template contains any block declarations, and if
not, reactive HTML is injected into the template's HTML buffer. If block
definitions were used, then the template's HTML buffer is left untouched, as it
already contained non-reactive HTML. Fixes #139.
  • Loading branch information...
bminer committed Mar 7, 2013
1 parent a050d0d commit 32ba1eee66fedebd1ff0224e298ad2cae694c8b5
Showing with 30 additions and 18 deletions.
  1. +0 −8 lib/runtime.js
  2. +6 −1 meteor/package.js
  3. +22 −7 meteor/runtime-meteor.js
  4. +1 −1 package.json
  5. +1 −1 smart.json
View
@@ -354,7 +354,6 @@
var sync = runtime.loadTemplate(info.base, info.rel + "/" + relFilename,
runtime.compileOptions, function(err, tmpl) {
if(err) throw err;
- var len = info.length;
tmpl(info.locals, function(err, html) {
//This is run after the template has been rendered
if(err) throw err;
@@ -367,13 +366,6 @@
info.col = pCol;
info.source = pSource;
info.locals = pLocals;
- //If the file did not declare any blocks, capture output as HTML and add a branch label
- if(!info.bd)
- {
- html = runtime.capture(info, len);
- info.push(liveUpdate.labelBranch(info.filename + ":" + info.line + ":inc:" + relFilename,
- function() {return html;}) );
- }
}, info);
});
if(!sync) throw new Error("Included file [" + info.rel + "/" + relFilename +
View
@@ -80,18 +80,23 @@ Package.register_extension("blade", function(bundle, srcPath, servePath, where)
"get:obj.helpers[i],configurable:true,enumerable:true" +
"});" +
"}" +
+ //Get `info` Object from the parent template (if any) and its length
+ "var info = blade._includeInfo || [], startLen = info.length;" +
+ //Expose `partials`
+ "info.partials = obj.partials;" +
/*call the actual Blade template here, passing in data
`ret` is used to capture async results.
Note that since we are using caching for file includes,
there is no async. All code is ran synchronously. */
"var ret = ''; blade._cachedViews[" + JSON.stringify(templateName + ".blade") +
"](data, function(err,html,info) {" +
"if(err) throw err;" +
+ "html = info.slice(startLen).join('');" +
//Remove event handler attributes
'html = html.replace(/on[a-z]+\\=\\"return blade\\.Runtime\\.trigger\\(this\\,arguments\\)\\;\\"/g, "");' +
//now bind any inline events and return
"ret = blade.LiveUpdate.attachEvents(info.eventHandlers, html);" +
- "});\n" +
+ "},info);\n" +
//so... by here, we can just return `ret`, and everything works okay
"return ret;" +
"}" +
View
@@ -20,19 +20,34 @@
};
var oldInclude = blade.Runtime.include;
blade.Runtime.include = function(relFilename, info) {
+ //Save old info
+ var oldIncludeInfo = blade._includeInfo,
+ bufLength = info.length,
+ branchLabel = info.filename + ":" + info.line + ":inc:" + relFilename;
+ //expose `info` to the raw_func generated by `package.js`
+ blade._includeInfo = info;
+ //Get the name of the included Template
var name = resolveFilename(info.rel + "/" + relFilename);
//Remove .blade file extension
if(name.substr(-6) == ".blade")
name = name.substr(0, name.length - 6);
- //Add helpers to info.locals
- var tmpl = Template[name] || {};
- var tmplData = tmpl._tmpl_data || {};
- _.extend(info.locals, Meteor._partials[name], tmplData.helpers || {});
- //Now call original "include" function
- return oldInclude.apply(this, arguments);
+ //Render the child template to get the reactive HTML (and to populate `info`)
+ var reactiveHTML = Spark.labelBranch(branchLabel, function() {
+ return info.partials[name](info.locals);
+ });
+ //If no block definitions were found in the parent and child templates, we can use the reactive HTML
+ if(!info.bd)
+ {
+ //Remove non-reactive HTML
+ blade.Runtime.capture(info, bufLength);
+ //Add reactive HTML
+ info.push(reactiveHTML);
+ }
+ //else... just use whatever is in `info` (non-reactive HTML)
+ blade._includeInfo = oldIncludeInfo;
};
//Use Spark as the live update engine
for(var i in Spark)
blade.LiveUpdate[i] = Spark[i];
-})();
+})();
View
@@ -15,7 +15,7 @@
"live binding",
"meteor"
],
- "version": "3.0.0beta8",
+ "version": "3.0.0rc2",
"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.0beta8",
+ "version": "3.0.0rc2",
"git": "https://github.com/bminer/node-blade.git",
"packages": {
}

0 comments on commit 32ba1ee

Please sign in to comment.