Skip to content

More Handlebars helpers#5937

Open
bubblobill wants to merge 22 commits into
RPTools:developfrom
bubblobill:handlebarsHelpers
Open

More Handlebars helpers#5937
bubblobill wants to merge 22 commits into
RPTools:developfrom
bubblobill:handlebarsHelpers

Conversation

@bubblobill

@bubblobill bubblobill commented Feb 12, 2026

Copy link
Copy Markdown
Collaborator

Identify the Bug or Feature request

progresses #4158
fixes #5977

Description of the Change

added handlebars helpers.
added template cache.

  • New class HandlebarsHelpers to contain helpers.
  • Helper registration moved to HandlebarsHelpers.

LibraryTemplateLoader class changes:

Normally it is not noticable, but on consecutive nested calls (i.e. calls to templates inside a template, as used in the include helper), Windows paths break the URL lookup, .e.g. when the first character is checked for / but it is a \.

New helper list;

previously existing helpers
  • StringHelpers:
    • capitalizeFirst,
    • center,
    • cut,
    • defaultIfEmpty,
    • join,
    • ljust,
    • rjust,
    • substring,
    • lower,
    • upper,
    • slugify,
    • stringFormat,
    • stripTags,
    • capitalize,
    • abbreviate,
    • wordWrap,
    • replace,
    • yesno,
    • dateFormat,
    • numberFormat
  • ConditionalHelpers:
    • eq,
    • neq,
    • gt,
    • gte,
    • lt,
    • lte,
    • and,
    • or,
    • not
  • NumberHelpers:
    • isEven
    • isOdd
    • stripes
  • AssignHelper:
    • assign
  • IncludeHelper:
    • include
  • Base64EncodeHelper
    • base64Encode
new helpers
  • Jackson2Helper:
    • json
  • MarkdownHelper:
    • markdown
  • MathsHelpers:
    • add,
    • subtract,
    • multiply,
    • divide,
    • max,
    • min,
    • mod,
    • div,
    • pow,
    • abs,
    • sqrt,
    • tau,
    • pi

Possible Drawbacks

things don't work as I think they should

Documentation Notes

added handlebars helpers.


This change is Reviewable

Added cache.
Moved in-house helpers to a separate class.
Added helpers for mark-down, simple maths, and string comparison.
…lpers

# Conflicts:
#	src/main/java/net/rptools/maptool/util/HandlebarsUtil.java
Comment thread src/main/java/net/rptools/maptool/util/HandlebarsHelpers.java Outdated
Comment thread src/main/java/net/rptools/maptool/util/HandlebarsHelpers.java
Comment thread src/main/java/net/rptools/maptool/util/HandlebarsHelpers.java Outdated
Added HBLogger to helper registrations.
faster).
Added HandlebarsHelperTest with tests for maths helpers.
HandlebarsHelpers;
- added debug logging to maths helpers.
- added number of parameters checks to maths helpers.
- set the MathContext for BigDecimal operations.
- miscellaneous bug fixes to maths helpers.
- improved argument parsing to accept literal array strings, and
named arguments.
StrListFunctionsTest: fixed annoying type cast message.
Comment thread src/main/java/net/rptools/maptool/util/HandlebarsHelpers.java Outdated
Change portrait on mouseover to portrait on stat-sheet.
@Nonnull
public String resolve(@Nonnull final String path) {
var location = current.resolveSibling(path).normalize().toString();
var location = current.resolveSibling(path).normalize().toString().replace('\\', '/');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not needed, please remove and just use / not \ as you are supposed to in a URL! Don't let windows path seperator start infecting things

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This was an effort to get include to work, as somewhere along the line it was being passed a string starting with \.
Removed now.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Example:

com.github.jknack.handlebars.HandlebarsException: Can't parse: LibraryTemplateSource[library=net.rptools.maptool.model.library.addon.AddOnLibrary@63f6c99f, filename=/\sheets\__include-css.hbs]```

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@cwisniew This is the partials path format issue.

Comment thread src/main/java/net/rptools/maptool/util/HandlebarsUtil.java
…lpers

# Conflicts:
#	src/main/resources/net/rptools/maptool/language/i18n.properties
@bubblobill

Copy link
Copy Markdown
Collaborator Author

What the hell - grrrr... I did not close this - damnit

@bubblobill

Copy link
Copy Markdown
Collaborator Author

Reopen damn you

Added Javadoc to getHandlebarsInstance
@bubblobill bubblobill reopened this Apr 3, 2026
@bubblobill

Copy link
Copy Markdown
Collaborator Author

Please stay open

@bubblobill bubblobill requested a review from cwisniew May 13, 2026 02:23
@bubblobill

Copy link
Copy Markdown
Collaborator Author

@cwisniew
LibraryTemplateLoader uses the Path current. Path uses the native filesystem. On Windows this means reverse-obliques as separators which appear in any strings.

AddOnLibrary chokes when given a path containing \.

LibraryTemplateLoader resolve(path) performs resolve using Path.
Thus var location = current.resolveSibling(path).normalize().toString(); returns current\path which is an invalid address for an AddOnLibrary.

Substituting / for \ like current.resolveSibling(path).normalize().toString().replace('\\', '/'); fixes this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Stat Sheet with Handlebars Partials not working at Windows PC due to Invalid Location Exception with /\sheets\myPartial.hbs

2 participants