diff -r 7ab2293917f8 -r e44c04a89dbc UI/CodeDocumentationViewerTemplate.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UI/CodeDocumentationViewerTemplate.py Thu Oct 19 19:39:59 2017 +0200 @@ -0,0 +1,130 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2017 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing functions to prepare an HTML documentation view. +""" + +from __future__ import unicode_literals + +def prepareDocumentationViewerHtmlDocument(documentationInfo): + """ + Public function to prepare the HTML document. + + @param documentationInfo dictionary containing the various documentation + parts + @type dict + @return prepared HTML document + @rtype str + """ + mainTemplate = """ + <!DOCTYPE html> + <html> + <head> + <meta http-equiv="content-type" content="text/html; charset=utf-8"> + <link rel="stylesheet" href="qrc:documentViewerStyle.css" + type="text/css" /> + </head> + <body> + @HEADER@ + @DOCSTRING@ + </body> + </html> + """ + + headerTemplate = """ + @TITLE@ + @METADATA@ + """ + + titleTemplate = """ + <div class="title"><h1>@NAME@</h1></div> + """ + + metadataTemplate = """ + <div class="metadata"> + @ARGSPEC@ + @NOTE@ + </div> + """ + + argspecTemplate = """ + <p><b>Definition:</b> <span class="def">@NAME@@ARGSPEC@</span></p> + """ + + noteTemplate = """ + <p><b>Type:</b> @NOTE@</p> + """ + + docstringTemplate = """ + <div class="docstring"> + @DOCSTRING@ + </div> + """ + + name = documentationInfo["name"] + if name: + title = titleTemplate.replace("@NAME@", name) + if documentationInfo["argspec"] or documentationInfo["note"]: + if documentationInfo["argspec"]: + argspec = argspecTemplate\ + .replace("@NAME@", name)\ + .replace("@ARGSPEC@", documentationInfo["argspec"]) + else: + argspec = "" + if documentationInfo["note"]: + note = noteTemplate.replace("@NOTE@", + documentationInfo["note"]) + else: + note = "" + metaData = metadataTemplate\ + .replace("@ARGSPEC@", argspec)\ + .replace("@NOTE@", note) + else: + metaData = "" + + header = headerTemplate\ + .replace("@TITLE@", title)\ + .replace("@METADATA@", metaData) + else: + header = "" + + if documentationInfo["docstring"]: + docstring = documentationInfo["docstring"]\ + .replace("\r\n", "<br/>")\ + .replace("\n", "<br/>")\ + .replace("\r", "<br/>") + docstring = docstringTemplate.replace("@DOCSTRING@", docstring) + else: + docstring = "" + + return mainTemplate\ + .replace("@HEADER@", header)\ + .replace("@DOCSTRING@", docstring) + +def prepareDocumentationViewerHtmlWarningDocument(text): + """ + Public function to prepare a HTML warning document. + + @param text warning text to be shown + @type str + @return prepared HTML document + @rtype str + """ + mainTemplate = """ + <!DOCTYPE html> + <html> + <head> + <meta http-equiv="content-type" content="text/html; charset=utf-8"> + <link rel="stylesheet" href="qrc:documentViewerStyle.css" + type="text/css" /> + </head> + <body> + <div id="doc-warning">@TEXT@</div> + </body> + </html> + """ + + return mainTemplate.replace("@TEXT@", text)