| @@ -0,0 +1 @@ | |||||
| {{#array_of_strings}} {{.}} {{/array_of_strings}} | |||||
| @@ -0,0 +1 @@ | |||||
| var array_of_strings = {array_of_strings: ['hello', 'world']}; | |||||
| @@ -0,0 +1 @@ | |||||
| hello world | |||||
| @@ -29,7 +29,7 @@ var Mustache = { | |||||
| } | } | ||||
| // keep context around for recursive calls | // 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 | // first, render all sections | ||||
| var html = this.render_section(template); | var html = this.render_section(template); | ||||
| @@ -42,7 +42,19 @@ var Mustache = { | |||||
| // render until all is rendered | // render until all is rendered | ||||
| return this.render_tags(html); | 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 | Tries to find a partial in the global scope and render it | ||||
| */ | */ | ||||
| @@ -18,11 +18,15 @@ describe "mustache" do | |||||
| mustache = File.read(__DIR__ + "/../mustache.js") | mustache = File.read(__DIR__ + "/../mustache.js") | ||||
| runner = <<-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 | JS | ||||
| File.open("runner.js", 'w') {|f| f << runner} | File.open("runner.js", 'w') {|f| f << runner} | ||||
| @@ -1,14 +0,0 @@ | |||||
| var a = function(s) { | |||||
| return s.replace(/[&"\<>]/g, function(s) { | |||||
| switch(s) { | |||||
| case "&": return "&"; break; | |||||
| case "\\": return "\\\\"; break; | |||||
| case '"': return '\"'; break; | |||||
| case "<": return "<"; break; | |||||
| case ">": return ">"; break; | |||||
| default: return String(s); break; | |||||
| } | |||||
| }); | |||||
| }; | |||||
| print(a("as&<")); | |||||