Procházet zdrojové kódy

Merge branch 'master' of git://shakti.local/mustache.js

Conflicts:
	mustache.js
tags/0.2
Alexander Lang před 16 roky
rodič
revize
2d5b7e2c81
4 změnil soubory, kde provedl 33 přidání a 31 odebrání
  1. +1
    -0
      examples/two_in_a_row.html
  2. +4
    -0
      examples/two_in_a_row.js
  3. +1
    -0
      examples/two_in_a_row.txt
  4. +27
    -31
      mustache.js

+ 1
- 0
examples/two_in_a_row.html Zobrazit soubor

@@ -0,0 +1 @@
{{greeting}}, {{name}}!

+ 4
- 0
examples/two_in_a_row.js Zobrazit soubor

@@ -0,0 +1,4 @@
var two_in_a_row = {
name: "Joe",
greeting: "Welcome"
};

+ 1
- 0
examples/two_in_a_row.txt Zobrazit soubor

@@ -0,0 +1 @@
Welcome, Joe!

+ 27
- 31
mustache.js Zobrazit soubor

@@ -84,44 +84,40 @@ var Mustache = function() {
Replace {{foo}} and friends with values from our view Replace {{foo}} and friends with values from our view
*/ */
render_tags: function(template, context) { render_tags: function(template, context) {
var pop_first = function(lines) {
var lines_array = lines.split("\n");
lines_array.shift();
return lines_array.join("\n");
};

var lines = template.split("\n");
var new_regex = function() { var new_regex = function() {
return new RegExp(that.otag + return new RegExp(that.otag +
"(=|!|<|\\{)?([^\/#]+?)\\1?" + that.ctag + "+", "m");
"(=|!|<|\\{)?([^\/#]+?)\\1?" +
that.ctag + "+",
"g");
}; };


// tit for tat // tit for tat
var that = this; var that = this;


regex = new_regex();
var lines = template;

// for each {{(!<{)?foo}} tag, do...
while(regex.test(lines)) {
template = template.replace(regex, function (match, operator, name) {
switch(operator) {
case "!": // ignore comments
return match;
case "=": // set new delimiters
that.set_delimiters(name);
return "";
case "<": // render partial
return that.render_partial(name, context);
case "{": // the triple mustache is unescaped
return that.find(name, context);
default: // escape the value
return that.escape(that.find(name, context));
}
}, this);
regex = new_regex();
lines = pop_first(lines);
}
return template;
var regex = new_regex();
for (var i=0; i < lines.length; i++) {
lines[i] = lines[i].replace(regex,
function (match,operator,name) {
switch(operator) {
case "!": // ignore comments
return match;
case "=": // set new delimiters, rebuild the replace regexp
that.set_delimiters(name);
regex = new_regex();
return "";
case "<": // render partial
return that.render_partial(name, context);
case "{": // the triple mustache is unescaped
return that.find(name, context);
default: // escape the value
return that.escape(that.find(name, context));
}},
this);
};

return lines.join("\n");
}, },


set_delimiters: function(delimiters) { set_delimiters: function(delimiters) {


Načítá se…
Zrušit
Uložit