10 ms·
Please look at JSON Template. http://code.google.com/p/json-template/ http://code.google.com/p/json-template/ It solves ALL of these problems. It has {.or},
by chubot 16y ago
Please look at JSON Template. http://code.google.com/p/json-template/ http://code.google.com/p/json-template/
It solves ALL of these problems. It has {.or}, the dot notation, and searches up the stack of contexts for variables.
I haven't been working on it for awhile, mostly because it does the job, but the codebase is small and easily hackable.
EDIT: It also compiles the templates and lets you change the delimiters! And has support for several other languages.
- deleted 16y ago[deleted]
- janl 16y agoJSON Template was around before mustache came around, it didn't win then, I don't know if it will win now. I want to improve the Mustache line, not make people switch to something else. As an alternative, it looks good, so thanks for bringing it up.
- chubot 16y agoI don't really think of it as "winning or losing". It's not like a general purpose programming language with large network effects (e.g. you may depend on a library with 100k sloc). The switching cost is pretty low, especially since they both use JSON as the data model.
- binspace 16y agoMustache has an equivalent to {.or} {{^something}} {{/something}} The draw of mustache is that it does things implicitly. I don't have to worry about .section, .repeated, .or, |html, for example. Mustache does it for me. That being said, one thing that mustache does need to address is the difference between conditionals and repeated operations as needed (handled by .section and .repeated in JSON Template). AFAIK, the songs template would require a boolean to be passed in of the existence of songs in mustache, since mustache would implicitly assume that {{#songs}} was a loop and create multiple tables. http://json-template.googlecode.com/svn/trunk/doc/Introducing-JSON-Template.html http://json-template.googlecode.com/svn/trunk/doc/Introducin...
- janl 16y agoIf you read the linked article, you'd see that I am calling for an {.or}-like construct to avoid having to use inverted sections for a fake else-case.
- binspace 16y agoGot it. I guess the distinction is not that big of a deal for me, though it would be nice to have the inline {.or}-like construct (it saves one statement).
- chubot 16y agoYou can set the default formatter to "html" if you want (or any other formatter). It probably could be better documented. You seem to be on the fence about if you want an explicit "repeated" or not. I haven't thought about it too much but it seems cleaner to be explicit. I don't want to confuse an object {} and a singleton array [{}].
- arnorhs 16y agoJSON template looks nice. Great feature set. I don't know about the python version, but I had a look at the Javascript code for json-template. At first look it seems pretty "hacky". The main obvious flaws I saw were: - it's polluting the global namespace a lot. Introducing a lot of functions and variables. - it's roughly 800 lines, while mustache.js is just over 300. I realize json template has more features. - A lot of the javascript could do with some optimization. Especially some of the loops. But maybe that's something you simply want help with?
- chubot 16y agoEverything is wrapped in the "jsontemplate" namespace. It's just not indented. If you have some speedups I'm open to it, although I think it is pretty fast as it doesn't parse the template on every expansion.