Changeset 5

Show
Ignore:
Timestamp:
Tue May 10 07:59:16 2005
Author:
rdelon
Message:
Files:

Legend:

Unmodified
Added
Removed
Modified
  • trunk/cherrytemplate/cherrytemplate.py

    r4 r5  
    167 167         for line in execStr.split('\n'):  
    168 168             if line.split():  
      169                 sLine = line.strip()  
    169 170                 indentCount = _firstNonSpace(line)  
    170 171                 lastIndent = indentCount  
    171                   if line.strip()[-1] == ':':  
      172                 if sLine[-1] == ':':  
    171 172                     lastIndent += 4  
    172                   if indentCount < minIndent: minIndent=indentCount  
      173                 if indentCount < minIndent:  
      174                     minIndent = indentCount  
    173 175                 lines.append(line)  
    174 176         if minIndent==1000: minIndent=0  
     
    178 180         _writeTemplate(f, template[:minI], tab)  
    179 181         lastLineIndent = ''  
    180           for line in lines:  
    181               # Remove "minIndent" tabs and add "tab" tabs from each line  
    182               sLine = line.strip()  
      182         isEnd = False  
      183         if len(lines) == 1:  
      184             sLine = lines[0].strip()  
    183 185             if sLine.startswith('# end') or sLine.startswith('#end'):  
      186                 isEnd = True  
    184 187                 tab = tab[4:]  
    185                   continue  
    186               f.write(tab+line[minIndent:]+'\n')  
      188         if not isEnd:  
      189             for line in lines:  
      190                 f.write(tab + line[minIndent:] + '\n')  
    187 191         _writeTemplate(f, template[j+2:], tab + ' ' * lastIndent)  
    188 192         return  
     
    439 443  
    440 444 def renderTemplate(template = '', file = None, inputEncoding = None, outputEncoding = None, outputEncodingErrors = None, returnGenerator = None, glob = None, loc = None):  
      445     print "* Rendering:", file  
    441 446     if loc is None:  
    442 447         loc = inspect.currentframe(1).f_locals  
     
    452 457     _writeTemplate(f, template, '    ')  
    453 458     template = f.getvalue()  
    454       # print "*** template:", template  
    455       # print "*** END TEMPLATE"  
      459     print "*** template:", template  
      460     print "*** END TEMPLATE"  
    456 461      
    457 462     g = glob.copy() # make a copy because we don't want to avoid changing original global scope.