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 #include <grantlee/exception.h>
10 #include <grantlee/parser.h>
11 
12 using namespace MessageViewer;
13 
14 CallbackTag::CallbackTag(const QString &name, QObject *parent)
15  : Grantlee::Node(parent)
16  , m_name(name)
17 {
18 }
19 
20 void CallbackTag::render(Grantlee::OutputStream *stream, Grantlee::Context *context) const
21 {
22  auto cb = context->lookup(m_name).value<GrantleeCallback>();
23  if (cb) {
24  cb(stream);
25  }
26 }
27 
28 Grantlee::Node *CallbackTagFactory::getNode(const QString &tagContent, Grantlee::Parser *parser) const
29 {
30  auto expr = tagContent.split(QLatin1Char(' '), Qt::SkipEmptyParts);
31  if (expr.size() != 2) {
32  return nullptr;
33  }
34 
35  return new CallbackTag(expr.at(1), parser);
36 }
37 
38 GrantleeTagLibrary::GrantleeTagLibrary(QObject *parent)
39  : QObject(parent)
40 {
41 }
42 
43 QHash<QString, Grantlee::AbstractNodeFactory *> GrantleeTagLibrary::nodeFactories(const QString &name)
44 {
45  Q_UNUSED(name)
46  QHash<QString, Grantlee::AbstractNodeFactory *> nodeFactories;
47  nodeFactories.insert(QStringLiteral("callback"), new CallbackTagFactory());
48  return nodeFactories;
49 }
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
SkipEmptyParts
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Dec 6 2021 23:04:57 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.