Bläddra i källkod

added processing arrays of plain values

tags/0.2
Alexander Lang 16 år sedan
förälder
incheckning
437056a7e7
6 ändrade filer med 26 tillägg och 21 borttagningar
  1. +1
    -0
      examples/array_of_strings.html
  2. +1
    -0
      examples/array_of_strings.js
  3. +1
    -0
      examples/array_of_strings.txt
  4. +14
    -2
      mustache.js
  5. +9
    -5
      test/mustache_spec.rb
  6. +0
    -14
      test/mustache_test.js

+ 1
- 0
examples/array_of_strings.html Visa fil

@@ -0,0 +1 @@
{{#array_of_strings}} {{.}} {{/array_of_strings}}

+ 1
- 0
examples/array_of_strings.js Visa fil

@@ -0,0 +1 @@
var array_of_strings = {array_of_strings: ['hello', 'world']};

+ 1
- 0
examples/array_of_strings.txt Visa fil

@@ -0,0 +1 @@
hello world

+ 14
- 2
mustache.js Visa fil

@@ -29,7 +29,7 @@ var Mustache = {
}

// keep context around for recursive calls
this.context = context = this.merge((this.context || {}), view);
this.context = context = this.merge((this.context || {}), this.create_context(view));

// first, render all sections
var html = this.render_section(template);
@@ -42,7 +42,19 @@ var Mustache = {
// render until all is rendered
return this.render_tags(html);
},

create_context: function(_context) {
if(this.is_object(_context)) {
return _context;
} else {
return {'.': _context};
}
},
is_object: function(a) {
return a && typeof a == 'object'
},
/*
Tries to find a partial in the global scope and render it
*/


+ 9
- 5
test/mustache_spec.rb Visa fil

@@ -18,11 +18,15 @@ describe "mustache" do

mustache = File.read(__DIR__ + "/../mustache.js")
runner = <<-JS
#{mustache}
#{view}
var template = #{template};
var result = Mustache.to_html(template, #{testname});
print(result);
try {
#{mustache}
#{view}
var template = #{template};
var result = Mustache.to_html(template, #{testname});
print(result);
} catch(e) {
print('ERROR: ' + e.message);
}
JS

File.open("runner.js", 'w') {|f| f << runner}


+ 0
- 14
test/mustache_test.js Visa fil

@@ -1,14 +0,0 @@
var a = function(s) {
return s.replace(/[&"\<>]/g, function(s) {
switch(s) {
case "&": return "&amp;"; break;
case "\\": return "\\\\"; break;
case '"': return '\"'; break;
case "<": return "&lt;"; break;
case ">": return "&gt;"; break;
default: return String(s); break;
}
});
};

print(a("as&<"));

Laddar…
Avbryt
Spara