Untitled diff

Créé Le diff n'expire jamais
5 suppressions
578 lignes
113 ajouts
670 lignes
// mostache, mo'mustache (mustache 8.1 fork )
/*!
/*!
* mustache.js - Logic-less {{mustache}} templates with JavaScript
* mustache.js - Logic-less {{mustache}} templates with JavaScript
* http://github.com/janl/mustache.js
* http://github.com/janl/mustache.js
*/
*/
/* modified by dandavis to become Mo'stache v0.8.2a
mustache improvements
inspired by dust:
The {SEP} some marker like <hr>, ", ", etc{/SEP} mini-section prints the enclosed block for every value except for the last.
The {INDEX} mini-tag passes the numerical index of the current element to the enclosed block.
my idea, somewhat like angular but not custom code:
{{phone.connectivity.radio | escape }} - any function that outputs stringy things, including eval
EX: {{name|escape|btoa}} // uses global functions
EX: {{|Math.random}} // uses global function
EX: {{name|.bold}} // uses self method (w/o arguments), indidcated by dot prefix
EX: {{name.bold}} // (native method mustache behaviour over-ride)
EX: {{numbers|JSON.stringify}} //uses global path
EX: {{123 * 456 |eval}} // uses expression and eval() for opt-in overloading/active processing
*/
/*global define: false*/
/*global define: false*/
(function (global, factory) {
(function (global, factory) {
if (typeof exports === "object" && exports) {
if (typeof exports === "object" && exports) {
factory(exports); // CommonJS
factory(exports); // CommonJS
} else if (typeof define === "function" && define.amd) {
} else if (typeof define === "function" && define.amd) {
define(['exports'], factory); // AMD
define(['exports'], factory); // AMD
} else {
} else {
factory(global.Mustache = {}); // <script>
factory(global.Mustache = {}); // <script>
}
}
}(this, function (mustache) {
factory.global=global;
}(this, function mostache(mustache) {
function resolve(start, path) {
return path.split(/[\.,]/).reduce(function(obj, prop) {
return obj && obj[prop];
}, start);
}
var Object_toString = Object.prototype.toString;
var Object_toString = Object.prototype.toString;
var isArray = Array.isArray || function (object) {
var isArray = Array.isArray || function (object) {
return Object_toString.call(object) === '[object Array]';
return Object_toString.call(object) === '[object Array]';
};
};
function isFunction(object) {
function isFunction(object) {
return typeof object === 'function';
return typeof object === 'function';
}
}
function escapeRegExp(string) {
function escapeRegExp(string) {
return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
}
}
// Workaround for https://issues.apache.org/jira/browse/COUCHDB-577
// Workaround for https://issues.apache.org/jira/browse/COUCHDB-577
// See https://github.com/janl/mustache.js/issues/189
// See https://github.com/janl/mustache.js/issues/189
var RegExp_test = RegExp.prototype.test;
var RegExp_test = RegExp.prototype.test;
function testRegExp(re, string) {
function testRegExp(re, string) {
return RegExp_test.call(re, string);
return RegExp_test.call(re, string);
}
}
var nonSpaceRe = /\S/;
var nonSpaceRe = /\S/;
function isWhitespace(string) {
function isWhitespace(string) {
return !testRegExp(nonSpaceRe, string);
return !testRegExp(nonSpaceRe, string);
}
}
var entityMap = {
var entityMap = {
"&": "&amp;",
"&": "&amp;",
"<": "&lt;",
"<": "&lt;",
">": "&gt;",
">": "&gt;",
'"': '&quot;',
'"': '&quot;',
"'": '&#39;',
"'": '&#39;',
"/": '&#x2F;'
"/": '&#x2F;'
};
};
function escapeHtml(string) {
function escapeHtml(string) {
return String(string).replace(/[&<>"'\/]/g, function (s) {
return String(string).replace(/[&<>"'\/]/g, function (s) {
return entityMap[s];
return entityMap[s];
});
});
}
}
var whiteRe = /\s*/;
var whiteRe = /\s*/;
var spaceRe = /\s+/;
var spaceRe = /\s+/;
var equalsRe = /\s*=/;
var equalsRe = /\s*=/;
var curlyRe = /\s*\}/;
var curlyRe = /\s*\}/;
var tagRe = /#|\^|\/|>|\{|&|=|!/;
var tagRe = /#|\^|\/|>|\{|&|=|!/;
/**
/**
* Breaks up the given `template` string into a tree of tokens. If the `tags`
* Breaks up the given `template` string into a tree of tokens. If the `tags`
* argument is given here it must be an array with two string values: the
* argument is given here it must be an array with two string values: the
* opening and closing tags used in the template (e.g. [ "<%", "%>" ]). Of
* opening and closing tags used in the template (e.g. [ "<%", "%>" ]). Of
* course, the default is to use mustaches (i.e. mustache.tags).
* course, the default is to use mustaches (i.e. mustache.tags).
*
*
* A token is an array with at least 4 elements. The first element is the
* A token is an array with at least 4 elements. The first element is the
* mustache symbol that was used inside the tag, e.g. "#" or "&". If the tag
* mustache symbol that was used inside the tag, e.g. "#" or "&". If the tag
* did not contain a symbol (i.e. {{myValue}}) this element is "name". For
* did not contain a symbol (i.e. {{myValue}}) this element is "name". For
* all text that appears outside a symbol this element is "text".
* all text that appears outside a symbol this element is "text".
*
*
* The second element of a token is its "value". For mustache tags this is
* The second element of a token is its "value". For mustache tags this is
* whatever else was inside the tag besides the opening symbol. For text tokens
* whatever else was inside the tag besides the opening symbol. For text tokens
* this is the text itself.
* this is the text itself.
*
*
* The third and fourth elements of the token are the start and end indices,
* The third and fourth elements of the token are the start and end indices,
* respectively, of the token in the original template.
* respectively, of the token in the original template.
*
*
* Tokens that are the root node of a subtree contain two more elements: 1) an
* Tokens that are the root node of a subtree contain two more elements: 1) an
* array of tokens in the subtree and 2) the index in the original template at
* array of tokens in the subtree and 2) the index in the original template at
* which the closing tag for that section begins.
* which the closing tag for that section begins.
*/
*/
function parseTemplate(template, tags) {
function parseTemplate(template, tags) {
if (!template)
if (!template)
return [];
return [];
var sections = []; // Stack to hold section tokens
var sections = []; // Stack to hold section tokens
var tokens = []; // Buffer to hold the tokens
var tokens = []; // Buffer to hold the tokens
var spaces = []; // Indices of whitespace tokens on the current line
var spaces = []; // Indices of whitespace tokens on the current line
var hasTag = false; // Is there a {{tag}} on the current line?
var hasTag = false; // Is there a {{tag}} on the current line?
var nonSpace = false; // Is there a non-space char on the current line?
var nonSpace = false; // Is there a non-space char on the current line?
// Strips all whitespace tokens array for the current line
// Strips all whitespace tokens array for the current line
// if there was a {{#tag}} on it and otherwise only space.
// if there was a {{#tag}} on it and otherwise only space.
function stripSpace() {
function stripSpace() {