#!/usr/bin/python # # genshitest - A Hello World python program for the Genshi templating tools # Copyright 2012 NC State University # Written by Jack Neely # # SDG # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. from genshi.template import NewTextTemplate class fooClass(object): def __init__(self): self.table = range(0, 11) self.row = 3 def __str__(self): return str(self.table[self.row]) def allValues(self): for i in range(0, len(self.table)): f = fooClass() f.row = i yield f def reset(self): self.row = 0 tmpl = NewTextTemplate("""Hello World! {% for i in items.allValues() %}\ $i {% end %}""") print "Example via Python:" print "Hello World!" for i in fooClass().allValues(): print i print "Example via Genshi Text Template:" stream = tmpl.generate(items=fooClass()) print stream.render()