Socket
Socket
Sign inDemoInstall

blade

Package Overview
Dependencies
2
Maintainers
1
Versions
113
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.6.4 to 3.0.0-alpha1

smart.json

4

lib/blade.js

@@ -149,4 +149,4 @@ /** Blade Public API and Middleware

res.type('application/javascript');
res.send("blade.cachedViews[" + JSON.stringify(filename) + "]=" + tmpl.toString() +
";if(blade.cb[" + JSON.stringify(filename) + "])blade.cb[" +
res.send("blade._cachedViews[" + JSON.stringify(filename) + "]=" + tmpl.toString() +
";if(blade._cb[" + JSON.stringify(filename) + "])blade._cb[" +
JSON.stringify(filename) + "](" + JSON.stringify(tmpl.reldir) + "," +

@@ -153,0 +153,0 @@ JSON.stringify(tmpl.dependencies) + "," + tmpl.unknownDependencies + ");");

@@ -92,3 +92,3 @@ /** Blade Compiler

this._pushOff(ns + ' = ' + ns + ' || [];' + //Define ns as an array
ns + '.r = ' + ns + '.r || blade.runtime;' + //Define ns.r to point to the runtime
ns + '.r = ' + ns + '.r || blade.Runtime;' + //Define ns.r to point to the runtime
'if(!' + ns + '.func) ' + ns + '.func = {},' + //Define ns.func to hold all functions

@@ -228,3 +228,3 @@ ns + '.blocks = {},' + //Define ns.blocks to hold all blocks

this.lastNode.type != "code" || this.lastNode.children.length == 0 ||
node.type != "code") )
node.type != "code") && node.type != "foreach_else")
{

@@ -288,3 +288,3 @@ this._pushOff(ns + ".line=" + node.line + "," + ns + ".col=" + node.col + ";");

"escape": false,
"text": "return blade.runtime.trigger(this,arguments);"
"text": "return blade.Runtime.trigger(this,arguments);"
};

@@ -312,3 +312,3 @@ }

else
varAttrs += "," + i + ":{v:" + attrs[i].code +
varAttrs += "," + JSON.stringify(i) + ":{v:" + attrs[i].code +
(attrs[i].escape ? ", e:1" : "") + "}";

@@ -544,2 +544,5 @@ }

case 'chunk':
console.warn("Blade chunks are now deprecated. Please fix " +
(this.options.filename ? this.options.filename + ":" : "line ") +
node.line + ":" + node.col);
var paramStr = node.parameters == null ? "" : node.parameters.join(",");

@@ -550,4 +553,36 @@ this._pushOff(ns + ".r.chunk(" + JSON.stringify(node.name) + ",function(" +

this._compileNode(node.children[i]);
this._pushOff("return this;}, " + ns + ");");
this._pushOff("}," + ns + ");");
break;
case 'isolate':
this._pushOff(ns + ".r.isolate(function() {");
for(var i = 0; i < node.children.length; i++)
this._compileNode(node.children[i]);
this._pushOff("}," + ns + ");");
break;
case 'constant':
this._pushOff(ns + ".r.constant(function() {");
for(var i = 0; i < node.children.length; i++)
this._compileNode(node.children[i]);
this._pushOff("}," + ns + ");");
break;
case 'foreach':
this._pushOff(ns + ".r.foreach(" + ns + "," + node.cursor + ",function(" +
(node.itemAlias ? node.itemAlias : "") + ") {");
for(var i = 0; i < node.children.length; i++)
this._compileNode(node.children[i]);
this._pushOff("});");
break;
case 'foreach_else':
if(!this.lastNode || this.lastNode.type != "foreach")
{
var e = new Error("No matching foreach list block. You cannot put a foreach else block here!");
e.line = node.line, e.column = node.col;
throw e;
}
//Remove trailing ");" and add elseFunc argument to the Runtime.foreach(...) call.
this.buf = this.buf.substr(0, this.buf.length - 2) + ",function() {";
for(var i = 0; i < node.children.length; i++)
this._compileNode(node.children[i]);
this._pushOff("});");
break;
case 'blank_line':

@@ -554,0 +589,0 @@ //Ignore these lines

@@ -12,16 +12,54 @@ /** Blade Run-time helper functions

cachedViews = {},
eventHandlers = {};
eventHandlers = {},
/* Add blade.LiveUpdate no-op functions */
htmlNoOp = function(arg1, html) {return html;},
funcNoOp = function(arg1, func) {return func();},
liveUpdate = {
"attachEvents": htmlNoOp,
"setDataContext": htmlNoOp,
"isolate": function(func) {return func();},
"list": function(cursor, itemFunc, elseFunc) {
var itemList = cursor || [];
//cursor could have an observe method, in which case...
if(cursor && "observe" in cursor)
{
//Let's go ahead and observe it...
itemList = [];
cursor.observe({
"added": function(item) {
//added must be called once per element before the
//`observe` call completes
itemList.push(item);
}
}).stop(); //and then stop observing it.
}
if(!itemList.length) //If itemList.length is null, zero, etc.
return elseFunc();
//Otherwise, call itemFunc for each item in itemList array
var html = "";
for(var i = 0; i < itemList.length; i++)
html += itemFunc(itemList[i]);
return html;
},
"labelBranch": funcNoOp,
"createLandmark": funcNoOp
};
/* blade.Runtime.mount is the URL where the Blade middleware is mounted (or where
compiled templates can be downloaded)
*/
runtime.options = {
'mount': '/views/', 'loadTimeout': 15000
};
/* Expose Blade runtime via window.blade, if we are running on the browser
blade.runtime is the Blade runtime
blade.cachedViews is an Object of cached views, indexed by filename
blade.cb contains a callback function to be called when a view is
blade.Runtime is the Blade runtime
blade.runtime was kept for backward compatibility (but is now deprecated)
blade._cachedViews is an Object of cached views, indexed by filename
blade._cb contains a callback function to be called when a view is
loaded, indexed by filename. The callback function also has a 'cb'
property that contains an array of callbacks to be called once all
of the view's dependencies have been loaded.
blade.mount is the URL where the Blade middleware is mounted (or where
compiled templates can be downloaded)
*/
if(runtime.client = typeof window != "undefined")
window.blade = {'runtime': runtime, 'cachedViews': cachedViews,
'cb': {}, 'mount': '/views/', 'timeout': 15000};
window.blade = {'Runtime': runtime, 'LiveUpdate': liveUpdate,
'_cachedViews': cachedViews, '_cb': {}, 'runtime': runtime};

@@ -163,4 +201,4 @@ /* Convert special characters to HTML entities.

//If the file is already loading...
if(blade.cb[filename])
blade.cb[filename].cb.push(cb); //push to the array of callbacks
if(blade._cb[filename])
blade._cb[filename].cb.push(cb); //push to the array of callbacks
else

@@ -172,3 +210,3 @@ {

st.async = true;
st.src = blade.mount + filename;
st.src = runtime.options.mount + filename;
//Add compile options to the query string of the URL, if given

@@ -200,11 +238,11 @@ //(this functionality is disabled for now since the middleware ignores it anyway)

var timer = setTimeout(function() {
var cb = blade.cb[filename].cb; //array of callbacks
delete blade.cb[filename];
var cb = blade._cb[filename].cb; //array of callbacks
delete blade._cb[filename];
st.parentNode.removeChild(st);
callCallbacks(cb, new Error("Timeout Error: Blade Template [" + filename +
"] could not be loaded.") );
}, blade.timeout);
var tmp = blade.cb[filename] = function(dependenciesReldir, dependencies, unknownDependencies) {
}, runtime.options.loadTimeout);
var tmp = blade._cb[filename] = function(dependenciesReldir, dependencies, unknownDependencies) {
clearTimeout(timer);
delete blade.cb[filename];
delete blade._cb[filename];
st.parentNode.removeChild(st);

@@ -332,4 +370,18 @@ //Load all dependencies, too

for(var i in buf.blocks)
if(buf.blocks[i].pos >= start)
{
var x = buf.blocks[i];
if(x.pos >= start && (!buf.block || x.parent == buf.block) )
{
//Insert the buffer contents where it belongs
if(x.parent == null)
buf[x.pos] = x.buf.join("");
else
{
x.parent.buf[x.pos] = x.buf.join("");
x.parent.numChildren--;
}
//Delete the block
delete buf.blocks[i];
}
}
/* Now remove the content generated by the function from the buffer

@@ -344,2 +396,7 @@ and return it as a string */

//This function needs to accept params and return HTML
/* Note: This following line is the same as:
var len = info.length;
func.apply(this, arguments);
return runtime.capture(info, len);
*/
return runtime.capture(info, info.length, func.apply(this, arguments) );

@@ -349,2 +406,35 @@ };

/* Define an isolate block */
runtime.isolate = function(func, buf) {
buf.push(liveUpdate.isolate(function() {
/* Note: This following line is the same as:
var len = buf.length;
func();
return runtime.capture(buf, len);
*/
return runtime.capture(buf, buf.length, func() );
}) );
};
/* Define a constant block */
runtime.constant = function(func, buf) {
buf.push(liveUpdate.createLandmark({"constant": true}, function(landmark) {
/* Note: This following line is the same as:
var len = buf.length;
func();
return runtime.capture(buf, len);
*/
return runtime.capture(buf, buf.length, func() );
}) );
};
/* Foreach/else block */
runtime.foreach = function(buf, cursor, listFunc, elseFunc) {
buf.push(liveUpdate.list(cursor, function(item) {
return runtime.capture(buf, buf.length, listFunc.call(item, item) );
}, function() {
return runtime.capture(buf, buf.length, elseFunc() );
}) );
};
/* Copies error reporting information from a block's buffer to the main

@@ -351,0 +441,0 @@ buffer */

@@ -0,19 +1,20 @@

MIT License - node-blade (https://github.com/bminer/node-blade/)
Copyright (c) 2011-2012 Blake Miner (http://www.blakeminer.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

@@ -1,8 +0,14 @@

blade.runtime.loadTemplate = function(baseDir, filename, compileOptions, cb) {
blade.Runtime.loadTemplate = function(baseDir, filename, compileOptions, cb) {
//Append .blade for filenames without an extension
if(filename.split("/").pop().indexOf(".") < 0)
filename += ".blade";
//Either pull from the cache or return an error
filename = blade.runtime.resolve(filename);
filename = blade.Runtime.resolve(filename);
if(blade.cachedViews[filename])
return cb(null, blade.cachedViews[filename]);
else
return cb(new Error("Template '" + filename + "' could not be loaded.") );
{
cb(null, blade.cachedViews[filename]);
return true;
}
cb(new Error("Template '" + filename + "' could not be loaded.") );
return false;
};
{
"author": "Blake Miner <miner.blake@gmail.com> (http://www.blakeminer.com/)",
"name": "blade",
"description": "Blade - HTML Template Compiler, inspired by Jade & Haml",
"keywords": [
"html",
"compile",
"compiler",
"render",
"view",
"template",
"engine",
"jade",
"haml",
"live binding",
"meteor"
],
"version": "2.6.4",
"homepage": "https://github.com/bminer/node-blade",
"repository": {
"name": "blade",
"author": "Blake Miner <miner.blake@gmail.com> (http://www.blakeminer.com/)",
"description": "Blade - HTML Template Compiler, inspired by Jade & Haml",
"keywords": [
"html",
"compile",
"compiler",
"render",
"view",
"template",
"engine",
"jade",
"haml",
"live binding",
"meteor"
],
"version": "3.0.0-alpha1",
"homepage": "https://github.com/bminer/node-blade",
"repository": {
"type": "git",
"url": "https://github.com/bminer/node-blade.git"
},
"main": "lib/blade.js",
"bin": { "blade": "./bin/blade" },
"dependencies": {
"commander": ">=0.6"
},
"devDependencies": {
"pegjs": ">=0.7",
"uglify-js": ">=1.2"
},
"optionalDependencies": {
"uglify-js": ">=1.2"
},
"engines": {
"node": ">=0.6"
},
"scripts": {
"pretest": "./lib/parser/build.sh",
"test": "node ./test/test.js",
"prepublish": "./lib/parser/build.sh",
"url": "https://github.com/bminer/node-blade.git"
},
"license": "MIT",
"main": "lib/blade.js",
"bin": { "blade": "./bin/blade" },
"dependencies": {
"commander": ">=0.6"
},
"devDependencies": {
"pegjs": ">=0.7",
"uglify-js": ">=1.2"
},
"optionalDependencies": {
"uglify-js": ">=1.2"
},
"engines": {
"node": ">=0.6"
},
"scripts": {
"pretest": "./lib/parser/build.sh",
"test": "node ./test/test.js",
"prepublish": "./lib/parser/build.sh",
"postinstall": "node ./postinstall.js"
},
"contributors": [
},
"contributors": [
"Michel Löhr (https://github.com/mlohr)"
]
}
]
}

@@ -12,3 +12,3 @@ /** Blade Live UI plugin

- Context
Adds the following to `blade.runtime`:
Adds the following to `blade.Runtime`:
- render(viewName, locals, cb)

@@ -266,5 +266,5 @@ - renderTo(element, viewName, locals [, cb])

*/
blade.runtime.render = function(viewName, locals, cb) {
blade.Runtime.render = function(viewName, locals, cb) {
//Load and render the template
blade.runtime.loadTemplate(viewName, function(err, tmpl) {
blade.Runtime.loadTemplate(viewName, function(err, tmpl) {
if(err) return cb(err);

@@ -289,4 +289,4 @@ (function renderTemplate() {

*/
blade.runtime.renderTo = function(el, viewName, locals, cb) {
blade.runtime.render(viewName, locals, function(err, html, info) {
blade.Runtime.renderTo = function(el, viewName, locals, cb) {
blade.Runtime.render(viewName, locals, function(err, html, info) {
if(err) {if(cb) cb.call(el, err); return;}

@@ -394,5 +394,5 @@ try

jQuery.fn.render = function(viewName, locals, cb) {
blade.runtime.renderTo(this, viewName, locals, cb);
blade.Runtime.renderTo(this, viewName, locals, cb);
};
})();

@@ -440,2 +440,43 @@ Blade - HTML Template Compiler

### Foreach block
The exact syntax of a foreach block is the word "foreach", followed by the variable
name of the JavaScript Array or [Cursor Object](http://docs.meteor.com/#observe),
optionally followed by "as" and an item alias. Finally, it is possible to follow the
foreach block by an "else" block, which is only rendered if there were no items in the
collection.
As a side note, a Cursor Object, as described above, is an Object with an `observe()`
method, as described by [`cursor.observe(callbacks)`](http://docs.meteor.com/#observe)
For example:
```
ul
foreach users as user
li #{user.firstName} #{user.lastName} (#{user.age})
else
li No users were found
```
Assuming that `users` is an Array, the above would produce the same as:
```
ul
- for(var i = 0; i < users.length; i++)
- var user = users[i];
li #{user.firstName} #{user.lastName} (#{user.age})
- if(users.length == 0)
li No users were found
```
The foreach block is preferred over the example above not only because of readability
and brevity, but because it also provides Blade with the ability to better integrate
with live page updating engines (like [Meteor](http://www.meteor.com/),
[Spark](https://github.com/meteor/meteor/wiki/Spark),
[Live UI](https://github.com/bminer/node-blade/wiki/Live-UI-Blade-Plugin), etc.).
That is, if the live page update engine supports tracking reactive collections, the most
efficient DOM operations may occur to update the view's results in-place, without
re-rendering the entire Blade template.
### Doctypes

@@ -663,3 +704,3 @@

You may also place an `include` inside of a `function`, `block`, or `chunk`.
You may also place an `include` inside of a `function` or `block`.

@@ -871,2 +912,4 @@ Finally, you can specify which local variables should be passed to the included view

#### Chunks are deprecated as of Blade 3.0
Chunks are simply functions that return HTML. They behave a bit differently than

@@ -881,3 +924,3 @@ conventional Blade functions.

One reason you might define a chunk is to pass it to
~~One reason you might define a chunk is to pass it to
[Meteor's](http://meteor.com/)

@@ -887,3 +930,4 @@ [`Meteor.ui.chunk` function](http://docs.meteor.com/#meteor_ui_chunk); however,

You can also use chunks to work with [`Meteor.ui.listChunk`]
(http://docs.meteor.com/#meteor_ui_listchunk).
(http://docs.meteor.com/#meteor_ui_listchunk).~~
As of Meteor 0.4.0, the Meteor functions above no longer exist.

@@ -1086,5 +1130,5 @@ Example:

to the client. Simply include the /blade/blade.js file in your `<script>`
tags, and then call `blade.runtime.loadTemplate`.
tags, and then call `blade.Runtime.loadTemplate`.
### blade.runtime.loadTemplate(filename, cb)
### blade.Runtime.loadTemplate(filename, cb)

@@ -1105,3 +1149,3 @@ - `filename` - the filename of the view you wish to retrieve, relative to the

```javascript
blade.runtime.loadTemplate("homepage.blade", function(err, tmpl) {
blade.Runtime.loadTemplate("homepage.blade", function(err, tmpl) {
tmpl({'users': ['John', 'Joe']}, function(err, html) {

@@ -1113,3 +1157,11 @@ console.log(html); //YAY! We have rendered HTML

As a side note, you can override the `blade.runtime.loadTemplate` function with
Additionally, you can set `blade.Runtime.options` to control how the templates are
loaded:
- `blade.Runtime.options.mount` - the URL path where you can request compiled views
(defaults to "/views/")
- `blade.Runtime.options.loadTimeout` - the maximum number of milliseconds to wait
before `loadTemplate` throws an error (defaults to 15 seconds).
As a side note, you can override the `blade.Runtime.loadTemplate` function with
your own implementation.

@@ -1140,3 +1192,3 @@

```javascript
function tmpl(locals,cb,__){var __=__||[];__.r=__.r||blade.runtime,__.blocks=__.blocks||{},__.func=__.func||{},__.locals=locals||{};with(__.locals){__.push("<!DOCTYPE html>","<html",">","<head",">","<title",">",__.r.escape("Blade"),"</title>","</head>","<body",">","<div",' id="nav"',">","<ul",">");for(var i in nav)__.push("<li",">","<a"),__.r.attrs({href:{val:nav[i],escape:!0}},__,this),__.push(">",__.r.escape(i),"</a>","</li>");__.push("</ul>","</div>","<div",' id="content"',' class="center"',">","<h1",">",__.r.escape("Blade is cool"),"</h1>","</div>","</body>","</html>"),__.inc||__.r.done(__)}cb(null,__.join(""),__)}
function tmpl(locals,cb,__){__=__||[],__.r=__.r||blade.Runtime,__.func||(__.func={},__.blocks={},__.chunk={}),__.locals=locals||{};with(__.locals){__.push("<!DOCTYPE html>","<html",">","<head",">","<title",">","Blade","</title>","</head>","<body",">","<div",' id="nav"',">","<ul",">");for(var i in nav)__.push("<li",">","<a"),__.r.attrs({href:{v:nav[i],e:1}},__),__.push(">",__.r.escape(i),"</a>","</li>");__.push("</ul>","</div>","<div",' id="content"',' class="center"',">","<h1",">","Blade is cool","</h1>","</div>","</body>","</html>")}__.inc||__.r.done(__),cb(null,__.join(""),__)}
```

@@ -1187,3 +1239,7 @@

Blade provides a Live UI plugin that allows Blade to support live binding. Live binding
#### As of Blade 3.0, the Live UI plugin has been moved to another repository.
#### More information about the Live UI plugin is coming soon...
~~Blade provides a Live UI plugin that allows Blade to support live binding. Live binding
provides automatic two-way synchronization between your models and views on a given web

@@ -1200,3 +1256,3 @@ page. That is, when data in your Model is updated, the rendered Blade views on the

Eventually, the Live UI plugin might live in a separate repository and work for any
templating language.
templating language. More information coming soon...

@@ -1206,3 +1262,3 @@ **definePropertyIE8**

This plugin is a prerequisite for the Live UI plugin if you plan on using Live UI in
Internet Explorer 8.
Internet Explorer 8.~~

@@ -1224,2 +1280,4 @@ Meteor Support

#### An Atmosphere smart package will be available soon!
**More documentation and examples for Meteor + Blade can be found [on this wiki page]

@@ -1276,3 +1334,3 @@ (https://github.com/bminer/node-blade/wiki/Using-Blade-with-Meteor).**

directly before the bound element. Then, the appropriate event attribute (i.e.
onclick, onchange, etc.) on the element is set to call `blade.runtime.trigger`. The
onclick, onchange, etc.) on the element is set to call `blade.Runtime.trigger`. The
`trigger` function basically grabs the HTML comment, passes the contents through eval(),

@@ -1285,3 +1343,3 @@ and binds the event handler directly to the element. This means that the event handlers

by assigning each element an 'id' attribute, if necessary. When the view has
finished rendering, the Blade runtime will pass a bunch of information (chunks, blocks,
finished rendering, the Blade runtime will pass a bunch of information (blocks,
functions, or event handlers that were defined, etc.) to the 3rd (undocumented) argument

@@ -1288,0 +1346,0 @@ of the render callback function. If you are rendering Blade templates on the browser,

@@ -35,3 +35,3 @@ var blade = require('../lib/blade'),

});
compare.on('exit', function(code) {
compare.on('close', function(code) {
if(diff != "")

@@ -38,0 +38,0 @@ {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc