Difference between revisions of "Template Engine"
(Add Reasons for change) |
(→Phase 1) |
||
Line 15: | Line 15: | ||
== Phase 1 == | == Phase 1 == | ||
− | The aim would be to utilise the already built output system and add | + | The aim would be to utilise the already built output system and add the ability to |
− | + | # Detect Freemarker templates and use the Freemarker engine to process them | |
− | existing output tags to be | + | # Add custom directives that can be called from a template (output sheet) to allow the |
− | change-over and use our existing well tested output code base. | + | existing output tags to be used. |
+ | |||
+ | This would give us a simple change-over and use our existing well tested output code base. | ||
So for example we might have | So for example we might have | ||
− | <@ | + | <nowiki> |
+ | <@pcstring tag="NAME"/> | ||
+ | <@pcstring tag="SPELLMEM.0.1.1.1.NAME"/> | ||
+ | <@pcvar tag="CL=Fighter"/> | ||
+ | <@pcvar tag="count(\"ABILITIES\",\"CATEGORY=FEAT\",\"TYPE=Metamagic\",\"VISIBILITY=DEFAULT[or]VISIBILITY=OUTPUT_ONLY\")"/></nowiki> | ||
We would need to ensure that freemarker templates can be used in html, and PDF output styles. | We would need to ensure that freemarker templates can be used in html, and PDF output styles. | ||
+ | |||
+ | See [http://freemarker.org/docs/dgui_misc_userdefdir.html User Defined Directives] and [http://freemarker.org/docs/pgui_config_sharedvariables.html Shared Variables] for information on creating custom directives/tags. | ||
+ | |||
+ | === Looping === | ||
+ | |||
+ | Freemarker's inbuilt looping mechanism is object oriented. It expects to receive a list and process through it. In contrast, PCGen currently only outputs strings and numbers. The technique described at [http://stackoverflow.com/questions/15461721/freemarker-template-for-loop-statement For loop] can be used, but a macro should be created to make this easier and more concise. The macro will also need to deal with the empty loop scenario. |
Revision as of 23:00, 23 October 2013
Template Engine Sub Project
The aim of the project is to examine the Freemarker library with a view to using it to replace our export engine. In particular it would cover functionality logic functions like looping and if tests. This would leave our code to deal with the important things like TO HIT values etc.
We would do this in three phases:
- Add support for Freemarker templates for output
- Once sufficient sheets have been converted/rewritten, deprecate support for olod sheet types
- Finally after a few releases, remove support for the old sheet types.
There are a few reasons for exploring this change
- Add a richer set of logic commands to enable more customisable output
- Simpler more consistent logic commands and more widely understood syntax
- Remove one of the more complex and difficult to maintain sections of the PCGen code base.
Phase 1
The aim would be to utilise the already built output system and add the ability to
- Detect Freemarker templates and use the Freemarker engine to process them
- Add custom directives that can be called from a template (output sheet) to allow the
existing output tags to be used.
This would give us a simple change-over and use our existing well tested output code base.
So for example we might have
<@pcstring tag="NAME"/> <@pcstring tag="SPELLMEM.0.1.1.1.NAME"/> <@pcvar tag="CL=Fighter"/> <@pcvar tag="count(\"ABILITIES\",\"CATEGORY=FEAT\",\"TYPE=Metamagic\",\"VISIBILITY=DEFAULT[or]VISIBILITY=OUTPUT_ONLY\")"/>
We would need to ensure that freemarker templates can be used in html, and PDF output styles.
See User Defined Directives and Shared Variables for information on creating custom directives/tags.
Looping
Freemarker's inbuilt looping mechanism is object oriented. It expects to receive a list and process through it. In contrast, PCGen currently only outputs strings and numbers. The technique described at For loop can be used, but a macro should be created to make this easier and more concise. The macro will also need to deal with the empty loop scenario.