Cutelee 6.1.0
scriptabletags.h
1/*
2 This file is part of the Cutelee template system.
3
4 Copyright (c) 2009,2010 Stephen Kelly <steveire@gmail.com>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either version
9 2.1 of the Licence, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library. If not, see <http://www.gnu.org/licenses/>.
18
19*/
20
21#ifndef SCRIPTABLETAGS_H
22#define SCRIPTABLETAGS_H
23
24#include "node.h"
25#include "taglibraryinterface.h"
26
27#include <QtQml/QJSValue>
28
29class QJSEngine;
30
31namespace Cutelee
32{
33class Engine;
34class Parser;
35
36class ScriptableHelperFunctions : public QObject
37{
38 Q_OBJECT
39 QJSEngine *m_scriptEngine;
40
41public:
42 ScriptableHelperFunctions(QJSEngine *scriptEngine)
43 : m_scriptEngine(scriptEngine)
44 {
45 }
46
47 Q_INVOKABLE QJSValue markSafeFunction(QJSValue inputValue);
48 Q_INVOKABLE QJSValue ScriptableFilterExpressionConstructor(QString name,
49 QObject *parserObj
50 = {});
51 Q_INVOKABLE QJSValue ScriptableNodeConstructor(QJSValue callContext);
52 Q_INVOKABLE QJSValue ScriptableVariableConstructor(QString name);
53 Q_INVOKABLE QJSValue ScriptableTemplateConstructor(QString content,
54 QString name,
55 QObject *parent);
56};
57
58class ScriptableTagLibrary : public QObject, public TagLibraryInterface
59{
60 Q_OBJECT
62 Q_PLUGIN_METADATA(IID "org.cutelee.TagLibraryInterface")
63public:
64 ScriptableTagLibrary(QObject *parent = {});
65
66 QHash<QString, AbstractNodeFactory *> nodeFactories(const QString &name
67 = {}) override;
68
69 QHash<QString, Filter *> filters(const QString &name = {}) override;
70
71public Q_SLOTS:
72 void addFactory(const QString &factoryName, const QString &tagname);
73 void addFilter(const QString &filterName);
74
75protected:
76 bool evaluateScript(const QString &name);
77 QHash<QString, AbstractNodeFactory *> getFactories();
78 QHash<QString, Filter *> getFilters();
79
80private:
81 QJSEngine *m_scriptEngine;
82 QJSValue m_functions;
83 QHash<QString, AbstractNodeFactory *> m_nodeFactories;
84 QHash<QString, QString> m_factoryNames;
85 QStringList m_filterNames;
86 QHash<QString, Filter *> m_filters;
87};
88}
89
90#endif
QHash< QString, AbstractNodeFactory * > nodeFactories(const QString &name={}) override
QHash< QString, Filter * > filters(const QString &name={}) override
The TagLibraryInterface returns available tags and filters from libraries.
The Cutelee namespace holds all public Cutelee API.
Definition Mainpage.dox:8