Moves the code for injecting the base tag to after templates have been applied instead of when they are read.
This is necessary because the syntax for including partial templates is {{> path}}
but the Jsoup code that adds the <base> tag normalises this strictly invalid HTML to {{> path}}
which makes it an invalid Handlebars template.
Adds a Handlebars TemplateLoader that loads from lib:// URLs.
Because the templates are already publicly exported from add-ons,
and they can load css from other files with relative URLs
it is natural to support loading partial templates the same way.
It is implemented as a URL loader which is aware of the path of the template being loaded
and interprets relative paths as relative to the directory.
As-implemented, absolute paths can load content from other add-ons, but this could be prevented by adjusting the prefix and current paths.
lib:// URIs were used to implement it as a URLTemplateLoader because handlebars.java already had a URL-based loader
and it was less intrusive to pass the URL around.
It would instead be possible to define a loader that uses a reference to the library which would have the benefit of allowing non-public templates, and bypasses the URL fetch machinery, but it may be useful to permit add-ons to depend on each other.
The & CSS selector didn't work when I created the examples, but may be available by the time you read this. It doesn't hurt to try it and see.
Which was probably due to the base tag being added before templates are parsed.
Release Notes
Fixed handlebars templates being mis-parsed if they were not strictly HTML.
Added support for loading partial handlebars templates with the {{> path}} syntax, which includes the contents of the named partial template file in the current template. If the path is an absolute path the first component is the library namespace. If the path is a relative path it is in the same directory as the template.
Adds the include helper, e.g. {{include "foo" bar=baz}} will include the partial template "foo" with the context altered to set bar to the value of baz in the current context.
Identify the Bug or Feature request
closes https://github.com/RPTools/maptool/issues/4920
Description of the Change
This has two major changes:
Moves the code for injecting the base tag to after templates have been applied instead of when they are read.
This is necessary because the syntax for including partial templates is
{{> path}}
but the Jsoup code that adds the<base>
tag normalises this strictly invalid HTML to{{> path}}
which makes it an invalid Handlebars template.Adds a Handlebars TemplateLoader that loads from lib:// URLs.
Because the templates are already publicly exported from add-ons, and they can load css from other files with relative URLs it is natural to support loading partial templates the same way.
It is implemented as a URL loader which is aware of the path of the template being loaded and interprets relative paths as relative to the directory. As-implemented, absolute paths can load content from other add-ons, but this could be prevented by adjusting the prefix and current paths.
See https://gitlab.com/richardmaw/maptool-bar-test/-/tree/main/mtlib/library/public/sheets/basic for an example stat sheet that uses partial templates.
Possible Drawbacks
lib:// URIs were used to implement it as a URLTemplateLoader because handlebars.java already had a URL-based loader and it was less intrusive to pass the URL around.
It would instead be possible to define a loader that uses a reference to the library which would have the benefit of allowing non-public templates, and bypasses the URL fetch machinery, but it may be useful to permit add-ons to depend on each other.
Documentation Notes
In https://wiki.rptools.info/index.php/Stat_Sheet_Tutorial there is a comment:
Which was probably due to the base tag being added before templates are parsed.
Release Notes
{{> path}}
syntax, which includes the contents of the named partial template file in the current template. If the path is an absolute path the first component is the library namespace. If the path is a relative path it is in the same directory as the template.include
helper, e.g.{{include "foo" bar=baz}}
will include the partial template"foo"
with the context altered to set bar to the value of baz in the current context.This change is