Hi there,

NOTE: if you see references to key or index generation below, or path
generation, or reconstructing the json context based on javascript
note, be aware that's NOT what I've implemented! Please do not let
those ideas distract you to the point where can't review the actual
work I did. :)

On a branch here:

https://json-template.googlecode.com/svn/branches/faassen-hooks

I've implemented hooks for json-template (javascript). The code is
prototype only (it may work, but it has no automated tests, as I still
haven't figured out how to do this properly; it needs the ability to
pass in specific javascript functions into the options dictionary).

Here is the code for review:

http://codereview.appspot.com/67105/show

(this ignores a small patch I've made to pass 'options' to
ScopedContext instead of options.undefined_str, that's independent)

The idea is that during various phases of the expansion process, hook
functions are called. I've defined 5 of them:

* transformData: used to automatically transform incoming json data,
for instance by amending it with path information

* beforeSection, afterSection: called before and after a section are
entered and left. Can be used to log, or to insert content into the
output stream (call write).

* beforeRepeatedSection, afterRepeatedSection: called before and after
a repeat is taking place in a repeated section

By default, an empty set of hooks is passed in (emptyHooks); these do nothing.

Optionally a LoggingHooks can be passed in; this will write
information to a supplied log object. With more hooks, the entire
logging system could be made to work like this (and it would be easy
to disable logging, or log to something else, etc).

I've also supplied a MultiHooks; this demonstrates that you can pass
in multiple hooks at the same time, for instance you may want to do
logging and also do something else: Template({hooks:
MultiHooks([LoggingHooks(log), jsonIdHooks])})

What the hooks can generally be used for is:

* logging

* inserting extra data into the output for debugging (for instance
"<!-- section foo -->" into HTML output).

* insert ids into the HTML output automatically so that the place in a
JSON structure can be reconstructed. (for instance <div
style="display: none" class="json-id" id="foo.bar[3].baz" />) (not
generate these ids, this can be done using the transformation below).

* transforming data before it's passed in; this can be used to amend
the json with key and index information, for instance.

Since the hooks are bundled, the whole policy of inserting ids into
the HTML and generating those ids by data transformation can be
embedded into one object which can be passed into the expansion
process.

Regards,

Martijn

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JSON 
Template" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/json-template?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to