chrisdickinson / plate

a javascript template library, aimed at being compatible with django's template language.
183 stars 17 forks source link

New-style with-tag ({% with a=b x=y %}) #21

Closed eternicode closed 2 months ago

eternicode commented 10 years ago

Implements the new with tag syntax {% with x=y %} while keeping old-style syntax {% with y as x %} intact (since Django 1.3).

A lot of this (mainly the new token_kwargs utility function) has been ported straight from the appropriate django sources.

Concerns:

FWIW, this implementation works for my templates which, at the moment, use a combination of old-style and new-style with tags.

Also, concerning code style, I didn't see any style guide, and there is no linter config in the repo, so I may have botched some style :grin:. I tried to follow existing conventions, but I'm happy to tweak specific things if you'll point them out.

eternicode commented 10 years ago
  • WithNode.render has lost a bit of code related to the second argument (value) and Promises. I'm not familiar enough with the codebase to say for sure, but looking through the rest of the code, I couldn't find any solid evidence that this second argument is ever actually passed in normal usage.

After spending a bit more time in the code, I get what this argument and the promise-related code did. I've added a commit that handles values that resolve to Promises.

Related note: There seem to be 0 tests related to variables/filters resolving to promises...

chrisdickinson commented 10 years ago

This is a great addition, thanks! The explicit global is the only remaining issue -- I can definitely handle the style fixes.

eternicode commented 10 years ago

Done and done.