[Kde-pim] Grantlee 0.1.3 issues

Janne Hakonen joyer83 at live.fi
Wed Aug 4 17:37:38 BST 2010


Hello,

I've stumbled upon two issues with Grantlee 0.1.3 while creating a custom tag and filter with javascript.

The tag-issue I found when I attempted to make a javascript based tag (noblanks...endnoblanks) for removing empty lines from template output. I based the custom tag to spaceless-tag with some modifications and then ported it to javascript using the if2-tag from testscriptabletags-project as an example. The issue appears when there is two or more noblanks-tags used in same template file, each tags' content is replaced with template's last tag's content.

The problem is easy to see by using if2-tag in tests/testscriptabletags.cpp in following way:
QTest::newRow( "scriptable-tags12" ) << "{% load scripteddefaults %}{% if2 \"any\" %}foo{% endif2 %}{% if2 \"key\" %}bar{% endif2 %}" << dict << "foobar" << NoError;

This causes following failure:
FAIL!  : TestScriptableTagsSyntax::testBasicSyntax(scriptable-tags12) Compared values are not the same
   Actual (result): barbar
   Expected (output): foobar
..\..\tests\testscriptabletags.cpp(106) : failure location

With trial and error, I found a workaround which seems to work. Changes to the if2-tag is in the attached scripteddefaults.qs.patch. But, I don't think that the solution is good enough IMO. 



The second issue with filtering occurred when I attempted to filter a list of QObject based wrapper objects with javascript filter. 

Here's a clip from my template:
    enum EventType
    {
{% for event in statemachine.uniqueEvents|onlytype:"signal" %}
        Event{{ event.name|safeident|capfirst }}{% if not forloop.last %},{% endif %}
{% endfor %}
    };

The idea with onlytype-filter is to pass through a list of wrapper objects which type-property is same as given argument. 

The onlytype-filter is defined as follows:
function OnlyTypeFilter( input, filterArgument )
{
    var outList = [];
    for( var i = 0; i < input.length; i++ )
    {
        if( input[i].type == filterArgument.rawString() )
            outList.push( input[i] );
    }
    return outList;
};

This filter, however doesn't work without some changes to scriptabletags/scriptablefilter.cpp. The input variable is a javascript Array with QVariant(QObject*) objects in it. Expression 'input[i].type' fails because the object is a QVariant and not QObject and there doesn't seem to be anyway to get the actual object from the variant.
Also, even if I would just return the input variable without doing anything inside the OnlyTypeFilter-function, the returned value on template's side is empty.

In C++-code that calls the javascript function the wrapper objects are passed to script engine's newVariant-method which doesn't seem to know what to do with QObject pointer and just stores it as a QVariant. in the attached scriptablefilter.cpp.patch are some modifications which uses newQObject-method instead of newVariant, if the input variants can be converted to QObject pointers.
Also, the return value is checked if it's an javascript Array and then casted to QVariantList.

Thanks,
Janne Hakonen
-------------- next part --------------
A non-text attachment was scrubbed...
Name: scriptablefilter.cpp.patch
Type: application/octet-stream
Size: 1372 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-pim/attachments/20100804/be992de7/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: scripteddefaults.qs.patch
Type: application/octet-stream
Size: 629 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-pim/attachments/20100804/be992de7/attachment-0001.obj>
-------------- next part --------------
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/


More information about the kde-pim mailing list