UI/CodeDocumentationViewerTemplate.py

changeset 5914
e44c04a89dbc
child 5919
d0de2b378b24
equal deleted inserted replaced
5913:7ab2293917f8 5914:e44c04a89dbc
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2017 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing functions to prepare an HTML documentation view.
8 """
9
10 from __future__ import unicode_literals
11
12 def prepareDocumentationViewerHtmlDocument(documentationInfo):
13 """
14 Public function to prepare the HTML document.
15
16 @param documentationInfo dictionary containing the various documentation
17 parts
18 @type dict
19 @return prepared HTML document
20 @rtype str
21 """
22 mainTemplate = """
23 <!DOCTYPE html>
24 <html>
25 <head>
26 <meta http-equiv="content-type" content="text/html; charset=utf-8">
27 <link rel="stylesheet" href="qrc:documentViewerStyle.css"
28 type="text/css" />
29 </head>
30 <body>
31 @HEADER@
32 @DOCSTRING@
33 </body>
34 </html>
35 """
36
37 headerTemplate = """
38 @TITLE@
39 @METADATA@
40 """
41
42 titleTemplate = """
43 <div class="title"><h1>@NAME@</h1></div>
44 """
45
46 metadataTemplate = """
47 <div class="metadata">
48 @ARGSPEC@
49 @NOTE@
50 </div>
51 """
52
53 argspecTemplate = """
54 <p><b>Definition:</b> <span class="def">@NAME@@ARGSPEC@</span></p>
55 """
56
57 noteTemplate = """
58 <p><b>Type:</b> @NOTE@</p>
59 """
60
61 docstringTemplate = """
62 <div class="docstring">
63 @DOCSTRING@
64 </div>
65 """
66
67 name = documentationInfo["name"]
68 if name:
69 title = titleTemplate.replace("@NAME@", name)
70 if documentationInfo["argspec"] or documentationInfo["note"]:
71 if documentationInfo["argspec"]:
72 argspec = argspecTemplate\
73 .replace("@NAME@", name)\
74 .replace("@ARGSPEC@", documentationInfo["argspec"])
75 else:
76 argspec = ""
77 if documentationInfo["note"]:
78 note = noteTemplate.replace("@NOTE@",
79 documentationInfo["note"])
80 else:
81 note = ""
82 metaData = metadataTemplate\
83 .replace("@ARGSPEC@", argspec)\
84 .replace("@NOTE@", note)
85 else:
86 metaData = ""
87
88 header = headerTemplate\
89 .replace("@TITLE@", title)\
90 .replace("@METADATA@", metaData)
91 else:
92 header = ""
93
94 if documentationInfo["docstring"]:
95 docstring = documentationInfo["docstring"]\
96 .replace("\r\n", "<br/>")\
97 .replace("\n", "<br/>")\
98 .replace("\r", "<br/>")
99 docstring = docstringTemplate.replace("@DOCSTRING@", docstring)
100 else:
101 docstring = ""
102
103 return mainTemplate\
104 .replace("@HEADER@", header)\
105 .replace("@DOCSTRING@", docstring)
106
107 def prepareDocumentationViewerHtmlWarningDocument(text):
108 """
109 Public function to prepare a HTML warning document.
110
111 @param text warning text to be shown
112 @type str
113 @return prepared HTML document
114 @rtype str
115 """
116 mainTemplate = """
117 <!DOCTYPE html>
118 <html>
119 <head>
120 <meta http-equiv="content-type" content="text/html; charset=utf-8">
121 <link rel="stylesheet" href="qrc:documentViewerStyle.css"
122 type="text/css" />
123 </head>
124 <body>
125 <div id="doc-warning">@TEXT@</div>
126 </body>
127 </html>
128 """
129
130 return mainTemplate.replace("@TEXT@", text)

eric ide

mercurial