Sfoglia il codice sorgente

i18n twitter stuff

tags/0.4.0
Ben Cherry 15 anni fa
parent
commit
a7f71e1635
1 ha cambiato i file con 31 aggiunte e 2 eliminazioni
  1. +31
    -2
      mustache.js

+ 31
- 2
mustache.js Vedi File

@@ -13,7 +13,8 @@ var Mustache = function() {
pragmas: {},
buffer: [],
pragmas_implemented: {
"IMPLICIT-ITERATOR": true
"IMPLICIT-ITERATOR": true,
"TRANSLATION-HINT": true
},
context: {},

@@ -34,8 +35,15 @@ var Mustache = function() {
}
}

// Branching or moving down the partial stack, save any translation mode info.
if (this.pragmas['TRANSLATION-HINT']) {
context['_mode'] = this.pragmas['TRANSLATION-HINT']['mode'];
}

template = this.render_pragmas(template);

template = this.render_i18n(template, context, partials);

var html = this.render_section(template, context, partials);

var stillNeedsToRender = (html === template);
@@ -110,6 +118,27 @@ var Mustache = function() {
return this.render(partials[name], context[name], partials, true);
},

render_i18n: function(html, context, partials) {
if (html.indexOf(this.otag + "_i") == -1) {
return html;
}
var that = this;
var regex = new RegExp(this.otag + "\\_i" + this.ctag +
"\\s*([\\s\\S]+?)" + this.otag + "\\/i" + this.ctag, "mg");

// for each {{_i}}{{/i}} section do...
return html.replace(regex, function(match, content) {
var translation_mode = undefined;
if (that.pragmas && that.pragmas["TRANSLATION-HINT"] && that.pragmas["TRANSLATION-HINT"]['mode']) {
translation_mode = { _mode: that.pragmas["TRANSLATION-HINT"]['mode'] };
} else if (context['_mode']) {
translation_mode = { _mode: context['_mode'] };
}

return that.render(_(content, translation_mode), context, partials, true);
});
},

/*
Renders inverted (^) and normal (#) sections
*/
@@ -333,7 +362,7 @@ var Mustache = function() {
if(send_fun) {
renderer.send = send_fun;
}
renderer.render(template, view, partials);
renderer.render(template, view || {}, partials);
if(!send_fun) {
return renderer.buffer.join("\n");
}


Loading…
Annulla
Salva