mustache / mustache.github.com

The {{official}} website
http://mustache.github.io/
Other
2.31k stars 293 forks source link

C# Port of Mustache.js #62

Closed ubershmekel closed 9 years ago

ubershmekel commented 9 years ago

It's not yet 100% compliant but it's almost there and I hope to finish soon.

locks commented 9 years ago

Thanks for your work :) Ping this thread when you have the specs passing and I'll merge it in.

ubershmekel commented 9 years ago

Np :) It's done. Every example at https://mustache.github.io/mustache.5.html appears and passes in the unittests.

bobthecow commented 9 years ago

@ubershmekel How does it do on the full Mustache spec? https://github.com/mustache/spec

ubershmekel commented 9 years ago

I wasn't aware of that spec, thanks! It's succeeded in 81/114 tests. I did not test dynamic lambdas for C# as that code is missing from the spec.

I'll see what I can do with the remaining 33 spec tests. But I'm not sure I understand some of it e.g.

template: "!\n  {{! I'm Still Standalone }}"
expected: "!\n"

Why remove the spaces?

bobthecow commented 9 years ago

Nice! That's pretty good for not even knowing the spec was there :)

That test is a test for standalone tags. Basically, there are a few tags that eat their entire line if they're the only thing on it. It's one of the harder whitespace issues to implement in the spec, judging from how many libraries get it wrong. But it's relatively simple to understand. Take this for example:

<ul>
  {{# items }}
    <li>{{ . }}</li>
  {{/ items }}
</ul>

When it's rendered, it shouldn't be like this:

<ul>
..
....<li>one</li>
....<li>two</li>
....<li>three</li>
..
</ul>

… it should be like this:

<ul>
....<li>one</li>
....<li>two</li>
....<li>three</li>
</ul>

But the line should only not count if that section tag is the only thing on the line. For example:

{{# foo }}<!-- start foo -->
    here's foo!
{{/ foo }}

In that case, the html comment needs to stay there. If the whole line disappears, the comment has nowhere to live. So that line wouldn't be collapsed, because the {{# foo }} tag isn't standalone.

The tags which act like this are open and close section, inverted section, comment, pragma, delimiter change, and partial.

Make sense?

ubershmekel commented 9 years ago

Yup. That makes sense. Thanks!

ubershmekel commented 9 years ago

By the way it's actually Succeeded in 91/113 tests when I use the Json parser and not Yaml. false was being parsed as "false" :open_mouth: Perhaps that's a YamlDotNet bug.

bobthecow commented 9 years ago

:+1:

ubershmekel commented 9 years ago

The dotnet implementation has the spec working https://ci.appveyor.com/project/Romanx/nustache/build/tests and it works with vanilla C#. So I think it's better to make it more discoverable by pointing that out. See the revised commit. This was a fun weekend project though, so thanks.

locks commented 9 years ago

Nustache is already listed in the homepage, so I'll close this issue. Thank you for your efforts regardless :)

locks commented 9 years ago

I just noticed https://github.com/ubershmekel/mustache.github.com/commit/49e2667d2c21debdfe4f591a8344f2fb0e5ec99a. If you send it separately I'll merge it in.