shushanxingzhe / json-template Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/json-template
Automatically exported from code.google.com/p/json-template
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
Probably a few more things
Original issue reported on code.google.com by [email protected]
on 14 Nov 2009 at 8:41
This is useful for single file releases.
SVN did this; Mercurial is a little fiddly. Better if it's in the release
process.
Original issue reported on code.google.com by [email protected]
on 19 Nov 2009 at 4:38
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
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
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
Files are byte streams by definition, so textual data needs an encoding.
FromString should probably either accept unicode() or str()
Original issue reported on code.google.com by [email protected]
on 6 May 2009 at 6:13
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
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
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
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
Maybe to chubot.org
Original issue reported on code.google.com by [email protected]
on 17 Apr 2009 at 3:56
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
In particular the 'json' and 'template-file' ones. Those are useful
features, so everyone shouldn't have to set them up manually.
Original issue reported on code.google.com by [email protected]
on 6 Jun 2009 at 6:42
This is a lot more common than CapWords and matches JS's own identifiers.
Original issue reported on code.google.com by [email protected]
on 21 Oct 2009 at 4:42
The JS version is not reentrant -- thus impossible to have templates
include other templates. Things like the stack, which while hidden in a
module pattern, is still a global to the functions.
Original issue reported on code.google.com by sroussey
on 15 Sep 2009 at 2:15
$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:
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
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
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
Simple rule:
Any line which has something like {.<anything>} by itself is stripped of
whitespace.
This will allow tightening up the tests.
Original issue reported on code.google.com by [email protected]
on 15 Oct 2009 at 5:25
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
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
And take this opportunity to rename
more_predicates -> predicates
with an alias
Original issue reported on code.google.com by [email protected]
on 31 Dec 2009 at 7:21
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
- For compressing all whitespace
- For preserving indentation
- default: do nothing
Original issue reported on code.google.com by [email protected]
on 8 Mar 2009 at 5:24
Templates can include themselves, which is useful for formatting recursive
structures like trees.
Original issue reported on code.google.com by [email protected]
on 25 Sep 2009 at 5:17
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:
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
From group:
"""
Although since there are 3 methods in Python that expand, it might be
better to use a keyword argument, like "t.expand(dictionary, default='')"
If default=None, then an exception is raised.
"""
In Java this can just use method overloading.
Original issue reported on code.google.com by [email protected]
on 15 Apr 2009 at 4:17
It uses too many top-level variables now. Need to figure out a decent
pattern for doing this.
Original issue reported on code.google.com by [email protected]
on 8 Mar 2009 at 10:02
There are a few use cases for this, like generating code and command line
arguments.
Original issue reported on code.google.com by [email protected]
on 30 Sep 2009 at 6:04
Repro here:
http://groups.google.com/group/json-template/browse_thread/thread/59293390cbca63
28?hl=en
Original issue reported on code.google.com by [email protected]
on 19 Nov 2009 at 4:22
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
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
The lookup for 'foo' looks up the stack. Subsequent lookups for bar and
baz are "simple".
Original issue reported on code.google.com by [email protected]
on 30 Apr 2009 at 6:28
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
Get rid of makedocs.py BS
Add better navigation in the layout, perhaps
Original issue reported on code.google.com by [email protected]
on 19 Nov 2009 at 4:52
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
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
The if and ? are redundant.
It should be just
{.foo?}
or
{.if foo}
Original issue reported on code.google.com by [email protected]
on 31 Dec 2009 at 7:21
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
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
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
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
Should return undefined / None
This is easier to deal with in formatters/predicates rather than try/catch
Original issue reported on code.google.com by [email protected]
on 15 Oct 2009 at 5:27
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
This is essentially promoting ScopedContext to a public API. It already is
sort of public, since you get use context.get() in formatters/predicates.
This may be necessary for PB support in issue 41.
Original issue reported on code.google.com by [email protected]
on 14 Nov 2009 at 9:05
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
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.