Package XPyTools :: Package codetpl
[hide private]
[frames] | no frames]

Package codetpl

source code

Package for enhance writing of source code.

List of package:

codetpl manual.

Provide functionality for code templates uses.

All templates saved into directory "./templates". You may save you templates in other dirictory that you like and add they paths into configuration file.

Conventions for templates name: typ_name.py, where By default defined next types:

Function's definition for template must like: "def ???_*(fields):", where "fields" - dict (for user enter values for fields), "???" - type of template, "*" - name of template.

Function's definition for keywords must like: "def kwd_*():", where "*" - name of keyword.

If function preffix is other or absent then this function is not interpreted as template or keyword.

Functions must return string or other objet which may be converted to string by operator str(). From returned string will be removed first and last newline characters. vIf returned string is empty then no result applying to source code.

Difference between templates and keywords is that keywords function string paste into code as is, other templates interpreted with using next rules.

Interpreter rules.

In string you may use follow templates:

First time template functions calls to get template for display user preview of you template, and pass empty fields=={}. You may change value of fields to take caller information about fields. If you do not change fields, then for fields value will be assigne it's names. Second time template-function will be called with entered fields dict as argument and you may use fields values that user entered or assigned by default. All fields are case insensitive, then parsing returned template.

String "# Your code" place into position for user input. All template's functions may have next attributes or other: Attributes must be written precendence function code into comment in next style: # metainfoname = value. Example:
   # language = python
   # category = Python
   # author = Mazhugin Aleksey

Predefined and known by pluggin in ./boa-pluggins/CodeTemplates.plug-in.py metainfonames is language and category.

For retrive source file path you must use codetpl_sourcefile global variable which auto appending into module dictionary.

If error occurs you may rise exception or return error description into template string. If you rise exception then exception type and text will be writed instead template.

Loads all finded and right files. Last templates override previous with same names.

Submodules [hide private]