[
https://issues.apache.org/jira/browse/FREEMARKER-148?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17156087#comment-17156087
]
Siegfried Goeschl edited comment on FREEMARKER-148 at 7/11/20, 6:14 PM:
------------------------------------------------------------------------
Reverted the approach since I ran into issues of shadowing - a "name" of a data
source shadows exposed member functions of "DataSource". So I'm using a plain
map to expose the data sources
* The various tools are exposed as map in FreeMarker
* The name of a data source is provided either by the user or the URI of the
data source is used so we have unique names
* "DataSources" (basically a wrapper of a list of data sources) exposed
convenience methods for selecting a "data source" - this feature is replaced by
using "DataSource.match(String key)" and FreeMarker's filter expression
{noformat}
List all data sources containing "test" in the name
<#list dataSources?values?filter(ds -> ds.match("name", "*test*")) as ds>
- ${ds.name}
</#list>
List all data sources having "json" extension
<#list dataSources?values?filter(ds -> ds.match("extension", "json")) as ds>
- ${ds.name}
</#list>
List all data sources having "src/test/data/properties" in their directory name
<#list dataSources?values?filter(ds -> ds.match("filePath",
"*/src/test/data/properties")) as ds>
- ${ds.name}
</#list>
{noformat}
was (Author: sgoeschl):
Reverted the approach since I ran into issues of shadowing - a "name" of a data
source shadows exposed member functions of "DataSource". So I'm using a plain
map to expose the data sources
* the name of a data source is provided either by the user or the URI of the
data source is used so we have unique names
* "DataSources" (basically a wrapper of a list of data sources) exposed
convenience methods for selecting a "data source" - this feature is replaced by
using "DataSource.match(String key)" and FreeMarker's filter expression
{noformat}
List all data sources containing "test" in the name
<#list dataSources?values?filter(ds -> ds.match("name", "*test*")) as ds>
- ${ds.name}
</#list>
List all data sources having "json" extension
<#list dataSources?values?filter(ds -> ds.match("extension", "json")) as ds>
- ${ds.name}
</#list>
List all data sources having "src/test/data/properties" in their directory name
<#list dataSources?values?filter(ds -> ds.match("filePath",
"*/src/test/data/properties")) as ds>
- ${ds.name}
</#list>
{noformat}
> [freemarker-cli] Make usage of "DataSources" more "Freemarker" like
> -------------------------------------------------------------------
>
> Key: FREEMARKER-148
> URL: https://issues.apache.org/jira/browse/FREEMARKER-148
> Project: Apache Freemarker
> Issue Type: Task
> Reporter: Siegfried Goeschl
> Assignee: Siegfried Goeschl
> Priority: Major
>
> "DataSources" is exposed to get/find documents - as suggested it would be
> nice to make the access more aligned with FreeMarker usage.
> The way to go is to wrap "DataSources" and expose "TemplateSequenceModel" and
> "TemplateHashModel".
> So accessing the first datasource would look like
> {code:java}
> ${GsonTool.toJson(YamlTool.parse(DataSources[0]))}
> {code}
> instead of
> {code:java}
> ${GsonTool.toJson(YamlTool.parse(DataSources.get(0)))}
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)