3
""" IPython extension: Render templates from variables and paste to clipbard """
7
ip = IPython.ipapi.get()
9
from string import Template
12
from IPython.Itpl import itplns
15
""" Places contents of s to clipboard
17
Needs pyvin32 to work:
18
http://sourceforge.net/projects/pywin32/
20
import win32clipboard as cl
24
cl.SetClipboardText( s.replace('\n','\r\n' ))
35
""" Render a template (Itpl format) from ipython variables
40
$ my_name = 'Bob' # %store this for convenience
41
$ t_submission_form = "Submission report, author: $my_name" # %store also
42
$ render t_submission_form
44
=> returns "Submission report, author: Bob" and copies to clipboard on win32
46
# if template exist as a file, read it. Note: ;f hei vaan => f("hei vaan")
47
$ ;render c:/templates/greeting.txt
49
Template examples (Ka-Ping Yee's Itpl library):
52
Here is a $module.member.
53
Here is an $object.member.
54
Here is a $functioncall(with, arguments).
55
Here is an ${arbitrary + expression}.
56
Here is an $array[3] member.
57
Here is a $dictionary['member'].
60
if os.path.isfile(tmpl):
61
tmpl = open(tmpl).read()
63
res = itplns(tmpl, ip.user_ns)
67
ip.to_user_ns('render')
b'\\ No newline at end of file'