Giter Club home page Giter Club logo

Comments (10)

GoogleCodeExporter avatar GoogleCodeExporter commented on June 12, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 12, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 12, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 12, 2024

Original comment by [email protected] on 17 Sep 2009 at 4:07

  • Changed title: Implement predicates for selecting sections

from json-template.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 12, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 12, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 12, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 12, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 12, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 12, 2024

Original comment by [email protected] on 9 Nov 2009 at 6:58

  • Added labels: Todo-Java, Todo-PHP

from json-template.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.