Messagelib

grantleeextension.cpp
1 /*
2  SPDX-FileCopyrightText: 2017 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "grantleeextension.h"
8 
9 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
10 #include <grantlee/exception.h>
11 #include <grantlee/parser.h>
12 #else
13 #include <KTextTemplate/exception.h>
14 #include <KTextTemplate/parser.h>
15 #endif
16 
17 using namespace MessageViewer;
18 
19 CallbackTag::CallbackTag(const QString &name, QObject *parent)
20  : Grantlee::Node(parent)
21  , m_name(name)
22 {
23 }
24 
25 void CallbackTag::render(Grantlee::OutputStream *stream, Grantlee::Context *context) const
26 {
27  auto cb = context->lookup(m_name).value<GrantleeCallback>();
28  if (cb) {
29  cb(stream);
30  }
31 }
32 
33 Grantlee::Node *CallbackTagFactory::getNode(const QString &tagContent, Grantlee::Parser *parser) const
34 {
35  auto expr = tagContent.split(QLatin1Char(' '), Qt::SkipEmptyParts);
36  if (expr.size() != 2) {
37  return nullptr;
38  }
39 
40  return new CallbackTag(expr.at(1), parser);
41 }
42 
43 GrantleeTagLibrary::GrantleeTagLibrary(QObject *parent)
44  : QObject(parent)
45 {
46 }
47 
48 QHash<QString, Grantlee::AbstractNodeFactory *> GrantleeTagLibrary::nodeFactories(const QString &name)
49 {
50  Q_UNUSED(name)
52  nodeFactories.insert(QStringLiteral("callback"), new CallbackTagFactory());
53  return nodeFactories;
54 }
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QHash::iterator insert(const Key &key, const T &value)
SkipEmptyParts
QString name(StandardShortcut id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon May 16 2022 04:18:56 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.