PocoDoc - merge changes from macchina.io to allow for insertion of custom HTML into generated pages

This commit is contained in:
Günter Obiltschnig 2021-03-02 12:08:28 +01:00
parent 3e0c80d8a8
commit 5ce9685613
9 changed files with 90 additions and 29 deletions

View File

@ -47,7 +47,8 @@
<charset>utf-8</charset>
<software>POCO C++ Libraries</software>
<company>Applied Informatics Software Engineering GmbH and Contributors</company>
<companyURI>http://pocoproject.org/</companyURI>
<companyURI>https://pocoproject.org/
</companyURI>
</PocoDoc>
<Translations>
<EN>

View File

@ -7,6 +7,7 @@
<meta name="generator" content="PocoDoc"/>
<link rel="stylesheet" href="css/styles.css" type="text/css"/>
<script type="text/javascript" src="js/iframeResizer.min.js"></script>
${PocoDoc.customHeadHTML}
</head>
<body>
<div class="header">
@ -28,5 +29,6 @@ ${PocoDoc.nameSpaceIndex}
Copyright &copy; ${PocoDoc.year}, <a href="${PocoDoc.companyURI}" target="_top">${PocoDoc.company}</a></p>
</div>
</div>
${PocoDoc.customBodyHTML}
</body>
</html>

View File

@ -135,7 +135,7 @@ void DocWriter::writeNavigation()
std::string path(pathFor("navigation.html"));
std::ofstream ostr(path.c_str());
if (!ostr.good()) throw Poco::CreateFileException(path);
writeHeader(ostr, tr("Navigation"), "js/iframeResizer.contentWindow.min.js");
writeHeader(ostr, tr("Navigation"), "js/iframeResizer.contentWindow.min.js", NO_CUSTOM_HTML);
beginBody(ostr);
ostr << "<h3 class=\"overview\"><a href=\"index.html\" target=\"_top\">" << htmlize(software) << "</a></h3>\n";
@ -208,7 +208,7 @@ void DocWriter::writeNavigation()
ostr << "<div>&nbsp;</div>\n"; // workaround to avoid cutting off a few pixels from last line
endBody(ostr);
ostr << "<script>CollapsibleLists.apply(true)</script>" << std::endl;
writeFooter(ostr);
writeFooter(ostr, NO_TRACKING | NO_CUSTOM_HTML);
}
@ -627,7 +627,7 @@ std::string DocWriter::makeFileName(const std::string& str)
}
void DocWriter::writeHeader(std::ostream& ostr, const std::string& title, const std::string& extraScript)
void DocWriter::writeHeader(std::ostream& ostr, const std::string& title, const std::string& extraScript, int options)
{
Application& app = Application::instance();
std::string company(app.config().getString("PocoDoc.company", "Applied Informatics"));
@ -651,6 +651,10 @@ void DocWriter::writeHeader(std::ostream& ostr, const std::string& title, const
ostr << "<script type=\"text/javascript\" src=\"" << extraScript << "\"></script>" << std::endl;
}
ostr << "<script type=\"text/javascript\" src=\"js/CollapsibleLists.compressed.js\"></script>" << std::endl;
if ((options & NO_CUSTOM_HTML) == 0)
{
ostr << app.config().getString("PocoDoc.customHeadHTML", "");
}
ostr << "</head>" << std::endl;
ostr << "<body";
if (_prettifyCode)
@ -659,11 +663,20 @@ void DocWriter::writeHeader(std::ostream& ostr, const std::string& title, const
}
void DocWriter::writeFooter(std::ostream& ostr)
void DocWriter::writeFooter(std::ostream& ostr, int options)
{
Application& app = Application::instance();
std::string googleAnalyticsCode(app.config().getString("PocoDoc.googleAnalyticsCode", ""));
ostr << googleAnalyticsCode;
if ((options & NO_TRACKING) == 0)
{
std::string googleAnalyticsCode(app.config().getString("PocoDoc.googleAnalyticsCode", ""));
ostr << googleAnalyticsCode;
std::string hubSpotCode(app.config().getString("PocoDoc.hubSpotCode", ""));
ostr << hubSpotCode;
}
if ((options & NO_CUSTOM_HTML) == 0)
{
ostr << app.config().getString("PocoDoc.customBodyHTML", "");
}
ostr << "</body>" << std::endl;
ostr << "</html>" << std::endl;
}
@ -674,8 +687,8 @@ void DocWriter::writeCopyright(std::ostream& ostr)
Application& app = Application::instance();
std::string software(app.config().getString("PocoDoc.software", ""));
std::string version(app.config().getString("PocoDoc.version", ""));
std::string company(app.config().getString("PocoDoc.company", "Applied Informatics"));
std::string companyURI(app.config().getString("PocoDoc.companyURI", "http://www.appinf.com/"));
std::string company(app.config().getString("PocoDoc.company", "Applied Informatics Software Engineering GmbH"));
std::string companyURI(app.config().getString("PocoDoc.companyURI", "https://macchina.io/"));
std::string licenseURI(app.config().getString("PocoDoc.licenseURI", ""));
DateTime now;
ostr << "<p class=\"footer\">";
@ -1286,7 +1299,7 @@ bool DocWriter::writeSpecial(std::ostream& ostr, std::string& token, std::string
{
_htmlMode = false;
}
else if (token == "<?")
else if (token == "<?" || token == "<?=")
{
std::string prop;
nextToken(begin, end, token);
@ -1299,6 +1312,19 @@ bool DocWriter::writeSpecial(std::ostream& ostr, std::string& token, std::string
Application& app = Application::instance();
ostr << htmlize(app.config().getString(prop, std::string("NOT FOUND: ") + prop));
}
else if (token == "<?-")
{
std::string prop;
nextToken(begin, end, token);
while (!token.empty() && token != "?>")
{
prop.append(token);
nextToken(begin, end, token);
}
Poco::trimInPlace(prop);
Application& app = Application::instance();
ostr << app.config().getString(prop, "");
}
else if (_htmlMode)
{
ostr << token;

View File

@ -82,6 +82,12 @@ protected:
NAMESPACE_INDEX_COLUMNS = 4
};
enum
{
NO_CUSTOM_HTML = 1,
NO_TRACKING = 2
};
struct TOCEntry
{
std::string title;
@ -117,9 +123,9 @@ protected:
static std::string headerFor(const Poco::CppParser::Symbol* pSymbol);
static std::string titleFor(const Poco::CppParser::Symbol* pSymbol);
void writeHeader(std::ostream& ostr, const std::string& title, const std::string& extraScript = "");
void writeHeader(std::ostream& ostr, const std::string& title, const std::string& extraScript = "", int options = 0);
void writeNavigationFrame(std::ostream& ostr, const std::string& group, const std::string& item);
static void writeFooter(std::ostream& ostr);
static void writeFooter(std::ostream& ostr, int options = 0);
void writeCopyright(std::ostream& ostr);
static void writeTitle(std::ostream& ostr, const std::string& category, const std::string& title);
static void writeTitle(std::ostream& ostr, const Poco::CppParser::NameSpace* pNameSpace, const std::string& title);

View File

@ -457,6 +457,9 @@ protected:
config().setString("PocoDoc.date", Poco::DateTimeFormatter::format(now, "%Y-%m-%d"));
config().setString("PocoDoc.year", Poco::DateTimeFormatter::format(now, "%Y"));
config().setString("PocoDoc.googleAnalyticsCode", generateGoogleAnalyticsCode());
config().setString("PocoDoc.hubSpotCode", generateHubSpotCode());
if (!config().has("PocoDoc.customHeadHTML")) config().setString("PocoDoc.customHeadHTML", "");
if (!config().has("PocoDoc.customBodyHTML")) config().setString("PocoDoc.customBodyHTML", "");
Poco::Stopwatch sw;
int errors = 0;
try
@ -484,17 +487,27 @@ protected:
std::string googleAnalyticsId(config().getString("PocoDoc.googleAnalyticsId", ""));
if (!googleAnalyticsId.empty())
{
ostr << "<!-- Begin Google Analytics -->\n";
ostr << "<script type=\"text/javascript\">\n";
ostr << "var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");\n";
ostr << "document.write(unescape(\"%3Cscript src='\" + gaJsHost + \"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));\n";
ostr << "<script>\n";
ostr << " (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n";
ostr << " (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n";
ostr << " m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n";
ostr << " })(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n";
ostr << "\n";
ostr << " ga('create', '" << googleAnalyticsId << "', 'auto');\n";
ostr << " ga('set', 'anonymizeIp', true);\n";
ostr << " ga('send', 'pageview');\n";
ostr << "</script>\n";
ostr << "<script type=\"text/javascript\">\n";
ostr << "try {\n";
ostr << "var pageTracker = _gat._getTracker(\"" << googleAnalyticsId << "\");\n";
ostr << "pageTracker._trackPageview();\n";
ostr << "} catch(err) {}</script>\n";
ostr << "<!-- End Google Analytics -->\n";
}
return ostr.str();
}
std::string generateHubSpotCode()
{
std::stringstream ostr;
std::string hubSpotId(config().getString("PocoDoc.hubSpotId", ""));
if (!hubSpotId.empty())
{
ostr << "<script type=\"text/javascript\" id=\"hs-script-loader\" async defer src=\"//js.hs-scripts.com/" << hubSpotId << ".js\"></script>\n";
}
return ostr.str();
}

View File

@ -32,6 +32,9 @@ standard library. The contributors attempt to find a good balance
between using advanced C++ features and keeping the classes
comprehensible and the code clean, consistent and easy to maintain.
<%
<?-PocoDoc.adContent?>
%>
!!! The Foundation Library

View File

@ -23,6 +23,9 @@ team and may not always be up to date.*>
Up-to-date [[https://conan.io Conan]] packages are available via
[[https://bintray.com/pocoproject/conan/Poco%3Apocoproject Bintray]].
<%
<?-PocoDoc.adContent?>
%>
!!Source Code Distribution Format

View File

@ -26,12 +26,12 @@ case `uname` in
esac
spec=""
docConfig=$POCO_BASE/PocoDoc/cfg/mkdoc-poco.xml
docConfig=""
while [ "$1" != "" ] ;
do
if [ "$1" = "-C" ] ; then
shift
docConfig=$1
docConfig="$docConfig -C $1"
shift
elif [ "$1" = "-v" ] ; then
shift
@ -43,6 +43,10 @@ do
fi
done
if [ -z "$docConfig" ] ; then
docConfig="-C $POCO_BASE/PocoDoc/cfg/mkdoc-poco.xml"
fi
if [ "$spec" != "" ] ; then
relspec="-f release/spec/${spec}.release"
tag="-$spec"
@ -105,4 +109,4 @@ export PATH=$tools/PocoDoc/bin/$osname/$osarch:$PATH
echo PATH=$PATH
echo "Building documentation $release (using $docConfig)"
mkdocumentation $reltag $relspec -C $docConfig -v $version
mkdocumentation $reltag $relspec $docConfig -v $version

View File

@ -30,7 +30,7 @@ make=make
include=`dirname $0`
build=$POCO_BASE/stage/docbuild
dist=$POCO_BASE/releases
docConfig=$POCO_BASE/PocoDoc/cfg/mkdocumentation.xml
docConfig=""
read version <$POCO_BASE/VERSION
osname=`uname -s | tr ' ' '_'`
@ -57,7 +57,7 @@ do
shift
elif [ "$1" = "-C" ] ; then
shift
docConfig=$1
docConfig="$docConfig --config=$1"
shift
elif [ "$1" = "-v" ] ; then
shift
@ -69,6 +69,10 @@ do
fi
done
if [ -z "$docConfig" ] ; then
docConfig=$POCO_BASE/PocoDoc/cfg/mkdocumentation.xml
fi
if [ "$specfile" != "" ] ; then
while read c
do
@ -130,8 +134,7 @@ echo "PocoDoc.output=$docPath" >>$build/PocoDoc.ini
echo "PocoDoc.version=$docVersion" >> $build/PocoDoc.ini
echo "Includes=$includes" >> $build/PocoDoc.ini
echo "PocoDoc --config=$docConfig --config=$build/PocoDoc.ini"
PocoDoc --config=$docConfig --config=$build/PocoDoc.ini
PocoDoc $docConfig --config=$build/PocoDoc.ini
cd $dist