Comments (13)
Hehe, this is something that I wanted to do a while ago, basically Grantlee stance is to no call object method, so I'm thinking in writting a custon filter like
{{ c|uriFor "action name" }}
Still I dunno if Grantlee exposes API for this, if you how please do a PR, otherwise I might look at this later this week.
from cutelyst.
For the moment I have been using relative urls..
from cutelyst.
Yes, a filter was also my first thought. But since the Grantlee documentation is a little bit sparse on that topic I am still investigating. As far as I know one can only add new filters by loading Qt plugins that implement a certain interface.
from cutelyst.
It doesn't look so complex http://www.grantlee.org/apidox/extension.html
from cutelyst.
Yeah, I know, I know ;) I already went through this but got stuck at the cmake macros. But I am on it...
from cutelyst.
OK, I don't know what I am doing wrong. I've been trying to build a simple filter that just prefixes a variable with a static string:
myfilter.hpp:
#ifndef __myfilter_hpp
#define __myfilter_hpp
#include <grantlee/filter.h>
#include <grantlee/safestring.h>
#include <grantlee/util.h>
class MyFilter : public Grantlee::Filter {
QVariant doFilter( const QVariant &input, const QVariant &arg,
bool autoescape) const;
bool isSafe() const { return true; }
};
#endif
myfilter.cpp:
#include "myfilter.hpp"
QVariant MyFilter::doFilter(
const QVariant &input,
const QVariant &arg = QVariant(),
bool autoescape = false
) const {
Grantlee::SafeString str = Grantlee::getSafeString(input);
return "MyFilter Says: " + str + "//";
}
mylib.hpp:
#ifndef __mylib_hpp
#define __mylib_hpp
#include <QDebug>
#include <grantlee/taglibraryinterface.h>
#include "myfilter.hpp"
#define MyFilterLib_iid "de.chronowerks.qtplugins.MyFilterPlugin"
class MyFilterLib : public QObject, public Grantlee::TagLibraryInterface {
Q_OBJECT
Q_PLUGIN_METADATA(IID "de.chronowerks.qtplugins.MyFilterPlugin" FILE "mylib.json")
Q_INTERFACES(Grantlee::TagLibraryInterface)
public:
MyFilterLib( QObject *parent = 0 ) : QObject(parent) {
m_filters.insert("myfilter", new MyFilter());
}
QHash<QString, Grantlee::Filter*> filters(const QString &name = QString()) {
Q_UNUSED(name);
return m_filters;
}
};
#endif
CMakeLists.txt:
cmake_minimum_required(VERSION 3.7)
project(myfilterlib)
add_library(myfilterlib MODULE
myfilter.cpp
myfilter.hpp
mylib.hpp
)
find_package(Qt5 COMPONENTS Core REQUIRED)
find_package(Grantlee5 REQUIRED)
set_property(TARGET myfilterlib PROPERTY EXPORT_NAME myfilterlib)
target_link_libraries(myfilterlib Grantlee5::Templates)
grantlee_adjust_plugin_name(myfilterlib)
Everything seems fine to me. The resulting library lib is located in the build directory under grantlee/5.1/myfilterlib.so
and builds without error.
In a very simple test program I tried to add the library:
Grantlee::Engine *e = new Grantlee::Engine();
e->addPluginPath("plugins");
e->addDefaultLibrary("myfilterlib");
but to no avail:
grantlee.template: "Plugin library 'myfilterlib' not found."
Even though strace
confirmed it's been opened:
> grep myfilter trace.txt
stat("[...]plugins/grantlee/5.1/myfilterlib.so", {st_mode=S_IFREG|0755, st_size=19256, ...}) = 0
...
open("[...]plugins/grantlee/5.1/myfilterlib.so", O_RDONLY|O_CLOEXEC) = 4
But I can't see anything wrong with the interface implementation.
Do you have any idea?
from cutelyst.
Ok, I finally managed to setup this, you can look at grantlee_uri_for branch, but it seems
that a Filter is not good for uri_for since you can only pass one argument, and requires you to put the Contex variable.
A tag on the other hand could probably be used like:
{% c_uri_for "action" "query" %}
which since has access to the Parser can get the Context automatically.
Grantlee is a project I'm trying to avoid forking but the maintainer doesn't have time to even accept PR, and doesn't seem to be willing to add me as a contributor... I'd like to add an API to not require creating a plugin which has no use outside Cutelyst...
from cutelyst.
I'd like to add an API to not require creating a plugin which has no use outside Cutelyst...
Exactly. That's what I thought.
Maybe there is a possibility to fill c->config()
with a hash of the controllers (like in the first posting) so that something like {{c.config.urlfor.Authen.logout}}
would be possible...
from cutelyst.
it's too much work to build such a hash, not to mention it won't work for chained, I think a tag will be fine.
from cutelyst.
OK
from cutelyst.
I have updated the branch with a tag now, please try it, I guess c_uri_for_action will also be needed, and some euristics in parsing arguments.
from cutelyst.
And there you go :D
from cutelyst.
Nice! :D Works like a charme!
from cutelyst.
Related Issues (20)
- Cutelyst with ASql HOT 2
- Asynchronous REST API using GUI mode HOT 2
- Epoll event loop on Qt 6.4+
- Macos build error in EventDispatcherEPoll
- Question about Response::redirect HOT 1
- CRASH: Cutelyst is not responsive after wrong request
- Question about default change server/plugins default config HOT 3
- How prevent from session expire time change on some request? HOT 1
- RoleACL problem HOT 3
- How to access Request inside custom tag processing? HOT 2
- Copy-paste issue in CredentialPasswordPrivate::checkPassword HOT 2
- Cutelyst "Authentication plugin not registered" error message when running multithreaded in Kubernetes HOT 6
- Qt 6.5 compatibility and broken QMetaMethod::invoke() HOT 3
- Cutelyst not working with Qt 6.5 HOT 3
- how use qt with mimalloc HOT 1
- SONUM for Cutelyst4
- Problem with call Root::Auto HOT 11
- Qt 6.5.3 problem [was 'Problem with call Root::Auto'] HOT 6
- Multiple configuration files HOT 7
- server config section naming HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cutelyst.