[IPython-dev] Template cells

Nicholas Bollweg nick.bollweg at gmail.com
Sat Dec 15 15:56:30 EST 2012


JS templating:
Mustache.js is pretty darn popular, as are its clones. dust.js is worth a
look, as it is already ready for the kind of "zippy" stuff that 0mq can
do... there's a lot of good competition in the space right now, so people
are actually competing on performance, usability and features :)

A use case:
I had previously done some work with implementing a tangle.js (
http://worrydream.com/Tangle/) markdown extension (
https://github.com/bollwyvl/TangleDown). I ended up doing all the parsing
in py, which was not A Good Idea, as it turns out... whereas doing the
heavy duty constrain solving to get bidirectional stuff didn't work very
well in JS. Bad choice of tools, i guess.

I'd like to replace (to the extent possible) all of the javascript exec'd
stuff with bindings to kernel values, while keeping all of the constraint
logic in the backend: thus, I'd like user modifications to the front end to
be bound into execution requests to re-update the front-end without
rerendering the whole template.

This goes a little beyond what you are proposing, but there may be some
common ground.

A low-risk implementation:
Based on the stuff i am working on right now, it could look something like
this:
- store the templated markdown in a degenerate code cell:

    %load_ext tmplmd
    display(TemplatedMarkdown(""), context={})

- enable an input widget, something being discussed on the custom cells
thread... it could be hacked in already with an output handler... but i
digress. Anyhow, somehow show a UI that generates normal python code... in
this case, you'd update the arguments to TemplatedMarkdown, so it becomes:

    display(TemplatedMarkdown("""
    # {{title}}

    {{ for result in results }}
      - {{ result }}
    {{ endfor }}""",
    context=dict(title=foo, results=[bar, baz]))

- on the python side (where you use load_ipython_extension, see brian's
example in
https://github.com/ipython/jsplugins/blob/master/d3graph/d3graph.py)
implement a formatter that returns something like:
    {
        "template": <the template>,
        "context": {
            "title": foo,
            "results": ["foo", "bar"]
        },
        "handler": "tmplmd"
    }
- and then let the client take over to actually render it.

the ipynb just knows there is some code, and the text would stay mostly
human readable and editable for other consumers.


On Sat, Dec 15, 2012 at 3:52 PM, Matthias BUSSONNIER <
bussonniermatthias at gmail.com> wrote:

>
> Le 15 déc. 2012 à 21:31, Carl Smith a écrit :
>
> > I'm not sure if you guys have seen this, but there's a Python Markdown
> > project that might be useful here.
>
> And this MD implementation is what nbconvert/nbviewer uses.
>
> Thanks for pointing this though.
> --
> Matthias
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20121215/9a7db74d/attachment.html>


More information about the IPython-dev mailing list