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