Skip to content

feat(dotprompt-go): add RegisterHelper method for custom template helpers - #636

Open
STiFLeR7 wants to merge 1 commit into
google:mainfrom
STiFLeR7:fix/go-register-helper-501
Open

STiFLeR7 wants to merge 1 commit into
google:mainfrom
STiFLeR7:fix/go-register-helper-501

Conversation

@STiFLeR7

Copy link
Copy Markdown

Summary

  • Adds a public RegisterHelper(name, helper) method on Dotprompt (Go) that stores a custom helper for application on the next Compile/Render, matching the JS implementation's defineHelper(name, fn) fluent API (js/src/dotprompt.ts).
  • Previously, registering a custom helper required passing it via DotpromptOptions.Helpers at construction time; there was no way to add one afterwards through a dedicated method, and the TODO(#501) comment above RegisterHelpers marked this gap.
  • RegisterHelpers (plural, internal pipeline) already applied dp.Helpers and built-ins to a compiled template — this change just adds the missing public single-helper entry point and removes the TODO.

Why

Fixes #501. The Go implementation lacked parity with JS for registering helpers outside of construction-time options, per the issue's acceptance criteria.

Testing

Ran from go/ with Go 1.25 (toolchain pinned by go.mod):

$ go vet ./dotprompt/...
(no output — clean)

$ go test ./... 
ok  	github.com/google/dotprompt/go/dotprompt	15.865s
ok  	github.com/google/dotprompt/go/dotprompt/test	11.443s
?   	github.com/google/dotprompt/go/example	[no test files]

$ gofmt -l dotprompt/dotprompt.go dotprompt/dotprompt_test.go
(no output — clean)

Added TestRegisterHelper covering registration, the fluent-chaining return value, and end-to-end template rendering with the registered helper. All existing tests pass unchanged.

🤖 Generated with Claude Code

@google-cla

google-cla Bot commented Oct 21, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

…pers

Adds a public RegisterHelper(name, helper) method on Dotprompt that stores
a custom helper in dp.Helpers for application on the next Compile/Render,
mirroring the JS implementation's defineHelper(name, fn) fluent API.
Previously the only way to register a custom helper was via the Helpers
field in DotpromptOptions at construction time.

Fixes google#501
@STiFLeR7
STiFLeR7 force-pushed the fix/go-register-helper-501 branch from c4d50e4 to 4bd1406 Compare October 21, 2026 08:40

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add register helpers support in Go Dotprompt

1 participant