[windup-dev] Freemarker usage

Ondrej Zizka ozizka at redhat.com
Thu Jul 9 07:33:56 EDT 2015


Hi,

I have few questions regarding Freemarker usage.

There are many places where we duplicate the functionality already 
available in Freemarker.
I wonder if it's necessary, as it makes the code less readable.

1)
For  example, sometimes the iterable needs to become a collection. And 
then needs to be sorted.
We have this:

           <#list 
sortFilesByPathAscending(projectModel.fileModelsNoDirectories) as fileModel>
              <@fileModelRenderer fileModel/>
           </#list>

sortFilesByPathAscending() is a FM function created just for this one 
single case (or there's a second one).

Wouldn't it be better to just make projectModel.fileModelsNoDirectories 
a collection using some toList(projectModel.fileModelsNoDirectories) and 
sort it in FM?
Did something prevent this kind of usage?

           <#list 
toList(projectModel.fileModelsNoDirectories)?sort_by("filePath") as 
fileModel>

Or, better, having it sorted right in the database, which is probably 
better place to do so as it may have indexes available for it?

2)
iterableHasContent(...)  - again, wouldn't it be better, instead of

        <#if iterableHasContent(projectModel.fileModelsNoDirectories)>
               ...
               <#list 
sortFilesByPathAscending(projectModel.fileModelsNoDirectories) as fileModel>
  to do
<#assign myList = toList(projectModel.fileModelsNoDirectories)
<#if myList?has_content>
      <#list myList?sort_by("filePath") as fileModel>

The only addition of iterableHasContent() is that it measures the time 
for the function call. Is that the reason for it?

Just asking.
Ondra




More information about the windup-dev mailing list