Smithy Qt 0.1.0-pre
Internal development documentation
Loading...
Searching...
No Matches
renderer.h
1// SPDX-FileCopyrightText: 2013-2025 Paul Colby <git@colby.id.au>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4#include <QtGlobal> // \todo Remove if/when dropping support for Qt 6.0.x.
5#if (QT_VERSION_CHECK(6, 0, 0) <= QT_VERSION) && (QT_VERSION < QT_VERSION_CHECK(6, 1, 0))
6#include <limits> // https://bugreports.qt.io/browse/QTBUG-89977
7#endif
8
9#if defined USE_CUTELEE
10#include <cutelee/engine.h>
11#elif defined USE_GRANTLEE
12#include <grantlee/engine.h>
13#elif defined USE_KTEXTTEMPLATE
14#include <KTextTemplate/Engine>
15#endif
16
17#include "textlee.h"
18
19#include <QCoreApplication>
20#include <QLoggingCategory>
21
22class Renderer
23{
24Q_DECLARE_TR_FUNCTIONS(Renderer);
25
26public:
27 Renderer();
28
29 bool loadTemplates(const QString &dirPath);
30
31 QStringList templatesNames() const;
32
33 void push(const QVariantHash &context);
34 void pop();
35
36 bool render(const QString &templateName, const QString &outputPathName,
37 const QVariantHash &additionalContext = QVariantHash{});
38
39 static QString sanitise(const QString &key);
40 static QVariant sanitise(const QVariant &variant);
41 static QVariantHash sanitise(const QVariantHash &hash);
42 static QVariantMap sanitise(const QVariantMap &map);
43
44protected:
45 Textlee::Context context;
46 Textlee::Engine engine;
47 QStringList templates;
48
49 static Q_LOGGING_CATEGORY(lc, "smithy.Renderer", QtInfoMsg); ///< Logging category for Renderer.
50};
static Q_LOGGING_CATEGORY(lc, "smithy.Renderer", QtInfoMsg)
Logging category for Renderer.