Comments (10)
For clarification, the "stack of namespaces" is exactly what JS prototypes are,
although I don't think of the as "prototypes" because the attributes generally
don't
overlap.
We could also change the JS implementation to actually use .prototype -- this
would
probably make it a bit faster.
Original comment by [email protected]
on 22 Sep 2009 at 4:49
from json-template.
Note: This is a little problematic for compatibility. The 'html' formatter is:
def HtmlEscape(s): # s is a string from the JSON
return cgi.escape(s)
If you need any other variables, it would have to be:
def HtmlEscape(context):
DoSomethingWith(context.Lookup('other-name'))
return cgi.escape(context.Lookup('@'))
Might have to distinguish between the 2 kinds of formatters/predicates.
{@|html}
{relative-url|$format-with-base-url}
Not sure I like $. Likewise for the Plural predicate -- it may need to take an
integer as well as a context.
Another possibility is to distinguish formatters/predicates on atoms (strings,
numbers, bools) vs formatters/predicates on composites (lists, dictionaries).
Original comment by [email protected]
on 25 Sep 2009 at 7:47
from json-template.
Idea: formatters/predicates that begin with a lower case letter take atoms.
Those
that begin with a capital letter take contexts.
Original comment by [email protected]
on 25 Sep 2009 at 7:48
from json-template.
I'm not a fan of having case change the meaning of things. Why not just always
pass the context as the second
parameter? Some formatters use it, some don't. In this case, the html formatter
just ignores the second
parameter and the format-with-base-url uses it.
Original comment by sroussey
on 28 Sep 2009 at 12:52
from json-template.
Well, that will break everyone's existing formatters. And I like being able to
do:
more_formatters={'html': cgi.escape}
rather than:
more_formatters={'html': lambda s, unused: cgi.escape(s)}
For functions that already exist.
I'm assuming here that nobody has formatters that start with non-lowercase
char.
It's a little unconventional but I think it's very simple and elegant. Template
authors generally don't need to be aware of it.
Original comment by [email protected]
on 28 Sep 2009 at 3:15
from json-template.
Hmm... in Javascript and PHP, it won't break existing formatters. It breaks
things in
Python, I guess, if you pass an unused parameter?
Original comment by sroussey
on 28 Sep 2009 at 10:44
from json-template.
Yup, in Python that breaks it. Interesting that it doesn't in PHP and
JavaScript. I
suppose we could make the API different. Not sure how I feel about that.
In general I want template-level compatibility. I suppose this doesn't break
template compatibility, only API compatibility. But the list of formatters is
supposed to cross-language. So "AbsUrl" should do the same thing in all
languages.
In Java it definitely matters. Probably C# and Ruby do too... I think
Javascript and
PHP are exceptional in this regard.
Original comment by [email protected]
on 29 Sep 2009 at 2:56
from json-template.
In Python, if you used named parameters, I think it can be more like JS and
PHP. But
that might be a Python 3.x thing. I can't remember where I read that....
If there is to be a break for the other languages, it could be with four
parameters:
formatter_function (data, context, formatter, argument_string)
data -- the same thing as always
context -- as you outline above
formatter -- the string as the user wrote it (this would seem overly redundant
unless
you had several formatters mapped to the same formatter function)
argument_string -- whatever text the user wrote that came after the previous
formatter parameter (alternately, given the previous parameter is available, it
could
be the entire string the user wrote -- if the function cared about the stuff
after,
it could strip off the formatter name as given in the previous param).
You could conceivably have the call type (one param or four params) to
formatters and
predicates be based on option, like meta characters are. In such a case, the
user
would have to specifically ask for feature that might then break their code,
otherwise everything degrades to the current system.
Original comment by sroussey
on 29 Sep 2009 at 4:16
from json-template.
Reply in the group. Implemented in Python as:
http://code.google.com/p/json-template/source/detail?r=9957eb309b019980d8ded3571
f2daebc7ee34eba
As mentioned this doesn't rule out the other idea, which is a more complex
superset.
Original comment by [email protected]
on 30 Sep 2009 at 6:00
- Changed state: Started
from json-template.
Original comment by [email protected]
on 7 Nov 2009 at 9:19
- Added labels: Todo-Java, Todo-PHP
from json-template.
Related Issues (20)
- Unbalanced section push and pop in the Java implementation HOT 3
- Add a LISP-style "let" statement
- A predicate containing the text 'or' results in a template parsing error
- typo in UrlParamsJsonTemplateFormatter HOT 2
- Error in JsonTemplateModule::FromFile() HOT 1
- Iteration over dictionary - Patch for /python/jsontemplate/_jsontemplate.py HOT 1
- Iteration over dictionary - Patch for /python/jsontemplate/_jsontemplate.py HOT 1
- cannot pip install json-template
- Javascript within JSON templates HOT 1
- <img> src being ignored. HOT 1
- Possibly a typo introduced by revision cc10d7e78b94 HOT 1
- HTML formatter doesn't work for numeric values HOT 2
- expand sometime return blank HOT 1
- Patch for /jesyll-doc/__config.json
- token_re_cache in javascript implementation doesn't do anything? HOT 2
- Setup.py dependency chaining broken; fix enclosed HOT 1
- Python 3 diff HOT 1
- json data formte with metdata of object HOT 1
- Iteration over dictionary (patch) HOT 2
- saite de filmes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-template.