8#include <Cutelyst/Context>
9#include <Cutelyst/ParamsMultiMap>
10#include <cutelee/exception.h>
11#include <cutelee/parser.h>
15using namespace Qt::StringLiterals;
18 : Cutelee::Node(parser)
19 , m_path(path, parser)
21 bool foundQuery =
false;
22 for (
const QString &expression : args) {
24 if (expression.compare(u
"QUERY") == 0) {
30 m_queryExpressions.push_back(Cutelee::FilterExpression(expression, parser));
32 m_argsExpressions.push_back(Cutelee::FilterExpression(expression, parser));
35 std::reverse(m_queryExpressions.begin(), m_queryExpressions.end());
38std::pair<QString, QString> splitQuery(
const QString &query)
40 std::pair<QString, QString> ret;
42 ret.first = query.
section(u
'=', 0, 0);
43 ret.second = query.
section(u
'=', 1);
48void UriFor::render(Cutelee::OutputStream *stream, Cutelee::Context *gc)
const
53 const QVariantHash hash = gc->stackHash(0);
54 for (
const auto &[key, value] : hash.asKeyValueRange()) {
55 if (value.userType() == qMetaTypeId<Cutelyst::Context *>()) {
58 m_cutelystContext = key;
73 QVariant pathVar = m_path.resolve(gc);
74 if (pathVar.
userType() == qMetaTypeId<Cutelee::SafeString>()) {
75 path = pathVar.
value<Cutelee::SafeString>().
get();
79 qWarning() <<
"c_uri_for PATH is not a valid type";
83 for (
const Cutelee::FilterExpression &exp : m_argsExpressions) {
85 if (var.
userType() == qMetaTypeId<Cutelee::SafeString>()) {
86 args << var.
value<Cutelee::SafeString>().
get();
94 for (
const Cutelee::FilterExpression &exp : m_queryExpressions) {
96 if (var.
userType() == qMetaTypeId<Cutelyst::ParamsMultiMap>()) {
98 queryValues.
unite(map);
99 }
else if (var.
userType() == qMetaTypeId<Cutelee::SafeString>()) {
100 auto query = splitQuery(var.
value<Cutelee::SafeString>().get());
103 auto query = splitQuery(var.
toString());
107 for (
const QString &str : queries) {
108 auto query = splitQuery(str);
117Cutelee::Node *UriForTag::getNode(
const QString &tagContent, Cutelee::Parser *p)
const
124 throw Cutelee::Exception(Cutelee::TagSyntaxError,
125 u
"c_uri_for requires at least the path"_s);
128 return new UriFor(parts.
first(), parts.
mid(1), p);
131#include "moc_urifor.cpp"
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * get(const QNetworkRequest &request)
bool isEmpty() const const
QList< T > mid(qsizetype pos, qsizetype length) const const
QMultiMap::iterator insert(QMultiMap::const_iterator pos, const Key &key, const T &value)
QMultiMap< Key, T > & unite(QMultiMap< Key, T > &&other)
QString first(qsizetype n) const const
QString section(QChar sep, qsizetype start, qsizetype end, QString::SectionFlags flags) const const
QString toString() const const
QStringList toStringList() const const
int userType() const const