From 47bc520ac8c0dde310dcb1999c622c591b373ffc Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Sat, 10 May 2014 17:17:26 +0200 Subject: changed append filter and added index and path attributes to node --- src/template.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/src/template.cpp b/src/template.cpp index e882930..b76d8f3 100644 --- a/src/template.cpp +++ b/src/template.cpp @@ -738,13 +738,34 @@ class FilterAdd //----------------------------------------------------------------------------- +/** @brief The implementation of the "append" filter */ +class FilterAppend +{ + public: + static TemplateVariant apply(const TemplateVariant &v,const TemplateVariant &arg) + { + if ((v.type()==TemplateVariant::String || v.type()==TemplateVariant::Integer) && + arg.type()==TemplateVariant::String) + { + return TemplateVariant(v.toString() + arg.toString()); + } + else + { + return v; + } + } +}; + +//----------------------------------------------------------------------------- + /** @brief The implementation of the "prepend" filter */ class FilterPrepend { public: static TemplateVariant apply(const TemplateVariant &v,const TemplateVariant &arg) { - if (v.type()==TemplateVariant::String && arg.type()==TemplateVariant::String) + if ((v.type()==TemplateVariant::String || v.type()==TemplateVariant::Integer) && + arg.type()==TemplateVariant::String) { return TemplateVariant(arg.toString() + v.toString()); } @@ -1102,7 +1123,7 @@ class TemplateFilterFactory // register a handlers for each filter we support static TemplateFilterFactory::AutoRegister fAdd("add"); -static TemplateFilterFactory::AutoRegister fAppend("append"); +static TemplateFilterFactory::AutoRegister fAppend("append"); static TemplateFilterFactory::AutoRegister fLength("length"); static TemplateFilterFactory::AutoRegister fNoWrap("nowrap"); static TemplateFilterFactory::AutoRegister fFlatten("flatten"); @@ -2214,6 +2235,24 @@ void TemplateContextImpl::closeSubIndex(const QCString &indexName) } } +static void getPathListFunc(TemplateStructIntf *entry,TemplateList *list) +{ + TemplateVariant parent = entry->get("parent"); + if (parent.type()==TemplateVariant::Struct) + { + getPathListFunc(parent.toStruct(),list); + } + list->append(entry); +} + +static TemplateVariant getPathFunc(const void *ctx, const QValueList &) +{ + TemplateStruct *entry = (TemplateStruct*)ctx; + TemplateList *result = TemplateList::alloc(); + getPathListFunc(entry,result); + return result; +} + void TemplateContextImpl::addIndexEntry(const QCString &indexName,const QValueList &arguments) { QValueListConstIterator it = arguments.begin(); @@ -2223,6 +2262,7 @@ void TemplateContextImpl::addIndexEntry(const QCString &indexName,const QValueLi // printf(" key=%s value=%s\n",(*it).key.data(),(*it).value.toString().data()); // ++it; //} + TemplateVariant parent(FALSE); QStack *stack = m_indexStacks.find(indexName); if (!stack) // no stack yet, create it! { @@ -2248,6 +2288,13 @@ void TemplateContextImpl::addIndexEntry(const QCString &indexName,const QValueLi { ASSERT(stack->top()->type()==TemplateVariant::List); } + if (stack->count()>1) + { + TemplateVariant *tmp = stack->pop(); + parent = *stack->top(); + stack->push(tmp); + ASSERT(parent.type()==TemplateVariant::Struct); + } // get list to add new item list = dynamic_cast(stack->top()->toList()); } @@ -2264,6 +2311,9 @@ void TemplateContextImpl::addIndexEntry(const QCString &indexName,const QValueLi } entry->set("is_leaf_node",true); entry->set("first",list->count()==0); + entry->set("index",list->count()); + entry->set("parent",parent); + entry->set("path",TemplateVariant::Delegate::fromFunction(entry,getPathFunc)); entry->set("last",true); stack->push(new TemplateVariant(entry)); list->append(entry); @@ -2785,6 +2835,10 @@ class TemplateNodeFor : public TemplateNodeCreator if (m_expr) { TemplateVariant v = m_expr->resolve(c); + if (v.type()==TemplateVariant::Function) + { + v = v.call(QValueList()); + } const TemplateListIntf *list = v.toList(); if (list) { @@ -3160,6 +3214,7 @@ class TemplateNodeCreate : public TemplateNodeCreator { QCString templateFile = m_templateExpr->resolve(c).toString(); QCString outputFile = m_fileExpr->resolve(c).toString(); + printf("TemplateNodeCreate file='%s' template='%s'\n",outputFile.data(),templateFile.data()); if (templateFile.isEmpty()) { ci->warn(m_templateName,m_line,"empty template name parameter for create command\n"); -- cgit v0.12