Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Push to 3.0.0alpha13

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...
commit c1afd67366e196f02ecd1177c3322fa923fa8968 1 parent d63bc84
@bminer authored
View
30 lib/runtime.js
@@ -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)
@@ -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 +
@@ -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:
@@ -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:
@@ -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)
@@ -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
@@ -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++)
@@ -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
View
2  meteor/package.js
@@ -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" +
View
4 meteor/runtime-meteor.js
@@ -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;
})();
View
2  package.json
@@ -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",
View
3  plugins/liveui.js
@@ -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) {
View
2  smart.json
@@ -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": {
}
Please sign in to comment.
Something went wrong with that request. Please try again.