Comments (10)
Answered on the group, see discussions about "predicates":
http://groups.google.com/group/json-template/browse_thread/thread/f354e3c2108353
b7#
http://groups.google.com/group/json-template/browse_thread/thread/1ef3327f6f9b54
36#
The reason it's done this way is that I don't want to add any operators to the
language. Once you add ==, then you need !=, >, >=, list membership, dictionary
membership, etc. So the solution is to just define predicates in the host
language
and refer to them in the template.
Comments welcome. I haven't gone around to implementing it yet.
Original comment by [email protected]
on 15 Sep 2009 at 6:54
from json-template.
OK, not adding operators to the template language makes sense.
So
{.section foo}
stuff
{.end}
is (will be) shorthand for:
{.section foo foo?}
stuff
{.end}
What do you mean by filters?
And what are your ideas on how to implement?
Original comment by sroussey
on 16 Sep 2009 at 11:04
from json-template.
No it will be shorthand for
{.section foo true?}
stuff
{.end}
The default predicate denoted "true?" is like "bool()" in Python -- take any
object
and convert it to True/False.
When I said "filters" there I meant "formatters", which come after the |.
Formatters
transform an arbitary value to a string. Predicates convert an arbitrary value
to a
boolean.
I don't think it should be too hard to implement. It's just adding the
predicate to
the parsing, looking it up at runtime, and deciding which section to expand.
Original comment by [email protected]
on 17 Sep 2009 at 4:06
from json-template.
Original comment by [email protected]
on 17 Sep 2009 at 4:07
- Changed title: Implement predicates for selecting sections
from json-template.
To me this mean that it will always run:
{.section foo true?}
stuff
{.end}
But a section won't show if there is no foo, correct?
To me, this seems like a better translation:
{.section foo}
stuff
{.end}
is the same as
{.section foo foo|true?}
stuff
{.end}
depending on the name of the function. Could be isTrue
{.section foo foo|isTrue?}
stuff
{.end}
So we can do this (where stuff in [] denotes what is optional):
{.section scope[|formatter][ test[|predicate]?]}
stuff
{.end}
Does that look right?
Original comment by sroussey
on 17 Sep 2009 at 4:51
from json-template.
There are only 2 concepts: formatters and predicates. You have 3 things there
--
what is "test"?
I haven't committed to doing formatters on sections -- only predicates. But if
we
were to add it, then the syntax would be:
{.section foo plural?|html}
hello
{.or}
<i>bye</i>
{.end}
That formats the section as HTML no matter what -- showing the first clause if
foo is
plural, otherwise showing the second clause.
There was a long discussion about the merits of combining these and the syntax
on the
groups thread I pointed you to. In sum, the formatters on sections seem nice,
but
they complicate some aspects of implementation. Maybe at some point though.
Original comment by [email protected]
on 17 Sep 2009 at 3:48
from json-template.
OK, I see. So no formatter, just predicates. But I'd like to see them optionally
based on different parts of the JSON.
JSON={
advancedSetting:true,
foo: ...
bar: ...
...
}
{.section foo advancedSetting|true?}
hello
{.or}
<i>bye</i>
{.end}
{.section jj}
stuff
{.end}
{.section foo advancedSetting|true?}
hello
{.or}
<i>bye</i>
{.end}
Thus why I thought:
{.section foo}
was shorthand for:
{.section foo foo|true?}
I need something more flexible like this, so I'm likely going to have to fork.
:(
But any other good changes I make I'll port over. I was hoping not to get into
the
implementation so much, but I guess that will give me the opportunity to have
better
compilation (like the php version creating compiled php files like smarty).
Original comment by sroussey
on 17 Sep 2009 at 10:04
from json-template.
I meant:
{.section foo advancedSetting|true?}
hello
{.or}
<i>bye</i>
{.end}
{.section jj}
stuff
{.end}
{.section bar advancedSetting|true?}
hello
{.or}
<i>bye</i>
{.end}
the second section having bar not foo....
I'll move the discussion over to the Google Group from here on out. Sorry to
clutter
up the issues list...
Original comment by sroussey
on 17 Sep 2009 at 10:07
from json-template.
Started in Python:
http://code.google.com/p/json-template/source/detail?r=1fd56e7734c6e5f7455526402
ee71002291068b2
Original comment by [email protected]
on 30 Sep 2009 at 6:01
- Changed state: Started
from json-template.
Original comment by [email protected]
on 9 Nov 2009 at 6:58
- 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.