[windup-dev] Freemarker usage
Jess Sightler
jsightle at redhat.com
Thu Jul 9 10:56:24 EDT 2015
On 07/09/2015 07:33 AM, Ondrej Zizka wrote:
> 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?
That would "work", but the sorting wouldn't look very nice.
Instead of:
com.example.Foo
com.example.Zoo
com.example.apples.Potato
com.example.bar.Baz
com.example.zoo.Animals
You would get something like this:
com.example.apples.Potato
com.example.bar.Baz
com.example.Foo
com.example.Zoo
com.example.zoo.Animals
It's just not the natural way to sort directories and package paths,
since they are hierarchical.
>
> 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?
I didn't write this one, so I don't know why it was written this way. I
think I agree with you, though, that method seems unnecessary.
Feel free to try it. :)
More information about the windup-dev
mailing list