Skip to content

Commit

Permalink
Push to 3.0.0alpha13
Browse files Browse the repository at this point in the history
Worked on a bunch of Meteor stuff:
	- Fixed some behavior when mixing blocks and element preservation
	- Added branch label for foreach blocks (fixes #102)
	- Fixed a bug in the Meteor smart package file
  • Loading branch information
bminer committed Jan 4, 2013
1 parent d63bc84 commit c1afd67
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
30 changes: 27 additions & 3 deletions lib/runtime.js
Expand Up @@ -341,7 +341,9 @@
pLine = info.line,
pCol = info.col,
pSource = info.source,
pLocals = info.locals;
pLocals = info.locals,
pUnsafeBlockAction = info.unsafeBlockAction,
pPreserve = info.preserve;
info.inc = true;
//If exposing locals, the included view gets its own set of locals
if(arguments.length > 2)
Expand All @@ -366,6 +368,8 @@
info.col = pCol;
info.source = pSource;
info.locals = pLocals;
info.unsafeBlockAction = pUnsafeBlockAction;
info.preserve = pPreserve;
}, info);
});
if(!sync) throw new Error("Included file [" + info.rel + "/" + relFilename +
Expand Down Expand Up @@ -454,6 +458,9 @@

/* Define a constant block */
runtime.constant = function(label, func, buf) {
if(buf.unsafeBlockAction)
throw new Error("You cannot preserve elements here because this template either defines a block or performs a block modification.");
buf.preserve = true;
buf.push(liveUpdate.labelBranch(buf.filename + ":" + label, function () {
return liveUpdate.createLandmark({"constant": true}, function(landmark) {
/* Note: This following line is the same as:
Expand All @@ -468,6 +475,9 @@

/* Define a preserve block */
runtime.preserve = function(label, preserved, func, buf) {
if(buf.unsafeBlockAction)
throw new Error("You cannot preserve elements here because this template either defines a block or performs a block modification.");
buf.preserve = true;
buf.push(liveUpdate.labelBranch(buf.filename + ":" + label, function () {
return liveUpdate.createLandmark({"preserve": preserved}, function(landmark) {
/* Note: This following line is the same as:
Expand All @@ -484,10 +494,15 @@
runtime.foreach = function(buf, cursor, itemFunc, elseFunc) {
//Define wrapper functions for itemFunc and elseFunc
function itemFuncWrapper(item) {
return runtime.capture(buf, buf.length, itemFunc.call(item, item) );
var label = (item._id || (typeof item === 'string' ? item : null) || liveUpdate.UNIQUE_LABEL);
return liveUpdate.labelBranch(label, function() {
return runtime.capture(buf, buf.length, itemFunc.call(item, item) );
});
}
function elseFuncWrapper() {
return elseFunc ? runtime.capture(buf, buf.length, elseFunc() ) : "";
return liveUpdate.labelBranch("else", function() {
return elseFunc ? runtime.capture(buf, buf.length, elseFunc() ) : "";
});
}
//Call liveUpdate.list for Cursor Objects
if(cursor && "observe" in cursor)
Expand Down Expand Up @@ -519,6 +534,9 @@

/* Defines a block */
runtime.blockDef = function(blockName, buf, childFunc) {
if(buf.preserve)
throw new Error("You cannot define a block in this template because element preservation is being used.");
buf.unsafeBlockAction = true;
var block = buf.blocks[blockName] = {
'parent': buf.block || null, //set parent block
'buf': [], //block get its own buffer
Expand Down Expand Up @@ -554,12 +572,15 @@
"r" ==> replace
*/
runtime.blockRender = function(type, blockName, buf) {
if(buf.preserve)
throw new Error("You cannot render a block in this template because element preservation is being used.");
var block = buf.blocks[blockName];
if(block == null)
throw new Error("Block '" + blockName + "' is undefined.");
if(block.paramBlock == null)
throw new Error("Block '" + blockName +
"' is a regular, non-parameterized block, which cannot be rendered.");
buf.unsafeBlockAction = true;
//Extract arguments
var args = [block.buf];
for(var i = 3; i < arguments.length; i++)
Expand Down Expand Up @@ -592,9 +613,12 @@
"r" ==> replace
*/
runtime.blockMod = function(type, blockName, buf, childFunc) {
if(buf.preserve)
throw new Error("You cannot modify a block in this template because element preservation is being used.");
var block = buf.blocks[blockName];
if(block == null)
throw new Error("Block '" + blockName + "' is undefined.");
buf.unsafeBlockAction = true;
if(type == "r") //replace
{
//Empty buffer and delete parameterized block function
Expand Down
2 changes: 1 addition & 1 deletion meteor/package.js
Expand Up @@ -73,7 +73,7 @@ Package.register_extension("blade", function(bundle, srcPath, servePath, where)
"](data, function(err,html,info) {" +
"if(err) throw err;" +
//Remove event handler attributes
'html = html.replace(/on[a-z]+\=\"return blade\.Runtime\.trigger\(this\,arguments\)\;\"/g, "");' +
'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" +
Expand Down
4 changes: 1 addition & 3 deletions meteor/runtime-meteor.js
Expand Up @@ -33,7 +33,5 @@
};

//Use Spark as the live update engine
if(Spark)
for(var i in Spark)
blade.LiveUpdate[i] = Spark[i];
blade.LiveUpdate = Spark;
})();
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -15,7 +15,7 @@
"live binding",
"meteor"
],
"version": "3.0.0alpha12",
"version": "3.0.0alpha13",
"homepage": "https://github.com/bminer/node-blade",
"repository": {
"type": "git",
Expand Down
3 changes: 1 addition & 2 deletions plugins/liveui.js
Expand Up @@ -96,8 +96,7 @@
//--- End

//Copy stuff from Spark to blade.LiveUpdate
for(var i in Spark)
blade.LiveUpdate[i] = Spark[i];
blade.LiveUpdate = Spark;
}

function Model(data) {
Expand Down
2 changes: 1 addition & 1 deletion smart.json
Expand Up @@ -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.0alpha12",
"version": "3.0.0alpha13",
"git": "https://github.com/bminer/node-blade.git",
"packages": {
}
Expand Down

0 comments on commit c1afd67

Please sign in to comment.