##// END OF EJS Templates
switch ipy_render.py to use Itpl notation
vivainio -
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 """ places contents of s to clipboard
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 (as specified in string.Template docs) from ipython variables
35 """ Render a template (Itpl format) from ipython variables
32
36
33 Example:
37 Example:
34
38
@@ -38,11 +42,19 b' def render(tmpl):'
38 $ render t_submission_form
42 $ render t_submission_form
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
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)
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 (todo - add a better
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