[px] Added the possibility to have several PX actions in the same XHTML tag. If several PX action are defined, they are evaluated in this order: var, for, if.
This commit is contained in:
parent
1bc2a2f890
commit
5ece5c9831
6 changed files with 257 additions and 19 deletions
|
@ -48,6 +48,9 @@ class BufferAction:
|
|||
self.fromExpr = fromExpr
|
||||
# When an error occurs, must we raise it or write it into the buffer?
|
||||
self.raiseErrors = not self.buffer.pod
|
||||
# Several actions may co-exist for the same buffer, as a chain of
|
||||
# BufferAction instances, defined via the following attribute.
|
||||
self.subAction = None
|
||||
|
||||
def getExceptionLine(self, e):
|
||||
'''Gets the line describing exception p_e, containing the pathname of
|
||||
|
@ -120,6 +123,13 @@ class BufferAction:
|
|||
if not error:
|
||||
result.write(feRes)
|
||||
|
||||
def addSubAction(self, action):
|
||||
'''Adds p_action as a sub-action of this action.'''
|
||||
if not self.subAction:
|
||||
self.subAction = action
|
||||
else:
|
||||
self.subAction.addSubAction(action)
|
||||
|
||||
class IfAction(BufferAction):
|
||||
'''Action that determines if we must include the content of the buffer in
|
||||
the result or not.'''
|
||||
|
@ -227,7 +237,12 @@ class ForAction(BufferAction):
|
|||
result.dumpEndElement(Row.OD.elem)
|
||||
result.dumpStartElement(Row.OD.elem, rowAttributes)
|
||||
currentColIndex = 0
|
||||
self.evaluateBuffer(result, context)
|
||||
# If a sub-action is defined, execute it.
|
||||
if self.subAction:
|
||||
self.subAction.execute(result, context)
|
||||
else:
|
||||
# Evaluate the buffer directly.
|
||||
self.evaluateBuffer(result, context)
|
||||
# Cell: increment the current column index
|
||||
if isCell:
|
||||
currentColIndex += 1
|
||||
|
@ -307,8 +322,12 @@ class VariablesAction(BufferAction):
|
|||
hidden[name] = context[name]
|
||||
# Store the result into the context
|
||||
context[name] = vRes
|
||||
# Evaluate the buffer
|
||||
self.evaluateBuffer(result, context)
|
||||
# If a sub-action is defined, execute it.
|
||||
if self.subAction:
|
||||
self.subAction.execute(result, context)
|
||||
else:
|
||||
# Evaluate the buffer directly.
|
||||
self.evaluateBuffer(result, context)
|
||||
# Restore hidden variables if any
|
||||
if hidden: context.update(hidden)
|
||||
# Delete not-hidden variables
|
||||
|
|
|
@ -471,6 +471,9 @@ class MemoryBuffer(Buffer):
|
|||
return res
|
||||
|
||||
def createPxAction(self, elem, actionType, statement):
|
||||
'''Creates a PX action and link it to this buffer. If an action is
|
||||
already linked to this buffer (in self.action), this action is
|
||||
chained behind the last action via self.action.subAction.'''
|
||||
res = 0
|
||||
statement = statement.strip()
|
||||
if actionType == 'for':
|
||||
|
@ -478,15 +481,19 @@ class MemoryBuffer(Buffer):
|
|||
if not forRes:
|
||||
raise ParsingError(BAD_FOR_EXPRESSION % statement)
|
||||
iter, subExpr = forRes.groups()
|
||||
self.action = ForAction('for', self, subExpr, elem, False, iter,
|
||||
'buffer', None)
|
||||
action = ForAction('for', self, subExpr, elem, False, iter,
|
||||
'buffer', None)
|
||||
elif actionType == 'if':
|
||||
self.action = IfAction('if', self, statement, elem, False,
|
||||
'buffer', None)
|
||||
action= IfAction('if', self, statement, elem, False, 'buffer', None)
|
||||
elif actionType == 'var':
|
||||
variables = self._getVariables(statement)
|
||||
self.action = VariablesAction('var', self, elem, False, variables,
|
||||
'buffer', None)
|
||||
action = VariablesAction('var', self, elem, False, variables,
|
||||
'buffer', None)
|
||||
# Is it the first action for this buffer or not?
|
||||
if not self.action:
|
||||
self.action = action
|
||||
else:
|
||||
self.action.addSubAction(action)
|
||||
return res
|
||||
|
||||
def cut(self, index, keepFirstPart):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue