import os
class DisplayHTMLRaw(object):
    def __init__(self, html=''):
        self.html = html
    def setRawHTML(self, html):
        self.html = html
    def _build(self, f, html):
        if html: f.write(html)
        
    def build(self, f):
        self._build(self.html)
class DisplayHTMLBlock(DisplayHTMLRaw):
    def __init__(self, title=''):
        super(DisplayHTMLBlock, self).__init__(html='')
        self.title = title
        self.cssclass = 'iwla_block'
        self.title_cssclass = 'iwla_block_title'
        self.value_cssclass = 'iwla_block_value'
    def getTitle(self):
        return self.title
    def setTitle(self, value):
        self.title = value
        
    def setCSSClass(self, cssclass):
        self.cssclass = cssclass
    def setTitleCSSClass(self, cssclass):
        self.title_cssclass = cssclass
    def setValueCSSClass(self, cssclass):
        self.value_cssclass = cssclass
    def build(self, f):
        html = '
' % (self.cssclass)
        if self.title:
            html += '
%s
' % (self.title_cssclass, self.title)
        html += '
%s
' % (self.value_cssclass, self.html)
        html += '
'
            html += ''
            for title in self.cols:
                html += '| %s' % (title)
            html += ' | 
'
            for row in self.rows:
                html += ''
                for v in row:
                    html += '| %s' % (v)
                html += ' | 
'
            html += '
'
            self.html = html
        super(DisplayHTMLBlockTable, self).build(f)
class DisplayHTMLPage(object):
    def __init__(self, title, filename):
        self.title = title
        self.filename = filename
        self.blocks = []
    def getFilename(self):
        return self.filename;
    def getBlock(self, title):
        for b in self.blocks:
            if title == b.getTitle():
                return b
        return None
    
    def appendBlock(self, block):
        self.blocks.append(block)
    def build(self, root):
        filename = root + self.filename
        base = os.path.dirname(filename)
        if not os.path.exists(base):
            os.makedirs(base)
        f = open(filename, 'w')
        f.write('')
        f.write('')
        f.write('')
        f.write('')
        if self.title:
            f.write('%s' % (self.title))
        f.write('')
        for block in self.blocks:
            block.build(f)
        f.write('