Bläddra i källkod

works with empty sections

tags/0.4.0
Ben Cherry 15 år sedan
förälder
incheckning
d5e54b409a
5 ändrade filer med 18 tillägg och 19 borttagningar
  1. +7
    -7
      examples/two_sections.html
  2. +4
    -1
      examples/two_sections.js
  3. +3
    -3
      examples/two_sections.txt
  4. +1
    -1
      mustache.js
  5. +3
    -7
      test/mustache_spec.rb

+ 7
- 7
examples/two_sections.html Visa fil

@@ -1,7 +1,7 @@
{{#show_following}}
{{/show_following}}
{{#show_following}}
{{/show_following}}
{{#foo}}
BAR
{{/foo}}
BAR
{{^bar}}
BAR
{{/bar}}

+ 4
- 1
examples/two_sections.js Visa fil

@@ -1 +1,4 @@
var two_sections = {};
var two_sections = {
foo: true,
bar: false
};

+ 3
- 3
examples/two_sections.txt Visa fil

@@ -1,3 +1,3 @@
BAR bar
BAR bar
BAR bar
BAR
BAR
BAR

+ 1
- 1
mustache.js Visa fil

@@ -149,7 +149,7 @@ var Mustache = function() {


var that = this; var that = this;
var regex = new RegExp("(?:^([\\s\\S]*?))?" + this.otag + "(\\^|\\#)\\s*(.+)\\s*" + this.ctag + var regex = new RegExp("(?:^([\\s\\S]*?))?" + this.otag + "(\\^|\\#)\\s*(.+)\\s*" + this.ctag +
"\n*([\\s\\S]+?)" + this.otag + "\\/\\s*\\3\\s*" + this.ctag + "\\s*" +
"\n*([\\s\\S]*?)" + this.otag + "\\/\\s*\\3\\s*" + this.ctag + "\\s*" +
"([\\s\\S]*?)(?=(?:" + this.otag + "(?:\\^|\\#)\\s*(?:.+)\\s*" + this.ctag + ")|$)", "g"); "([\\s\\S]*?)(?=(?:" + this.otag + "(?:\\^|\\#)\\s*(?:.+)\\s*" + this.ctag + ")|$)", "g");


// for each {{#foo}}{{/foo}} section do... // for each {{#foo}}{{/foo}} section do...


+ 3
- 7
test/mustache_spec.rb Visa fil

@@ -92,22 +92,18 @@ describe "mustache" do
run_js(js).strip.should == "foo BAR" run_js(js).strip.should == "foo BAR"
end end


it "should not suck" do
it "should work with empty sections" do
js = <<-JS js = <<-JS
try{ try{
#{@boilerplate} #{@boilerplate}


print(Mustache.to_html("{{#foo}}\\
{{/foo}}\\
{{#bar}}\\
{{/bar}}\\
", {}));
print(Mustache.to_html("{{#foo}}{{/foo}}foo{{#bar}}{{/bar}}", {}));
} catch(e) { } catch(e) {
print(e); print(e);
} }
JS JS


run_js(js).should == "foanfs"
run_js(js).strip.should == "foo"
end end






Laddar…
Avbryt
Spara