Ejemplo n.º 1
0
    def generate(self, writer, phase=None):

        if writer._useBraces:
            # send lines to be output by the braces generator
            bc = BraceConverter.BraceConverter()
            for line in string.splitfields(PSPUtils.removeQuotes(self.chars),
                                           '\n'):
                bc.parseLine(line, writer)
            return

        #check for whitespace at the beginning and if less than 2 spaces, remove
        if self.chars[:1] == ' ' and self.chars[:2] != '  ':
            self.chars = string.lstrip(self.chars)
        lines = string.splitfields(PSPUtils.removeQuotes(self.chars), '\n')
        #writer.printList(string.splitfields(PSPUtils.removeQuotes(self.chars),'\n'))

        #userIndent check
        if len(lines[-1]) > 0 and lines[-1][-1] == '$':
            lastline = lines[-1] = lines[-1][:-1]
            if lastline == '':
                lastline = lines[-2]  #handle endscript marker on its own line
            count = 0
            while lastline[count] in string.whitespace:
                count = count + 1
            userIndent = lastline[:count]
        else:
            userIndent = writer.EMPTY_STRING
            lastline = lines[-1]

        #print out code, (moved from above)
        writer._userIndent = writer.EMPTY_STRING  #reset to none
        writer.printList(lines)
        writer.printChars('\n')

        #check for a block
        #lastline = string.splitfields(PSPUtils.removeQuotes(self.chars),'\n')[-1]
        commentstart = string.find(lastline, '#')
        if commentstart > 0: lastline = lastline[:commentstart]
        blockcheck = string.rstrip(lastline)
        if len(blockcheck) > 0 and blockcheck[-1] == ':':
            writer.pushIndent()
            writer.println()
            writer._blockcount = writer._blockcount + 1
            #check for end of block, "pass" by itself
        if string.strip(self.chars) == 'pass' and writer._blockcount > 0:
            writer.popIndent()
            writer.println()
            writer._blockcount = writer._blockcount - 1

        #set userIndent for subsequent HTML
        writer._userIndent = userIndent
Ejemplo n.º 2
0
 def generate(self, writer, phase=None):
     self.chars = PSPUtils.normalizeIndentation(self.chars)
     if writer._useBraces:
         # Send lines to be output by the braces generator:
         bc = BraceConverter.BraceConverter()
         lines = PSPUtils.splitLines(PSPUtils.removeQuotes(self.chars))
         for line in lines:
             bc.parseLine(line, writer)
         return
     # Check for whitespace at the beginning and if less than 2 spaces, remove:
     if self.chars.startswith(' ') and not self.chars.startswith('  '):
         self.chars = self.chars.lstrip()
     lines = PSPUtils.splitLines(PSPUtils.removeQuotes(self.chars))
     if not lines:
         return  # ignore any empty tag
     # userIndent check
     if lines[-1].endswith('$'):
         lastline = lines[-1] = lines[-1][:-1]
         if not lastline:
             lastline = lines[-2]  # handle endscript marker on its own line
         count = 0
         while lastline[count].isspace():
             count += 1
         userIndent = lastline[:count]
     else:
         userIndent = writer._emptyString
         lastline = lines[-1]
     # Print out code (moved from above):
     writer._userIndent = writer._emptyString  # reset to none
     writer.printList(lines)
     writer.printChars('\n')
     # Check for a block:
     commentstart = lastline.find('#')  # @@ this fails if '#' part of string
     if commentstart >= 0:
         lastline = lastline[:commentstart]
     blockcheck = lastline.rstrip()
     if blockcheck.endswith(':'):
         writer.pushIndent()
         writer.println()
         writer._blockcount = writer._blockcount+1
         # Check for end of block, "pass" by itself:
     if self.chars.strip() == 'pass' and writer._blockcount > 0:
         writer.popIndent()
         writer.println()
         writer._blockcount -= 1
     # Set userIndent for subsequent HTML:
     writer._userIndent = userIndent
Ejemplo n.º 3
0
	def generate(self, writer, phase=None):
		writer.println('res.write(_formatter(' + PSPUtils.removeQuotes(self.chars) + '))')
Ejemplo n.º 4
0
	def generate(self, writer, phase=None):
		writer.pushIndent()
		writer.printList(PSPUtils.splitLines(PSPUtils.removeQuotes(self.chars)))
		writer.printChars('\n')
		writer.popIndent()
Ejemplo n.º 5
0
	def generate(self, writer, phase=None):
		writer.println('# Class level user code\n')
		pySrc = PSPUtils.normalizeIndentation(self.chars, writer._indent)
		pySrc = PSPUtils.splitLines(PSPUtils.removeQuotes(pySrc))
		writer.printList(pySrc)
Ejemplo n.º 6
0
 def generate(self, writer, phase=None):
     writer.println('res.write(_formatter(' +
                    PSPUtils.removeQuotes(self.chars) + '))')
Ejemplo n.º 7
0
 def generate(self, writer, phase=None):
     writer.pushIndent()
     writer.printList(
         string.splitfields(PSPUtils.removeQuotes(self.chars), '\n'))
     writer.printChars('\n')
     writer.popIndent()