7#include "genericformatter.h"
10#include "grantleeki18nlocalizer.h"
11#include "grantleethemeengine.h"
13using namespace GrantleeTheme;
15class GrantleeTheme::GenericFormatterPrivate
18 GenericFormatterPrivate()
25 std::unique_ptr<Engine>
const mEngine;
31GenericFormatter::GenericFormatter(
const QString &defaultHtmlMain,
const QString &themePath)
32 : d(new GenericFormatterPrivate)
34 d->mThemePath = themePath;
35 d->mDefaultMainFile = defaultHtmlMain;
36 setTemplatePath(d->mThemePath);
39GenericFormatter::GenericFormatter()
40 : d(new GenericFormatterPrivate)
44GenericFormatter::~GenericFormatter() =
default;
46void GenericFormatter::setDefaultHtmlMainFile(
const QString &name)
48 if (d->mDefaultMainFile != name) {
49 d->mDefaultMainFile = name;
54void GenericFormatter::setTemplatePath(
const QString &path)
56 if (!d->mTemplateLoader) {
59 d->mTemplateLoader->setTemplateDirs(
QStringList() << path);
60 d->mEngine->addTemplateLoader(d->mTemplateLoader);
67 d->mEngine->localizer()->setApplicationDomain(domain);
70QString GenericFormatter::errorMessage()
const
72 return d->mErrorMessage;
75QString GenericFormatter::render(
const QVariantHash &mapping)
const
78 context.setLocalizer(d->mEngine->localizer());
80 const QString contentHtml = d->mTemplate->render(&context);
86 d->mTemplate = d->mEngine->newTemplate(content, QStringLiteral(
"content"));
87 if (d->mTemplate->error()) {
88 d->mErrorMessage = d->mTemplate->errorString() +
"<br>"_L1;
92void GenericFormatter::reloadTemplate()
94 d->mTemplate = d->mEngine->loadByName(d->mDefaultMainFile);
95 if (d->mTemplate->error()) {
96 d->mErrorMessage += d->mTemplate->errorString() +
"<br>"_L1;