added ATGESCAPE command

This commit is contained in:
2015-03-24 14:14:16 +03:00
parent 18e184d6aa
commit f33237e712

View File

@@ -53,6 +53,8 @@ class TemplateV2(Template):
* [$Name$], where Name is the column header, * [$Name$], where Name is the column header,
will be replaced with value from the current row. will be replaced with value from the current row.
* [$ATGLINDEX$] will be replaced with the number of a current row. * [$ATGLINDEX$] will be replaced with the number of a current row.
* [$ATGESCAPE$name$] , where Name is the column header,
will be replaced with value from the current row, quotes and line endings will be escaped.
* [$ATGHEADER$Text$] and [$ATGFOOTER$Text$] will place the given text * [$ATGHEADER$Text$] and [$ATGFOOTER$Text$] will place the given text
at the begining or at the end of the file. You can't use other at the begining or at the end of the file. You can't use other
commands in this text. commands in this text.
@@ -219,6 +221,18 @@ class TemplateV2(Template):
return flow.replace(key,'') return flow.replace(key,'')
partCommands['ATGFOOTER'] = addFooter partCommands['ATGFOOTER'] = addFooter
def addEscape(index, flow, keytag):
if not keytag in self._data.keys:
self.warning('WARNING: keyword not found in table - %s' % (keytag))
return flow
string = unicode(self._data[keytag, index])
string = string.replace('\n', '\\n')
string = string.replace('"', '\\"')
string = string.replace('\\', '\\\\')
string = string.replace('\'', '\\\'')
return flow.replace('[$ATGESCAPE$%s$]' % (keytag), string)
partCommands['ATGESCAPE'] = addEscape
def addList(index, flow, string): def addList(index, flow, string):
key = '[$ATGLIST$%s$%s$]' % (string.split('$')[0], string[len(string.split('$')[0])+1:]) key = '[$ATGLIST$%s$%s$]' % (string.split('$')[0], string[len(string.split('$')[0])+1:])
sub = string[len(string.split('$')[0])+1:] sub = string[len(string.split('$')[0])+1:]