Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add template engine ADR #11900

Merged
merged 13 commits into from
Oct 23, 2024
107 changes: 107 additions & 0 deletions docs/decisions/0039-template-engine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
nav_order: 39
parent: Decision Records
---

# Template engine

## Context and Problem Statement

We need to choose a template engine for [custom export filters](https://docs.jabref.org/collaborative-work/export/customexports) and [AI features](https://github.com/JabRef/jabref/pull/11884).

A discussion of template engines was also in [one of the JabRef repos](https://github.com/koppor/jabref/issues/392).

A discussion was raised on StackOverflow ["Velocity vs. FreeMarker vs. Thymeleaf"](https://stackoverflow.com/q/1459426/10037342).

## Decision Drivers

* It should be fast.

Check failure on line 18 in docs/decisions/0039-template-engine.md

View workflow job for this annotation

GitHub Actions / Markdown

Trailing spaces

docs/decisions/0039-template-engine.md:18:21 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md009.md
* It should be possible to provide templates out of Strings (required by the AI feature).
* It should have short and understandable syntax. Especially. Work with unset fields and empty Optionals should be easy.
InAnYan marked this conversation as resolved.
Show resolved Hide resolved

## Considered Options

* Apache Velocity
* Apache FreeMarker
* Thymeleaf

## Decision Outcome

Chosen option: "{title of option 1}", because
{justification. e.g., only option, which meets k.o. criterion decision driver | which resolves force {force} | … | comes out best (see below)}.

## Pros and Cons of the Options

### Apache Velocity

- Main page: <https://velocity.apache.org/>.
- User guide: <https://velocity.apache.org/engine/devel/user-guide.html>.
- Developer guide: <https://velocity.apache.org/engine/devel/developer-guide.html>.

Example:
```text

Check failure on line 42 in docs/decisions/0039-template-engine.md

View workflow job for this annotation

GitHub Actions / Markdown

Fenced code blocks should be surrounded by blank lines

docs/decisions/0039-template-engine.md:42 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```text"] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md031.md
You are an AI assistant that analyses research papers. You answer questions about papers.

Here are the papers you are analyzing:
#foreach( $entry in $entries )
${CanonicalBibEntry.getCanonicalRepresentation($entry)}
#end
```

* Good, because supports plain text templating.
* Good, because it is possible to use `String` as a template.
* Good, because it has simple syntax.
* Bad, because {argument d}
* Bad, because it is in maintenance mode.

### Apache FreeMarker

- Main page: <https://freemarker.apache.org/index.html>.
- User guide: <https://freemarker.apache.org/docs/dgui.html>.
- Developer guide: <https://freemarker.apache.org/docs/pgui_quickstart.html>.

```text
You are an AI assistant that analyzes research papers. You answer questions about papers.

Here are the papers you are analyzing:
<#list entries as entry>
${CanonicalBibEntry.getCanonicalRepresentation(entry)}
</#list>
```

* Good, because supports plain text templating.
* Good, because it is possible to use `String` as a template.
* Good, because in active development.
* Good, because it is powerful and flexible.
* Neutral, because {argument c}
* Bad, because {argument d}

### Thymeleaf

- Main page: <https://www.thymeleaf.org/>.
- Documentation: <https://www.thymeleaf.org/doc/tutorials/3.1/usingthymeleaf.html>.

Example (not related to AI):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? 😅

```text

Check failure on line 85 in docs/decisions/0039-template-engine.md

View workflow job for this annotation

GitHub Actions / Markdown

Fenced code blocks should be surrounded by blank lines

docs/decisions/0039-template-engine.md:85 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```text"] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md031.md
Dear [(${customer.name})],

This is the list of our products:
[# th:each="p : ${products}"]
- [(${p.name})]. Price: [(${#numbers.formatdecimal(p.price,1,2)})] EUR/kg
[/]
Thanks,
The Thymeleaf Shop
```

* Good, because supports plain text templating.
* Good, because it is possible to use `String` as a template.
* Good, because it has [several template modes](https://www.thymeleaf.org/doc/tutorials/3.1/usingthymeleaf.html#what-kind-of-templates-can-thymeleaf-process), that helps to make HTML, XML, and other templates.
* Good, because it is powerful and flexible.
* Neutral, because the API is a bit more complex than the other options.
* Bad, because {argument d}

## More Information

As stated in [the template discussion issue](https://github.com/koppor/jabref/issues/392), we should choose a template engine, and then slowly migrate previous code and templates to the chosen engine.

<!-- markdownlint-disable-file MD004 -->
Loading