##// END OF EJS Templates
Merge pull request #1934 from minrk/cellmd...
Merge pull request #1934 from minrk/cellmd Cell/Worksheet metadata * metadata dicts are attached to cells and worksheets * restores collapsed flag to the nbformat - this change happened in the refactor, and was undocumented, and possibly accidental. But we should either document it or fix it, and this includes a fix. * adds a new field, `nbformat_minor`, used to denote minor bumps of the notebook format that expose new capabilities but don't prevent loading by older clients. * Add a warning in Javascript if loading a multiworksheet notebook (which will exist in the future) as current JS code will only save the first. closes #1915

File last commit:

r6624:9d90e074
r7612:ca7d2a9c merge
Show More
ipy_render.py
67 lines | 1.6 KiB | text/x-python | PythonLexer
vivainio
crlf cleanup
r680 """ IPython extension: Render templates from variables and paste to clipbard """
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 from IPython.core import ipapi
vivainio
crlf cleanup
r680
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 ip = ipapi.get()
vivainio
crlf cleanup
r680
from string import Template
import sys,os
Thomas Kluyver
Remove bundled Itpl module.
r6624 # We no longer bundle Itpl. If you update this module, you should use advanced
# string formatting instead.
Brian Granger
Moved Itpl.py to deathrow as we already have a copy in external.
r2031 from IPython.external.Itpl import itplns
vivainio
crlf cleanup
r680
def toclip_w32(s):
""" Places contents of s to clipboard
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680 Needs pyvin32 to work:
http://sourceforge.net/projects/pywin32/
"""
import win32clipboard as cl
import win32con
cl.OpenClipboard()
cl.EmptyClipboard()
cl.SetClipboardText( s.replace('\n','\r\n' ))
cl.CloseClipboard()
try:
Bernardo B. Marques
remove all trailling spaces
r4872 import win32clipboard
vivainio
crlf cleanup
r680 toclip = toclip_w32
except ImportError:
def toclip(s): pass
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680
def render(tmpl):
""" Render a template (Itpl format) from ipython variables
Example:
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680 $ import ipy_render
$ my_name = 'Bob' # %store this for convenience
$ t_submission_form = "Submission report, author: $my_name" # %store also
$ render t_submission_form
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680 => returns "Submission report, author: Bob" and copies to clipboard on win32
# if template exist as a file, read it. Note: ;f hei vaan => f("hei vaan")
Bernardo B. Marques
remove all trailling spaces
r4872 $ ;render c:/templates/greeting.txt
vivainio
crlf cleanup
r680 Template examples (Ka-Ping Yee's Itpl library):
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680 Here is a $string.
Here is a $module.member.
Here is an $object.member.
Here is a $functioncall(with, arguments).
Here is an ${arbitrary + expression}.
Here is an $array[3] member.
Here is a $dictionary['member'].
"""
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680 if os.path.isfile(tmpl):
tmpl = open(tmpl).read()
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680 res = itplns(tmpl, ip.user_ns)
toclip(res)
return res
Brian Granger
Continuing a massive refactor of everything.
r2205 ip.push('render')