Coverage for khufu/scaffolding/htmlDocument.py : 75%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# encoding: utf-8
2from . import *
4def htmlDocument(
5 contentType=False,
6 content='',
7 attachmentSaveAsName=False):
8 """
9 *The doctype and html tags*
11 **Key Arguments**
13 - ``content`` -- the head and body of the html page
14 - ``attachmentSaveAsName`` -- save file as this name instead of opening in browser
17 **Return**
19 - ``contentType`` -- the content type [ "text/html" ]
20 - ``doctype`` -- the HTML5 doctype
22 """
24 if attachmentSaveAsName is not False:
25 contentType = """Content-Disposition: attachment; filename=%(attachmentSaveAsName)s""" % locals(
26 )
27 elif not contentType:
28 contentType = ""
29 else:
30 contentType = "Content-type: %(contentType)s" % locals()
32 content = content.strip()
34 if "text/plain" in contentType or "text/csv" in contentType or attachmentSaveAsName is not False:
35 htmlDocument = \
36 """%(contentType)s\n
37%(content)s
38""" % locals()
39 else:
40 htmlDocument = \
41 """%(contentType)s\n
42 <!DOCTYPE html>
43 <html lang="en">
44 %(content)s
45 </html>
46 """ \
47 % locals()
48 return htmlDocument.strip()