On Thu, May 21, 2009 at 4:42 AM, Martijn Faassen <[email protected]> wrote: > > Hi there, > > On Thu, May 21, 2009 at 9:28 AM, Andy Chu <[email protected]> wrote: >> Hm, can this be done by modifying the data dictionary? I think that >> was my original suggestion. Like: >> >> def AddPathInfo(data_dict): >> for each compound object: >> AddPathInfo(...) # recursively > > Sure, that's an alternative way to generate the paths and might in > fact be prettier. I hooked it into ScopedContext as that seemed a > fairly natural fit, but this would work just fine as well. > > The important new insight I had however are about the hook points and > a way to make this work completely transparently without requiring > anyone to modify their templates (as long as some easy structural > constraints concerning HTML generation are followed). I propose a > beforeSection and beforeRepeatedSection hook point. Perhaps we also > need the after* equivalent, and I'm not sure I got everything right > concerning alternates and or and so on, so a review would be > appreciated. I also want to be able to *test* these hooks. > >> Actually the other bug about Template not being prototypable is >> relevant here. > > Yes, that would allow the data dictionary modification to be > implemented fairly cleanly, though an alternative would be to insert a > similar hook to pre-process the JSON structure. > > Subclassing won't help though with _DoSection and _DoRepeatedSection, > where I need to pass in my hooks. See the patch. > >> I think this would fit well in an add-on module, and I >> was thinking about adding it but never got around to it. There are a >> few things like this that you might want to do with the data >> dictionary. > > Yes, that would be useful, and it could contain the path resolution > mechanism as well, along with functionality that finds the <div /> > marker in HTML and the hooks that automatically insert it. > > My concrete questions: > > * please review the hooks. Ignore the path story for now, I just want > hooks to insert into the stream whenever any {.command} changes the > scope (or when one leaves a scope with {.end}, though this is less > important).
So the problem with the hooks is that I don't see any use case for them that can't be addressed in a way that doesn't modify the core code. Putting them in the core code basically generates TODOs for all the other implementations, which is sometimes acceptable, but in this case I don't see enough reasons yet. The philosophy is to keep things out of the core unless they can't be done any other way. Can you think of any other examples where the hooks are useful? And why not after hooks? Why not a hook before starting all of template expansion and ending it? And a hook where 'alternates' is used? I can't judge the hooks in the absence of real problems. Also, it's probably not clear from the code, but the builder interface isn't meant to be public -- i.e. it could change over time incompatibly (and it fact it already did when I added the dotted lookup). I will write a warning about this in the code. I think it's kind of a "use at your own risk" feature. It was basically meant as a hook for compiling templates directly to say JavaScript or C, but I never got around to implementing that (although I would still like to explore that area, I haven't had a need). The interface isn't a real one because it only has one implementation (which means it is likely wrong in general) > * how would I set up the javascript tests to set up with hooks? I don't see a good way to test in a language-independent way, because it's a feature that depends on passing callbacks, sort of like the formatters. Andy --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
