Skip to content

More Handlebars helpers#5937

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

More Handlebars helpers#5937
bubblobill wants to merge 23 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.
Comment thread src/main/java/net/rptools/maptool/util/HandlebarsUtil.java Outdated
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.

@cwisniew

Copy link
Copy Markdown
Member

@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.

current.resolveSibling(path).normalize().toUri().getPath();

Should give you what you want without possibly clobering a \ that a user has in their path (I don't know why they would do that, I just know they like doing things that will break things).

@FullBleed

Copy link
Copy Markdown

json.get(getInfo("client"),"file sync directory") on Windows systems also returns an address that has to be converted.

@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.

current.resolveSibling(path).normalize().toUri().getPath();

Should give you what you want without possibly clobering a \ that a user has in their path (I don't know why they would do that, I just know they like doing things that will break things).

This doesn't work. toUri() from a path adds a _file:\c:_ scheme and keeps the windows \

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

3 participants