Extract template functions into their own package #159

Closed
opened 2026-10-07 11:48:38 +00:00 by aniram · 0 comments
Owner

About 150 lines of main.go are the template FuncMap plus ptMonths, ptMonthsShort and formatDate. None of this is relevant to startup. Move it to something like internal/web/tmplfuncs (or internal/handler/tmpl) exposing FuncMap() template.FuncMap, and add a LoadTemplates(root string) helper that does the ParseFS call.

While moving, fix these:

regexp.MustCompile is called inside grepFilename and extractSocialMedia on every invocation. Hoist them to package-level vars.
formatDatePTLong repeats the same case for 6 types. Consider a small interface (anything with Day(), Month(), Year()) to collapse it.
The dict error messages are inconsistent ("failed call to…" vs "failed to call…").

Acceptance criteria:

  • Unit tests cover the date formatters (including the default branches), dict (odd args, non-string key) and formatMoneyFromDB. (TODO)
  • Rendered output of existing pages is unchanged.
About 150 lines of main.go are the template FuncMap plus ptMonths, ptMonthsShort and formatDate. None of this is relevant to startup. Move it to something like internal/web/tmplfuncs (or internal/handler/tmpl) exposing FuncMap() template.FuncMap, and add a LoadTemplates(root string) helper that does the ParseFS call. While moving, fix these: regexp.MustCompile is called inside grepFilename and extractSocialMedia on every invocation. Hoist them to package-level vars. formatDatePTLong repeats the same case for 6 types. Consider a small interface (anything with Day(), Month(), Year()) to collapse it. The dict error messages are inconsistent ("failed call to…" vs "failed to call…"). Acceptance criteria: - Unit tests cover the date formatters (including the default branches), dict (odd args, non-string key) and formatMoneyFromDB. (TODO) - Rendered output of existing pages is unchanged.
aniram added this to the 2027.1 milestone 2026-10-07 11:50:41 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
overdrives/chambersbr#159
No description provided.