Grantlee::Node* I18npVarNodeFactory::getNode( const QString& tagContent, Parser* p ) const { QStringList expr = smartSplit( tagContent ); if ( expr.size() < 5 ) throw Grantlee::Exception( TagSyntaxError, QLatin1String( "Error: i18np_var tag takes at least four arguments" ) ); QString sourceText = expr.at( 1 ); if ( !( sourceText.startsWith( QLatin1Char( '"' ) ) && sourceText.endsWith( QLatin1Char( '"' ) ) ) && !( sourceText.startsWith( QLatin1Char( '\'' ) ) && sourceText.endsWith( QLatin1Char( '\'' ) ) ) ) { throw Grantlee::Exception( TagSyntaxError, QLatin1String( "Error: i18np tag first argument must be a static string." ) ); } sourceText = sourceText.mid( 1, sourceText.size() - 2 ); QString pluralText = expr.at( 2 ); int argsStart = 3; if ( !( pluralText.startsWith( QLatin1Char( '"' ) ) && pluralText.endsWith( QLatin1Char( '"' ) ) ) && !( pluralText.startsWith( QLatin1Char( '\'' ) ) && pluralText.endsWith( QLatin1Char( '\'' ) ) ) ) { argsStart = 2; pluralText = sourceText; } else { pluralText = pluralText.mid( 1, pluralText.size() - 2 ); } QList<FilterExpression> feList; for ( int i = argsStart; i < expr.size() - 2; ++i ) { feList.append( FilterExpression( expr.at( i ), p ) ); } QString resultName = expr.last(); return new I18npVarNode( sourceText, pluralText, feList, resultName ); }
Node* IfEqualNodeFactory::do_getNode( const QString &tagContent, Parser *p, bool negate ) const { QStringList expr = smartSplit( tagContent ); if ( expr.size() != 3 ) { throw Grantlee::Exception( TagSyntaxError, QString::fromLatin1( "%1 tag takes two arguments." ).arg( expr.first() ) ); } QStringList vars; FilterExpression val1( expr.at( 1 ), p ); FilterExpression val2( expr.at( 2 ), p ); IfEqualNode *n = new IfEqualNode( val1 , val2, negate, p ); const QString endTag( QLatin1String( "end" ) + expr.first() ); NodeList trueList = p->parse( n, QStringList() << QLatin1String( "else" ) << endTag ); n->setTrueList( trueList ); NodeList falseList; if ( p->takeNextToken().content.trimmed() == QLatin1String( "else" ) ) { falseList = p->parse( n, QStringList() << endTag ); n->setFalseList( falseList ); p->removeNextToken(); } // else empty falseList. return n; }
Grantlee::Node* XmlNamespaceNodeFactory::getNode(const QString &tagContent, Grantlee::Parser *p) const { QStringList expr = smartSplit(tagContent); Grantlee::FilterExpression query(expr.at(1), p); QString name; if (expr.size() == 4) name = expr.at(3); return new XmlNamespaceNode(query, name); }
Grantlee::Node* MediaFinderNodeFactory::getNode( const QString& tagContent, Parser* p ) const { QStringList expr = smartSplit( tagContent ); if ( expr.size() <= 1 ) { throw Grantlee::Exception( TagSyntaxError, QLatin1String( "'media_finder' tag requires at least one argument" ) ); } expr.takeAt( 0 ); return new MediaFinderNode( getFilterExpressionList( expr, p ), p ); }
Node* WidthRatioNodeFactory::getNode( const QString &tagContent, Parser *p ) const { QStringList expr = smartSplit( tagContent ); if ( expr.size() != 4 ) { throw Grantlee::Exception( TagSyntaxError, QStringLiteral( "widthratio takes three arguments" ) ); } FilterExpression valExpr( expr.at( 1 ), p ); FilterExpression maxExpr( expr.at( 2 ), p ); FilterExpression maxWidth( expr.at( 3 ), p ); return new WidthRatioNode( valExpr, maxExpr, maxWidth, p ); }
Grantlee::Node* RssFeedNodeFactory::getNode(const QString& tagContent, Grantlee::Parser* p) const { QStringList expr = smartSplit(tagContent); Grantlee::FilterExpression url(expr.at(1), p); Grantlee::FilterExpression query(expr.at(2), p); RssFeedNode *n = new RssFeedNode(url, query); QList<Grantlee::Node*> nodes = p->parse(n, "endrssfeed"); p->takeNextToken(); n->setChildNodes(nodes); return n; }
Node* WithLocaleNodeFactory::getNode( const QString &tagContent, Parser *p ) const { QStringList expr = smartSplit( tagContent ); if ( expr.size() != 2 ) { throw Grantlee::Exception( TagSyntaxError, QString::fromLatin1( "%1 expected format is for example 'with_locale \"de_DE\"'" ).arg( expr.first() ) ); } FilterExpression fe( expr.at( 1 ), p ); WithLocaleNode *n = new WithLocaleNode( fe, p ); NodeList nodeList = p->parse( n, QStringLiteral( "endwith_locale" ) ); n->setNodeList( nodeList ); p->removeNextToken(); return n; }
Grantlee::Node* RangeNodeFactory::getNode( const QString& tagContent, Parser* p ) const { QStringList expr = smartSplit( tagContent ); expr.takeAt( 0 ); int numArgs = expr.size(); if ( numArgs != 1 ) { if ( numArgs <= 2 ) { throw Grantlee::Exception( TagSyntaxError, QStringLiteral( "'range' tag requires at least three arguments" ) ); } if ( expr.at( numArgs - 2 ) != QStringLiteral( "as" ) ) { throw Grantlee::Exception( TagSyntaxError, QStringLiteral( "Invalid arguments to 'range' tag" ) ); } } const QString name = ( numArgs > 2 ) ? expr.at( numArgs - 1 ) : QString(); if ( numArgs > 2 ) numArgs -= 2; RangeNode *n = 0; switch ( numArgs ) { case 1: n = new RangeNode( name, FilterExpression( QChar::fromLatin1( '0' ), p ), FilterExpression( expr.first(), p ), p ); break; case 2: n = new RangeNode( name, FilterExpression( expr.first(), p ), FilterExpression( expr.at( 1 ), p ), p ); break; case 3: n = new RangeNode( name, FilterExpression( expr.first(), p ), FilterExpression( expr.at( 1 ), p ), FilterExpression( expr.at( 2 ), p ), p ); break; default: return 0; } NodeList list = p->parse( n, QStringLiteral( "endrange" ) ); p->removeNextToken(); n->setNodeList( list ); return n; }
Node *WithNodeFactory::getNode(const QString &tagContent, Parser *p) const { auto expr = smartSplit(tagContent); if (expr.size() != 4 || expr.at(2) != QStringLiteral("as")) { throw Grantlee::Exception( TagSyntaxError, QStringLiteral("%1 expected format is 'value as name'") .arg(expr.first())); } FilterExpression fe(expr.at(1), p); QString name(expr.at(3)); auto n = new WithNode(fe, name, p); auto nodeList = p->parse(n, QStringLiteral("endwith")); n->setNodeList(nodeList); p->removeNextToken(); return n; }
Node* BlockNodeFactory::getNode( const QString &tagContent, Parser *p ) const { const QStringList expr = smartSplit( tagContent ); if ( expr.size() != 2 ) { throw Grantlee::Exception( TagSyntaxError, QLatin1String( "block tag takes one argument" ) ); } const QString blockName = expr.at( 1 ); QVariant loadedBlocksVariant = p->property( __loadedBlocks ); QVariantList blockVariantList; if ( loadedBlocksVariant.isValid() && loadedBlocksVariant.type() == QVariant::List ) { blockVariantList = loadedBlocksVariant.toList(); QListIterator<QVariant> it( blockVariantList ); while ( it.hasNext() ) { const QString blockNodeName = it.next().toString(); if ( blockNodeName == blockName ) { throw Grantlee::Exception( TagSyntaxError, QString::fromLatin1( "%1 appears more than once." ).arg( blockName ) ); } } } // Block not already in list. blockVariantList.append( blockName ); loadedBlocksVariant = QVariant( blockVariantList ); p->setProperty( __loadedBlocks, loadedBlocksVariant ); BlockNode *n = new BlockNode( blockName, p ); const NodeList list = p->parse( n, QStringList() << QLatin1String( "endblock" ) << QLatin1String( "endblock " ) + blockName ); n->setNodeList( list ); p->removeNextToken(); return n; }
Node* I18nNodeFactory::getNode( const QString& tagContent, Parser* p ) const { QStringList expr = smartSplit( tagContent ); if ( expr.size() < 2 ) throw Grantlee::Exception( TagSyntaxError, QStringLiteral( "Error: i18n tag takes at least one argument" ) ); QString sourceText = expr.at( 1 ); int size = sourceText.size(); if ( !( sourceText.startsWith( QLatin1Char( '"' ) ) && sourceText.endsWith( QLatin1Char( '"' ) ) ) && !( sourceText.startsWith( QLatin1Char( '\'' ) ) && sourceText.endsWith( QLatin1Char( '\'' ) ) ) ) { throw Grantlee::Exception( TagSyntaxError, QStringLiteral( "Error: i18n tag first argument must be a static string." ) ); } sourceText = sourceText.mid( 1, size - 2 ); QList<FilterExpression> feList; for ( int i = 2; i < expr.size(); ++i ) { feList.append( FilterExpression( expr.at( i ), p ) ); } return new I18nNode( sourceText, feList ); }
Grantlee::Node* XmlRoleNodeFactory::getNode(const QString &tagContent, Grantlee::Parser *p) const { QStringList expr = smartSplit(tagContent); Grantlee::FilterExpression query(expr.at(1), p); return new XmlRoleNode(query); }