Giter Club home page Giter Club logo

json-template's People

Contributors

pauloppenheim avatar sroussey avatar

Watchers

 avatar

json-template's Issues

Add PrefixRegistry

The formatter/predicate is identified by prefix.

The next char is a arg separator, usually space.

And then come the variable list of arguments.

Original issue reported on code.google.com by [email protected] on 21 Oct 2009 at 4:43

PHP Notice: in the log files

What steps will reproduce the problem?
1. print JsonTemplateModule::expand($tmpl,$data);

What is the expected output? What do you see instead?
----
No Error in the log. Errors in the log.

What version of the product are you using? On what operating system?
----
HEAD version of the PHP code base, Apache2, PHP 5.3, OSX

Please provide any additional information below.
----
These two code line will remove the errors found in the log.

Line 187: if(!isset($formatter) || !$formatter){

Line 267: if(isset($this->statements[$clause])) return
$this->statements[$clause];

Original issue reported on code.google.com by [email protected] on 2 Feb 2010 at 7:10

Fix lookup of null values

These should not raise UndefinedVariable.  The null value can be passed to
the formatter.

See mailing list.

Original issue reported on code.google.com by [email protected] on 15 May 2009 at 5:05

configurable log function (javascript)

json-template Javascript defines a 'log' function and makes it be the
system 'log' function if it exists, otherwise a function that does nothing.
This clobbers the system 'log' function.

It's sometimes nice to be able to turn off logging in json-template
entirely - an application that *uses* json-template may want to do its own
logging and having the output from json-template appear in for instance
firebug is rather distracting.

The simplest way (though somewhat ugly as we need to modify the source
code) is to go into json-template.js and do:

var log = function() {};

but since you redefine the system 'log' here, *all* logging in any
javascript code is disabled.

If instead we'd use a log function with a different name (say, _log) in
json-template code, we could globally disable json-template logging with a
single edit.

I'd be nicer still if we could somehow configure json-template to log or
not log, and configure which logging function to use. An essential first
step in accomplishing that is still not clobbering the system 'log', though.

Original issue reported on code.google.com by [email protected] on 20 Apr 2009 at 12:56

Need builtin predicate that tests attributes up the stack

See {.Debug?} which is already a default predicate

Suggesting {.attr debug?}   {.attr isAdmin?} 

Or the other idea is just to make attributes live in the *same namespace*
as predicates:

{.debug?}

{.isAdmin?}

At first this seems confusing, because you could make a typo like
{.isAAAdmin?} and it would return false.  But that's a problem with {.attr
isAdmin} too (if isAdmin is missing, then it will return False)


Original issue reported on code.google.com by [email protected] on 11 Dec 2009 at 4:25

Make JSON Template work with Protobol Buffers

This is most easily done via something like pyb (dynamic PB engine, no code
generation):

http://code.google.com/p/protobuf-pyb/

Rationale here:

http://groups.google.com/group/json-template/browse_thread/thread/86a8cc7e6131b2
0b

Original issue reported on code.google.com by [email protected] on 14 Nov 2009 at 6:24

Implement predicates for selecting sections

How to do an if statement? 

{.section foo=='bar'} 

some stuff {a:html}
 other junk {b:html} 
{.end}

{.section foo=='barbara'} 
more stuff {c:html} 
complete junk {v:html} 
{.end} 

? 

I sorta hacked it in, but obviously it is not in the other versions (only 
JS). But some sort of IF statement is essential, I think.

Original issue reported on code.google.com by sroussey on 15 Sep 2009 at 4:55

Formatters (and predicates) should be passed a stack of namespaces, rather than a single one

This is a design bug, but thankfully we can keep compatibility:

{"base-url": "http://foo",
  posts: [ { "relative-url": ... id1 },
           { "relative-url": ... id2 },
}

{.repeated section posts}
  {base-url}/{relative-url}   <-- Here we can access the "global" base-url
  {relative-url|format-with-base-url}  <-- The formatter has no access to it
  {section relative-url is-public?}  <-- Predicate needs access to it
{.end}

Original issue reported on code.google.com by [email protected] on 22 Sep 2009 at 6:19

ToString filter not doing what it should. (javascript)

The ToString formatter should invoke s.toString() which is either
Object.toString() or whatever is overridden. Since javascript does not do
this automatically like java does whenever converting an object to a string
it would make sense to do this, otherwise ToString is really a noop.

Original issue reported on code.google.com by dlikhten on 7 Apr 2009 at 12:22

Better handle undefined variables

$console.log(jsontemplate.Template('vvv={vvv}').expand({xxx:10}))

Generate an exception difficult to intercept and on real/complex 
applications it is possibile that variables are not present in the json 
object.

I've made a patch that detects this situation, logs it and return an empty 
String to let the program execution continue without exceptions

I'll find it useful and think others too..

Thanks, Francesco.

Original issue reported on code.google.com by [email protected] on 3 Jul 2009 at 7:06

Attachments:

Provide @index variable for the current array index

This is really common and trivial to implement.

Then you can to {section $index odd?} color1 {.or} color2 {.end}

Or also {$index|even? color1 color2}

Could make it 'index', but that might clobber people's variables.  $ means
a "special" variable.




Original issue reported on code.google.com by [email protected] on 22 Jul 2009 at 1:47

javascript example currently broken

This page is referenced from the project homepage:

http://json-template.googlecode.com/svn/trunk/doc/Introducing-JSON-Template.html

it references:

http://json-template.googlecode.com/svn/trunk/doc/testTableExample-001.js.html

Unfortunately, the example is currently broken on Firefox (3.0.8 on Linux).
That's not a good demo.

Perhaps this example never worked. But it's still not a very good idea to
publish the moving SVN trunk as documentation to the web. It might be a
good idea to at the very least tag a working version of the project and
link to this to the homepage, to prevent such occurrences.

Original issue reported on code.google.com by [email protected] on 17 Apr 2009 at 2:44

Default argument to sections and repeated sections should be @

For repeated sections, a common idiom to put them inside a section:

{.section foo}
  {.repeated section}  {# leave off @ here}
  {.end}
{.end}

If sections grow predicates, then you might do something like:

{.section foo}
  Stuff here
  {.section?plural}
    Only in the plural case
  {.end}
{.end}

{.section?plural} is the same as {.section @ ? plural}

(still don't like the ? syntax)


Original issue reported on code.google.com by [email protected] on 23 Jun 2009 at 6:07

Need DotNet version

I like what I see, but I need/want to use it from .Net.  I also need the
Python, JavaScript, and Java versions, but they already exist.

I propose to port json-template to .Net, if that would be acceptable. 
Please inform me regarding the necessary coordination steps (shall I send
you a draft for your review?).

Original issue reported on code.google.com by Robert.David.Williams on 7 Apr 2009 at 7:06

Nested repeated section issue

Got this template to reproduce a sort of breadcrumbs output:
[ul class="path"]
{.repeated section outer}
    [li]
        {.repeated section inner}
            [a href="#"]{someproperty}[/a] >    
        {.end}
        [a href="#"]{someotherproperty}[/a]
    [/li]
{.end}  
[/ul]

When the outer has only one inner element it doesn't show it, if it has
more than one it shows perfectly. 
What version of the product are you using? On what operating system?

I've tested in macosx leopard firefox 3 and safari 4.

Any clues ?

Original issue reported on code.google.com by [email protected] on 22 Jun 2009 at 5:01

Idea: implement XSS detection

http://googleonlinesecurity.blogspot.com/2009/03/reducing-xss-by-way-of-automati
c.html

This protects against the template author making a mistake in specifying
the escaping formatter.  Since JSON Template is trivial to tokenize, it
shouldn't be that hard.

Original issue reported on code.google.com by [email protected] on 10 Apr 2009 at 7:40

Live example doesn't work in IE6

What steps will reproduce the problem?
1. Run jslint on json-template.js

What is the expected output? What do you see instead?

Lint at line 376 character 25: Extra comma.
'space': ' ',


What version of the product are you using? On what operating system?

Windows IE6

Please provide any additional information below.

You mentioned in the demo that it doesn't work in IE6 so I thought I would
check it out.

First it didn't work but didn't give any debugger info, so I ran the script
through jslint, and it found an extra comma at the end of one of your objects:

Lint at line 376 character 25: Extra comma.
'space': ' ',

Then after removing that comma, it was giving me a debugger error, but I
haven't quite figured that out. Attaching debugger screenshot for your info.

Original issue reported on code.google.com by [email protected] on 31 Mar 2009 at 5:50

Attachments:

Need Unicode Test Cases

This was brought up in discussion about the Java implementation, there are
no tests for Unicode (very important for templates!)

The Python version's output types just relies on the input types, so should
be fine, but need tests.


Original issue reported on code.google.com by [email protected] on 7 Apr 2009 at 3:15

GetFormatter is wrong on so many levels (javascript). Proposed changes.

I will be working on fixing this, but to document my findings...

GetFormatter in the *javascript implementation* is wrong on so many levels:

1) It does not extend DEFAULT_FORMATTERS. Instead it just replaces the
defaults with more_formatters if they are specified.

2) It does not define any API of more formatters, it just assumes that the
full formatter name is going to be the exact name of the property. The
formatter cannot specify some special logic to deal with parameters or
anything of that nature. Esencially the conversation in ticket #4 regarding
making parameters for formatters is impossible in javascript impl (without
replacing any methods).

3) Essentially the default formatter and more_formatters are incompatible
APIs, default formatter is a hash, more_formatters should really be a function.

I propose doing the following:
1) Format rules: a function is invoked (overridable) which gets the full
formatter_str and returns an object containing: A formatter name, and an
array containing arguments to the invocation of that formatter.

2) That formatter is invoked, the first parameter is the raw format string,
the second parameter and onwards is the parameters parsed by the format
rules function.

3) The formatter returns the full text.

4) A formatter object can be passed which will extend (similar to how
jQuery does $.extend) the defaults.

5) The default format rules are the following: ^(.*)\((.*)\)$, group 1 =
formatter name, group 2 = formatter arguments, split by the comma(,) character.

Original issue reported on code.google.com by dlikhten on 7 Apr 2009 at 12:38

Trying to iterate over a string with repeated section should throw an error (JavaScript version)

Given the following template fragment
{.section term}
  {.repeated section @}
    <li>{@}</li>
  {.or}
    <li>{@}</li>
  {.end}
{.end}

The following input works as expected:
{term: ['one', 'two', 'three'] }

The following input however does not:
{term: 'one'}

On Firefox the string is treated as an array and returns a list element for
each character. On Internet Explorer it throws an error. The expected
result would have been to call the {.or} section of the template and only
produce a single list element.

The problem occurs on line 276 of json-template.js (210 2009-04-30), where
the code assumes that if the object exists and has a length value greater
than zero it will repeat the section:
  if (items && items.length > 0) 

Changing this line to test for the presence of an array fixes the error and
produces the expected result. The resulting fix is as follows:

  if (items && Object.prototype.toString.apply(items) === '[object Array]'
&& items.length > 0)

Original issue reported on code.google.com by [email protected] on 27 May 2009 at 11:50

Add FromString to the JavaScript version

It would be great to add the FromString method to the JavaScript version as
is found in the Python and PHP versions.

Original issue reported on code.google.com by sroussey on 15 Sep 2009 at 12:55

".repeated" is not strictly necessary

Proposal:

{.section} will be augmented to repeat if the node type is a list [].

{.repeated section} will then become superfluous.  But for readability,
we'll keep it, and it could *enforce* that the node type is a list, unlike
{.section}.



Original issue reported on code.google.com by [email protected] on 10 Apr 2009 at 12:34

Need Version labels for test cases

This is a multi-language project, so we need to be able to upgrade each
version on its own.

The cases should be labeled with versions, and then each implementation
(Python, Java, JavaScript) will be labeled with the maximum version it
supports.


Original issue reported on code.google.com by [email protected] on 7 Apr 2009 at 3:16

{.end} should take an argument and assert that it closes the argument

This is optional, but some people might want this for readability in long
templates.

{.section foo}
  blah
{.end foo}

{.section @}
  blah
{.end @}

{.section bar}
  blah
{.end foo}  <-- throws an error, 'foo' is not closed here

{.singular?}
  1
{.plural?}
  2
{.end ?}  <-- Asserts that predicates are closed

Original issue reported on code.google.com by [email protected] on 30 Sep 2009 at 6:13

Java version available

Hi, I translated the python implementation to Java. Maybe you're 
interested in including it?

http://codereview.appspot.com/33078

Original issue reported on code.google.com by [email protected] on 5 Apr 2009 at 6:15

Provide a standard way for formatters to take arguments, e.g. for implementing include statement

It would be quite useful to allow a template to include another template
passing it a section as the "root". Here is an example:

Template 1:
{.section items}
  <h1>{name}</h1>
  {.repeater section @}
    <a href="{urlbase}{url}"></a>
  {.end}
{.end}

Template 2:
{.section shoppingCart}
  {.template 'Template 1' @}
{.end}

OR

Template 2:
{.template 'Template 1' shoppingCart}


Its a tad bit funky since currently templating (I am using the javascript
version) takes in a string and substitutes.

What would be nice is the ability to pass in custom template finders so we
can specify the rules of how to retrieve another template string.

Original issue reported on code.google.com by dlikhten on 30 Mar 2009 at 5:35

JavaScript JSONTemplate cannot be prototyped

The Template class in JSONTemplate cannot be prototyped.
ie: You cannot add a function to jsontemplate.Template.prototype and make
use of it.

I tried making use of json-template inside of a Server Side environment and
wanted to prototype in a function to save a rendered template to the disk.
Because of the way Template returns a new object rather than acting like a
proper JavaScript class.

Rather than returning a new object Template should do something like this
at the very least:
{{{
function Template(template_str, options) {
  if(!( this instanceof Template )) return new Template(template_str, options);
  // options.undefined_str can either be a string or undefined
  options = options || {};

  var program = _Compile(template_str, options);

  this.render = function(data_dict, callback) {
    var context = _ScopedContext(data_dict, options.undefined_str);
    _Execute(program.Statements(), context, callback);
  };

  this.expand = function(data_dict) {
    var tokens = [];
    this.render(data_dict, function(x) { tokens.push(x); });
    return tokens.join('');
  };
};
}}}

Though the proper thing to do would be to make at least expand part of
Template's prototype. Even better if render is part of it and the
constructor is reduced to adding something like `this._program =
_Compile(template_str, options);`.

Original issue reported on code.google.com by [email protected] on 19 May 2009 at 4:46

sections could have formatters applied to them

As discussed here:

http://groups.google.com/group/json-template/browse_thread/thread/bc6a5ed3cdc0ef
0e#

I'm pretty close to doing this... I don't think it will complicate the
implementation too much.  Should finish all the other stuff first though.

Original issue reported on code.google.com by [email protected] on 30 Sep 2009 at 6:20

release this on pypi

I don't generally like to just copy files into my projects from SVN trunks.
I know it's just one file, but it'd be nice if this was released as a
package to pypi.

Original issue reported on code.google.com by [email protected] on 6 Apr 2009 at 2:44

Template.expand does not accept an encoding paramter

What steps will reproduce the problem?
1. Run the simple example:  jsontemplate.expand('Hello {name}', {'name':
'world'})

Results in:
>>> jsontemplate.expand('Hello {name}', {'name': 'world'})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "jsontemplate.py", line 658, in expand
    return t.expand(dictionary, encoding=encoding)
TypeError: expand() got an unexpected keyword argument 'encoding'


The module method expand passes an encoding param to the Template.expand
method, which does not define an encoding param in its signature.

What version of the product are you using? On what operating system?
MacOSX / (FreeBSD-like)
Python 2.5.1



Original issue reported on code.google.com by [email protected] on 30 Mar 2009 at 5:10

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.