Beispiel #1
0
def render(tmpl):
    """ Render a template (Itpl format) from ipython variables

    Example:
    
    $ import ipy_render
    $ my_name = 'Bob'  # %store this for convenience
    $ t_submission_form = "Submission report, author: $my_name"  # %store also
    $ render t_submission_form
    
    => 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")
    $ ;render c:/templates/greeting.txt  
    
    Template examples (Ka-Ping Yee's Itpl library):
    
    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'].
    """
    
    if os.path.isfile(tmpl):
        tmpl = open(tmpl).read()
        
    res = itplns(tmpl, ip.user_ns)
    toclip(res)
    return res
Beispiel #2
0
def render(tmpl):
    """ Render a template (Itpl format) from ipython variables

    Example:

    $ import ipy_render
    $ my_name = 'Bob'  # %store this for convenience
    $ t_submission_form = "Submission report, author: $my_name"  # %store also
    $ render t_submission_form

    => 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")
    $ ;render c:/templates/greeting.txt

    Template examples (Ka-Ping Yee's Itpl library):

    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'].
    """

    if os.path.isfile(tmpl):
        tmpl = open(tmpl).read()

    res = itplns(tmpl, ip.user_ns)
    toclip(res)
    return res
Beispiel #3
0
 def call_editor(self, file, line=0):
     if line is None:
         line = 0
     cmd = itplns(run_template, locals())
     print ">",cmd
     if os.system(cmd) != 0:
         raise TryNext()
     if wait:
         raw_input("Press Enter when done editing:")
Beispiel #4
0
 def call_editor(self, file, line=0):
     if line is None:
         line = 0
     cmd = itplns(run_template, locals())
     print ">",cmd
     if os.system(cmd) != 0:
         raise TryNext()
     if wait:
         raw_input("Press Enter when done editing:")