Exemplo n.º 1
0
 def test_basic(self):
     html = "<html><head></head><body></body></html>"
     doc = HtmlDocument(html)
     
     self.assertEquals(doc.prefix, '')
     self.assertEquals(doc.head, '')
     self.assertEquals(doc.body, '')
     self.assertEqualsHtml(doc.assemble(), html)
Exemplo n.º 2
0
 def test_with_title(self):
     html = "<html><head><title>A Title</title></head><body></body></html>"
     doc = HtmlDocument(html)
     
     self.assertEquals(doc.prefix, '')
     self.assertEquals(doc.head, '<title>A Title</title>')
     self.assertEquals(doc.body, '')
     self.assertEqualsHtml(doc.assemble(), html)
Exemplo n.º 3
0
 def test_with_pi(self):
     html = "<?xml version='1.0'?><html><head></head><body></body></html>"
     #nlhtml = _put_htmldoc_newlines(html)
     doc = HtmlDocument(html)
     
     self.assertEquals(doc.prefix, "<?xml version='1.0'?>")
     self.assertEquals(doc.head, '')
     self.assertEquals(doc.body, '')
     self.assertEqualsHtml(doc.assemble(), html)
Exemplo n.º 4
0
 def test_nohtmlelem(self):
     html = "<head>The head.</head><body>The body.</body>"
     doc = HtmlDocument(html)
     
     self.assertEquals(doc.prefix, '')
     self.assertEquals(doc.head, 'The head.')
     self.assertEquals(doc.body, 'The body.')
     self.assertEqualsHtml(
             doc.assemble(), 
             "<html><head>The head.</head><body>The body.</body></html>")
Exemplo n.º 5
0
 def test_tagless(self):
     html = "Some content."
     doc = HtmlDocument(html)
     
     self.assertEquals(doc.prefix, '')
     self.assertEquals(doc.head, '')
     self.assertEquals(doc.body, 'Some content.')
     self.assertEqualsHtml(
             doc.assemble(), 
             "<html><head></head><body>Some content.</body></html>")
Exemplo n.º 6
0
 def test_with_bodycontent(self):
     html = "<html><head></head><body><h1>A heading.</h1>"
     html += "<p>A paragraph.</p></body></html>"
     #nlhtml = _put_htmldoc_newlines(html)
     doc = HtmlDocument(html)
     
     self.assertEquals(doc.prefix, '')
     self.assertEquals(doc.head, '')
     self.assertEquals(doc.body, '<h1>A heading.</h1><p>A paragraph.</p>')
     self.assertEqualsHtml(doc.assemble(), html)
Exemplo n.º 7
0
class HtmlEmailContent(EmailContent):
    """The text/html content of en email message."""
    
    def __init__(self, data):
        super(HtmlEmailContent, self).__init__()
        self.html = HtmlDocument(data)
        
    def compile(self):
        """Process the content as a Django template, returning the result."""
        r = self.process_template(self.docify())
        return r
        
    def add_header(self, header):
        """Adds the given data to the beginning of the body element's 
           content."""
        self.html.body = header + self.html.body
        
    def add_footer(self, footer):
        """Adds the given data to the end of the body element's content."""
        self.html.body = self.html.body + footer
        
    def add_pixel_image(self, imgtype='png'):
        """Adds a img tag referring to a 1x1 pixel image to the email.  It 
           assumes adding the tag to the beginning of the body element content 
           is safe.
           
           imgtype must be 'png' or 'gif'.
        """
        assert imgtype in ('png','gif')
        imgfmt = '''<img src="{{% track 'pixel' '{0}' %}}" '''
        imgfmt += '''height="1" width="1"/>'''
        imgtag = imgfmt.format(imgtype)
        self.html.body = imgtag + self.html.body
        
    def add_headcontent(self, content):
        """Appends the given data to the end of the head element's content."""
        self.html.head += content
        
    def docify(self):
        """Returns the content as HTML data."""
        return self.html.assemble()