Re: Introducing freemarker-introspection

"Wong, Christopher" <[email protected]> Mon, 16 Jun 2014 08:51:00 -0400
Newsgroups gmane.comp.web.freemarker.user
Message-ID <5900C695468EF8469DF7867FD277BA1E95A1B695D3@PMACPWEXCLS01.corp.epsilon.com>
I agree that the current reflection-based implementation is less maintainable than using the package-access methods you have available starting in 2.3.20. The current approach is only temporary, to allow support for an older version of Freemarker. I will replace it with your recommended approach. This list announcement is to solicit feedback on the public interfaces for freemarker-introspection, which should be independent of the underlying implementation.

Chris

-----Original Message-----
From: Daniel Dekany [mailto:[email protected]]
Sent: Saturday, June 14, 2014 7:10 AM
To: FreeMarker-user
Subject: Re: [FreeMarker-user] Introducing freemarker-introspection

Do you plan to work on this against 2.3.21, or if something is missing from the freemarker.core-package-visible API, then against the trunk?
If I refactor something inside freemarker.core later, it's much easier to keep freemarker-introspection in sync with it if it relies on freemkarker.core-package-access rather than on reflection.


Friday, June 13, 2014, 3:03:49 PM, Wong, Christopher wrote:

> I would like to introduce a new project, "freemarker-introspection".
> Meant to supplement the core Freemarker project, the purpose of this
> project is to provide a programmatic way to inspect and modify a
> Freemarker template. While Freemarker has an object representation of
> a parsed template, this representation is generally not externally
> accessible. The primary feature of freemarker-introspection is to
> expose the parsed Freemarker template as a DOM-like AST object that
> you can navigate in Java:
>
>         Element root = TemplateIntrospector.getRootNode(template);
>         for (Element child : root.getChildren()) {
>             for (Expr param : child.getParams()) {
>                 ...
>             }
>         }
>
> You can also use a Visitor pattern to walk the template nodes. I
> implemented 2 classes that serve as consumers of this output.
>
> VariableFinder scans the template and returns information on variables
> that the template will reference from the model:
>
>         Element root = TemplateIntrospector.getRootNode(template);
>         List<VariableInfo> vars = new
> VariableFinder(root).seek().getVariableInfo();
>
> TemplateEditor lets you replace specific nodes (elements and
> expressions) with your own content:
>
>         Element root = TemplateIntrospector.getRootNode(template);
>         Element elem = ...; // find element node in tree to replace
>         Expr expr = ...; // find expression node in tree to replace
>         String newTemplateText = new TemplateEditor(oldTemplateText)
>                 .replace(elem, "<#include 'something_else.ftl'>")
>                 .replace(expr, "123")
>                 .apply()
>                 .getModifiedTemplate();
>
> You can find freemarker-introspection at:
>
> https://github.com/cwong15/freemarker-introspection
>
> You will need Gradle to build it. It currently works with Freemarker
> versions 2.3.19 and 2.3.20. This project is still in its very early
> stages, so your feedback will be very much welcome.
>
> Chris
>
> This e-mail and files transmitted with it are confidential, and are
> intended solely for the use of the individual or entity to whom this
> e-mail is addressed. If you are not the intended recipient, or the
> employee or agent responsible to deliver it to the intended recipient,
> you are hereby notified that any dissemination, distribution or
> copying of this communication is strictly prohibited. If you are not
> one of the named recipient(s) or otherwise have reason to believe that
> you received this message in error, please immediately notify sender
> by e-mail, and destroy the original message. Thank You.
--
Thanks,
 Daniel Dekany


------------------------------------------------------------------------------
HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
Find What Matters Most in Your Big Data with HPCC Systems
Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
Leverages Graph Analysis for Fast Processing & Easy Data Exploration
http://p.sf.net/sfu/hpccsystems
_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user

This e-mail and files transmitted with it are confidential, and are intended solely for the use of the individual or entity to whom this e-mail is addressed. If you are not the intended recipient, or the employee or agent responsible to deliver it to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you are not one of the named recipient(s) or otherwise have reason to believe that you received this message in error, please immediately notify sender by e-mail, and destroy the original message. Thank You.

------------------------------------------------------------------------------
HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
Find What Matters Most in Your Big Data with HPCC Systems
Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
Leverages Graph Analysis for Fast Processing & Easy Data Exploration
http://p.sf.net/sfu/hpccsystems