Commit Graph

16 Commits

Author SHA1 Message Date
Michael Bayne 4b443fe148 Last night, I read about the Mustache templating library (a derivative of
Google's CTemplate) and got all hot and bothered, because it seemed like it
would be sufficiently powerful to replace Velocity for our Narya templating
needs.

I then sought out a Java implementation and found one, and quickly discovered
that it lacked the right level of awesome for my needs. So I foolishly decided
to write my own, because Mustache seemed simple enough that I could reimplement
it in a few hours.

A few hours later, I had a neat and tidy reimplementation of Mustache and then
set about to converting Narya to using it. Then the fun began.

I discovered that Mustache wants everything in a hash, but sometimes you just
want to iterate over the elements of a list, and print them into the template
whole-hog. So I extended Mustache with the special "this" variable for printing
the whole context instead of pulling values out of it by name.

Then I remembered that Velocity allows you to do a deep dive into objects,
calling methods and calling methods on the return values of those methods.
Velocity even allows you to pass constants as arguments to those methods (true,
strings, integers). Well, I reimplemented the compound keys, so that you can
call foo.bar.baz, but I didn't go so far as to support constant arguments. That
seemed a step too far into complexity land and to be the sort of thing that
Mustache tries to avoid. So with compound keys, I just had to add a few
alternative versions of methods we were already calling, since we only ever
passed true/false as an argument.

Then I realized that Mustache doesn't do any smart trimming of newlines, so if
you have:

{{#stuff}}
blah blah
{{/stuff}}

You get the annoying newline after the open-tag and after the close-tag. So I
modified my implementation to trim newlines in those circumstances, so that
template authors don't have to do a bunch of template-weirding whitespace
jockeying.

Then I discovered that Mustache doesn't support any notion of scope. So when
you're inside a so-called section, the only variables visible are those bound
by that section. The stuff outside the section is totally invisible. Well,
that's not how Velocity works, you can reference things outside your loop
iterations. It seemed no terribly affront to Mustache to make things work that
way as well, so I did that.

Then I discovered a problem with the fact that Mustache implicitly binds the
loop object to the root of the namespace, so if you have {{name}} outside the
loop and then your loop object also contains a {{name}} field, then you can't
see the outside {{name}} anymore because it's shadowed. Tough titties, in this
case, I just changed our code to not shadow the name.

Then I encountered a bunch of uses of $vidx to put a space before all but the
first element of a list. So I added two more special variables -first and -last
which allow you to do just that sort of thing (and more) in a more template
friendly way because you don't need a Turing complete language just to decide
whether or not you need to mind the gap.

Then I encoutered some uses of $vidx directly, where we were using it to assign
constants in invocation service related classes. So I added another special
variable -index which resolves to basically the same thing that $vidx resolves
to (a 1-based counter indicating which element you're on in your list
iteration). I rationalized to myself that if you wanted to automatically number
laundry lists in your templates, having -index would be nice.

Finally, I have Narya's templating stuff producing character-for-character
replicas of what it used to do with Velocity. Well, actually there's one
newline in a place where there didn't used to be one, but I think that newline
makes sense and it was maybe some sort of Velocity bug that caused it not to
exist.

I've tested the gendobj, genservice and genreceiver tasks. I have no tested
whatever uses streamable_as.tmpl, but I'm pretty confident that it will work
exactly as before because I modified hundreds of lines of other templates in
exactly the same ways and they all work just fine.

So the world gets yet another templating library:

http://code.google.com/p/jmustache/


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6218 542714f4-19e9-0310-aa3c-eee0fc999fb1
2010-10-22 06:42:47 +00:00
Michael Bayne 339c822d3a Let Eclipse know about Narya's gwt-user.jar and gwt-utils dependencies.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6189 542714f4-19e9-0310-aa3c-eee0fc999fb1
2010-10-13 17:04:26 +00:00
Dave Hoover 6fe5ae9238 Include jar for JSR-250
The @Generated annotation showed up in JSR-250 and then was bundled into
Java 1.6. For those of us stuck in a 1.5 world, there's fortunately a
nice tiny little jar with the necessary classes, so slurp that in.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6057 542714f4-19e9-0310-aa3c-eee0fc999fb1
2010-04-08 21:24:35 +00:00
Charlie Groves 67e88e2df5 Fuck off with that inject.internal shit
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6007 542714f4-19e9-0310-aa3c-eee0fc999fb1
2010-01-04 21:27:53 +00:00
Charlie Groves 266595e2a0 Disallow access to atunit/lib/com/google in atunit.jar
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5854 542714f4-19e9-0310-aa3c-eee0fc999fb1
2009-07-08 21:06:48 +00:00
Michael Bayne 37c14fe414 Depot now exports google-collect.jar for us.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5553 542714f4-19e9-0310-aa3c-eee0fc999fb1
2008-11-17 18:47:59 +00:00
Michael Bayne 0de7d59bdb Have narya depend on depot which depends on samskivert.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5552 542714f4-19e9-0310-aa3c-eee0fc999fb1
2008-11-17 18:46:23 +00:00
Nathan Curtis aaa403052e ooo-libs' samskivert is back.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5338 542714f4-19e9-0310-aa3c-eee0fc999fb1
2008-08-25 16:51:30 +00:00
Nathan Curtis 0c9199c2a5 Narya exports the samskivert jar and the jars that our projects rely on that samskivert used to
export


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5335 542714f4-19e9-0310-aa3c-eee0fc999fb1
2008-08-22 18:26:50 +00:00
Mike Thomas aff425651c Stop eclipse copying .svn dirs to the output directory.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5299 542714f4-19e9-0310-aa3c-eee0fc999fb1
2008-08-07 23:07:25 +00:00
Michael Bayne aba13e5718 Oops, that's tests not test.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5287 542714f4-19e9-0310-aa3c-eee0fc999fb1
2008-08-04 18:11:01 +00:00
Michael Bayne 024e112796 More output fixes.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5284 542714f4-19e9-0310-aa3c-eee0fc999fb1
2008-08-04 17:47:36 +00:00
Charlie Groves 335fcc6da1 Export guice since subprojects are going to need it
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5175 542714f4-19e9-0310-aa3c-eee0fc999fb1
2008-06-09 18:03:21 +00:00
Mike Thomas 57ff422162 Tell eclipse about guicey jars.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5174 542714f4-19e9-0310-aa3c-eee0fc999fb1
2008-06-09 17:33:36 +00:00
Charlie Groves c4af1d257c Add dependency on google-collect for the bureaucracy
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5035 542714f4-19e9-0310-aa3c-eee0fc999fb1
2008-05-05 21:10:11 +00:00
Charlie Groves 0784d40c10 Eclipse metadata
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4856 542714f4-19e9-0310-aa3c-eee0fc999fb1
2007-10-26 18:37:07 +00:00