Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mustache

Package Overview
Dependencies
Maintainers
2
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mustache - npm Package Compare versions

Comparing version 0.7.0 to 0.7.1

test/_files/check_falsy.js

80

mustache.js

@@ -23,3 +23,3 @@ /*!

exports.name = "mustache.js";
exports.version = "0.7.0";
exports.version = "0.7.1";
exports.tags = ["{{", "}}"];

@@ -197,35 +197,39 @@

Writer.prototype.compile = function (template, tags) {
return this._compile(this._cache, template, template, tags);
var fn = this._cache[template];
if (!fn) {
var tokens = exports.parse(template, tags);
fn = this._cache[template] = this.compileTokens(tokens, template);
}
return fn;
};
Writer.prototype.compilePartial = function (name, template, tags) {
return this._compile(this._partialCache, name, template, tags);
var fn = this.compile(template, tags);
this._partialCache[name] = fn;
return fn;
};
Writer.prototype.render = function (template, view, partials) {
return this.compile(template)(view, partials);
};
Writer.prototype.compileTokens = function (tokens, template) {
var fn = compileTokens(tokens);
var self = this;
Writer.prototype._compile = function (cache, key, template, tags) {
if (!cache[key]) {
var tokens = exports.parse(template, tags);
var fn = compileTokens(tokens);
var self = this;
cache[key] = function (view, partials) {
if (partials) {
if (typeof partials === "function") {
self._loadPartial = partials;
} else {
for (var name in partials) {
self.compilePartial(name, partials[name]);
}
return function (view, partials) {
if (partials) {
if (typeof partials === "function") {
self._loadPartial = partials;
} else {
for (var name in partials) {
self.compilePartial(name, partials[name]);
}
}
}
return fn(self, Context.make(view), template);
};
}
return fn(self, Context.make(view), template);
};
};
return cache[key];
Writer.prototype.render = function (template, view, partials) {
return this.compile(template)(view, partials);
};

@@ -255,3 +259,4 @@

return value.call(context.view, text, scopedRender) || "";
var result = value.call(context.view, text, scopedRender);
return result != null ? result : "";
default:

@@ -322,3 +327,3 @@ if (value) {

* Low-level function that compiles the given `tokens` into a function
* that accepts two arguments: a Context and a Writer.
* that accepts three arguments: a Writer, a Context, and the template.
*/

@@ -339,3 +344,3 @@ function compileTokens(tokens) {

function renderFunction(writer, context, template) {
return function (writer, context, template) {
var buffer = "";

@@ -371,5 +376,3 @@ var token, sectionText;

return buffer;
}
return renderFunction;
};
}

@@ -436,3 +439,3 @@

function squashTokens(tokens) {
var token, lastToken;
var token, lastToken, squashedTokens = [];

@@ -445,7 +448,9 @@ for (var i = 0; i < tokens.length; ++i) {

lastToken[3] = token[3];
tokens.splice(i--, 1); // Remove this token from the array.
} else {
lastToken = token;
squashedTokens.push(token);
}
}
return squashedTokens;
}

@@ -471,2 +476,3 @@

exports.parse = function (template, tags) {
template = template || '';
tags = tags || exports.tags;

@@ -568,3 +574,3 @@

squashTokens(tokens);
tokens = squashTokens(tokens);

@@ -602,2 +608,10 @@ return nestTokens(tokens);

/**
* Compiles the given array of tokens (the output of a parse) to a reusable
* function using the default writer.
*/
exports.compileTokens = function (tokens, template) {
return _writer.compileTokens(tokens, template);
};
/**
* Renders the `template` with the given `view` and `partials` using the

@@ -604,0 +618,0 @@ * default writer.

{
"name": "mustache",
"version": "0.7.0",
"version": "0.7.1",
"description": "Logic-less {{mustache}} templates with JavaScript",

@@ -12,3 +12,3 @@ "author": "mustache.js Authors <http://github.com/janl/mustache.js>",

"volo": {
"url": "https://raw.github.com/janl/mustache.js/0.7.0/mustache.js"
"url": "https://raw.github.com/janl/mustache.js/0.7.1/mustache.js"
},

@@ -15,0 +15,0 @@ "scripts": {

@@ -105,3 +105,3 @@ # mustache.js - Logic-less {{mustache}} templates with JavaScript

If the `person` key exists and has a value of `null`, `undefined`, or `false`, or is an empty list, the block will not be rendered.
If the `person` key does not exist, or exists and has a value of `null`, `undefined`, or `false`, or is an empty list, the block will not be rendered.

@@ -108,0 +108,0 @@ View:

@@ -8,2 +8,3 @@ var assert = require('assert');

var expectations = {
'' : [],
'{{hi}}' : [ [ 'name', 'hi', 0, 6 ] ],

@@ -10,0 +11,0 @@ '{{hi.world}}' : [ [ 'name', 'hi.world', 0, 12 ] ],

var assert = require("assert");
var vows = require("vows");
var Writer = require("./../mustache").Writer;
var Mustache = require("./../mustache");
var Writer = Mustache.Writer;

@@ -19,4 +20,26 @@ vows.describe("Mustache.Writer").addBatch({

assert.equal(result, partial);
},
"caches partials by content, not by name": function (writer) {
var result = writer.render("{{>partial}}", {}, {
partial: "partial one"
});
assert.equal(result, "partial one");
result = writer.render("{{>partial}}", {}, {
partial: "partial two"
});
assert.equal(result, "partial two");
},
"can compile an array of tokens": function (writer) {
var template = "Hello {{name}}!";
var tokens = Mustache.parse(template);
var render = writer.compileTokens(tokens, template);
var result = render({ name: 'Michael' });
assert.equal(result, 'Hello Michael!');
}
}
}).export(module);

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc