freemarker-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Dekany <ddek...@apache.org>
Subject Re: [FM3] Solving FM2 caching problems due to locale etc.
Date Mon, 27 Mar 2017 00:07:21 GMT
Sunday, March 26, 2017, 8:33:57 PM, Denis Bredelet wrote:

> Hi Daniel,
>
>>> Hi,
>>> 
>>>>> Template.process(...) would be removed, as it's not the duty of the
>>>>> Template to create the Environment anymore.
>>>>> 
>>>>> On the level of the more expert Environment API, this translates to
>>>>> something like this:
>>>>> 
>>>>>   Environment env = new Environment(cfg, dataModel, out);
>>>>>   env.setLocale(aLocale);
>>>>>   env.setCustomLookupCondition(aLookupCondition);
>>>>>   ... // Addjust env further
>>>>>   env.loadMainTemplate(name); // After setting locale and customLookupCond!
>>>>>   env.process();
>>>>>   ... // Get back variables from env if you want
>>>> This looks a lot clearer and more intuitive to me!
>>>> 
>>> 
>>> The last two lines do not seem intuitive for me. What do they do?
>> 
>> 1. loadMainTemplate gets a Template (from the TemplateResolver) and
>>   sets it as the main template of the Environment.
>> 2. process runs the main template of the Environment.
>> 
>> What exactly is confusing about it? I'm asking so that we can make it
>> more intuitive.
>
> In the current environment I do not think there is a main template.

But there is:
http://freemarker.org/docs/api/freemarker/core/Environment.html#getMainTemplate--

The template whose process (or createProcessingEnvironment) method you
call is the main template. With other words, it's the top-level
template. There are also FTL special variables like `.main` and
`.main_template_name`.

> Is that new? Does it contain the template text? What can you do with it? Can you access
it as text?
>
> Next, the process method seems to run the main template. If that is
> its function then the name should reflect that.

It's like "main" in C (or even in Java). When you run an application,
you are actually invoking "main", yet we are just talking about
running an application. It's analogous to that.

But we might as well call it "processMainTemplate". What do others think?

Also, I wonder if instead of "process" (terminology inherited form
FM2), "run" would be better. So then it's "runMainTemplate", and then
we also have cfg.runTemplate(...) instead of cfg.processTemplate(...).

> Conceptually, do you want the environment to be a container for the
> main template or does it have another purpose?

Its purpose of Environment is to hold the status of the template
processing (such as current setting values, other variables, call
stack, etc). Part of that "state" is what the main template is.

> I don’t like using a class which serves more than one main purpose
> — too comparable to kitchen sink for my liking.
>
> Thanks,
> — Denis.
>
>>> — Denis.
>>> 
>>>>> 
>>>>> You might notice that Environment now stores the
>>>>> customLookupCondition, while in FM2 the Template stores it. Any
>>>>> template loading from the Environment will happen with that condition
>>>>> (and with env.locale, just as in FM2). In FM2 the
>>>>> customLookupCondition is inherited from the Template that contains the
>>>>> #import/#include statement, but if you think about it, the end results
>>>>> is practically the same.
>>>> Yeah, it's really cool concepts now. Very exciting!!
>>>> 
>>>> Cheers,
>>>> 
>>>> Woonsan
>>> 
>> 
>> -- 
>> Thanks,
>> Daniel Dekany
>

-- 
Thanks,
 Daniel Dekany


Mime
View raw message