# Copyright (c) 2004-2005 LOGILAB S.A. (Paris, FRANCE). # http://www.logilab.fr/ -- mailto:contact@logilab.fr # # 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., # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. """HTML formatting drivers for ureports """ __revision__ = "$Id: html_writer.py,v 1.10 2006-03-08 09:47:29 katia Exp $" from cgi import escape from logilab.common.ureports import BaseWriter class HTMLWriter(BaseWriter): """format layouts as HTML""" def __init__(self, snipet=None): super(HTMLWriter, self).__init__(self) self.snipet = snipet def handle_attrs(self, layout): """get an attribute string from layout member attributes""" attrs = '' klass = getattr(layout, 'klass', None) if klass: attrs += ' class="%s"' % klass nid = getattr(layout, 'id', None) if nid: attrs += ' id="%s"' % nid return attrs def begin_format(self, layout): """begin to format a layout""" super(HTMLWriter, self).begin_format(layout) if self.snipet is None: self.writeln('') self.writeln('
') def end_format(self, layout): """finished to format a layout""" if self.snipet is None: self.writeln('') self.writeln('') def visit_section(self, layout): """display a section as html, using div + h[section level]""" self.section += 1 self.writeln('%s | ' % cell) else: self.writeln('%s | ' % cell) self.writeln('
---|
)""" self.write('
') self.format_children(layout) self.write('
') def visit_span(self, layout): """display links (using)""" self.write('' % self.handle_attrs(layout)) self.format_children(layout) self.write('') def visit_link(self, layout): """display links (using )""" self.write(' %s' % (layout.url, self.handle_attrs(layout), layout.label)) def visit_verbatimtext(self, layout): """display verbatim text (using
)""" self.write('') self.write(layout.data.replace('&', '&').replace('<', '<')) self.write('') def visit_text(self, layout): """add some text""" data = layout.data if layout.escaped: data = data.replace('&', '&').replace('<', '<') self.write(data)