Show More
@@ -1,5 +1,7 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | |
|
3 | """ IPython extension: Render templates from variables and paste to clipbard """ | |
|
4 | ||
|
3 | 5 | import IPython.ipapi |
|
4 | 6 | |
|
5 | 7 | ip = IPython.ipapi.get() |
@@ -7,8 +9,10 b' ip = IPython.ipapi.get()' | |||
|
7 | 9 | from string import Template |
|
8 | 10 | import sys |
|
9 | 11 | |
|
12 | from IPython.Itpl import itplns | |
|
13 | ||
|
10 | 14 | def toclip_w32(s): |
|
11 |
""" |
|
|
15 | """ Places contents of s to clipboard | |
|
12 | 16 | |
|
13 | 17 | Needs pyvin32 to work: |
|
14 | 18 | http://sourceforge.net/projects/pywin32/ |
@@ -28,7 +32,7 b' except ImportError:' | |||
|
28 | 32 | |
|
29 | 33 | |
|
30 | 34 | def render(tmpl): |
|
31 |
""" Render a template ( |
|
|
35 | """ Render a template (Itpl format) from ipython variables | |
|
32 | 36 | |
|
33 | 37 | Example: |
|
34 | 38 | |
@@ -38,11 +42,19 b' def render(tmpl):' | |||
|
38 | 42 | $ render t_submission_form |
|
39 | 43 | |
|
40 | 44 | => returns "Submission report, author: Bob" and copies to clipboard on win32 |
|
45 | ||
|
46 | Template examples (Ka-Ping Yee's Itpl library): | |
|
41 | 47 | |
|
48 | Here is a $string. | |
|
49 | Here is a $module.member. | |
|
50 | Here is an $object.member. | |
|
51 | Here is a $functioncall(with, arguments). | |
|
52 | Here is an ${arbitrary + expression}. | |
|
53 | Here is an $array[3] member. | |
|
54 | Here is a $dictionary['member']. | |
|
42 | 55 | """ |
|
43 | 56 | |
|
44 | s = Template(tmpl) | |
|
45 | res = s.substitute(ip.user_ns) | |
|
57 | res = itplns(tmpl, ip.user_ns) | |
|
46 | 58 | toclip(res) |
|
47 | 59 | return res |
|
48 | 60 |
@@ -1,8 +1,8 b'' | |||
|
1 | 1 | 2007-04-20 Ville Vainio <vivainio@gmail.com> |
|
2 | 2 | |
|
3 | 3 | * Extensions/ipy_render.py: added extension for easy |
|
4 |
interactive text template rendering (to |
|
|
5 | renderer than string.Template) | |
|
4 | interactive text template rendering (to clipboard). Uses Ka-Ping Yee's | |
|
5 | 'Iptl' template notation, | |
|
6 | 6 | |
|
7 | 7 | * Extensions/ipy_completers.py: introduced Olivier Lauzanne's |
|
8 | 8 | safer & faster 'import' completer. |
General Comments 0
You need to be logged in to leave comments.
Login now