Skip to content

refactor: split template helpers and slug utils out of markdown.go#459

Open
Caesarsage wants to merge 1 commit into
kubernetes-sigs:masterfrom
Caesarsage:refactor/template-helpers-and-utils
Open

refactor: split template helpers and slug utils out of markdown.go#459
Caesarsage wants to merge 1 commit into
kubernetes-sigs:masterfrom
Caesarsage:refactor/template-helpers-and-utils

Conversation

@Caesarsage

Copy link
Copy Markdown
Contributor

Pure relocation; no behavior change. Tests pass without golden updates.

  • New template_helpers.go holds the resource.tmpl parse block + escape, hugoRef, and their regex vars.
  • Slug helpers (anchor, kebabCase, kebabName, groupVersionString, operationSlug, constValueFor) move into the existing util.go.
  • markdown.go drops the moved symbols + now-unused imports.

markdown.go had grown to ~950 lines mixing view-model, writer methods, slug helpers, and template primitives. The extraction lets each file have one concern.

Sets up cleaner ground for the upcoming #440 PRs.

@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Caesarsage
Once this PR has been reviewed and has the lgtm label, please assign onlydole for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow kubernetes-prow Bot requested review from jimangel and onlydole June 21, 2026 10:40
@kubernetes-prow kubernetes-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jun 21, 2026
@lavishpal

Copy link
Copy Markdown
Member

Only wanna understand your intention that why is template_helpers.go a separate file instead of merging into util.go and  also escape() is in template_helpers.go but it's a pure string transform, not template-specific. The template FuncMap could reference it from util.go

// kebabCase lowercases and slugifies any string into a kebab-case identifier
// used for directory and file names.
func kebabCase(s string) string {
return strings.Trim(anchorRegex.ReplaceAllString(strings.ToLower(s), "-"), "-")

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.

operationSlug and kebabCase have identical implementations. is keeping them separate intentional to allow independent divergence later, or should operationSlug just assign to kebabCase

@Caesarsage

Caesarsage commented Jun 27, 2026

Copy link
Copy Markdown
Contributor Author

Only wanna understand your intention that why is template_helpers.go a separate file instead of merging into util.go and  also escape() is in template_helpers.go but it's a pure string transform, not template-specific. The template FuncMap could reference it from util.go

Only wanna understand your intention that why is template_helpers.go a separate file instead of merging into util.go and  also escape() is in template_helpers.go but it's a pure string transform, not template-specific. The template FuncMap could reference it from util.go

Two design choices, each with trade-offs:

On the separate file: template_helpers.go holds the template specific functions registers. They're tightly coupled, anyone wanting to know "what helpers does the template have access to" reads one file end-to-end. Folding into util.go would mix template parsing with the existing PrintInfo diagnostic and slug helpers, three unrelated concerns in one file.

On escape() placement: you're right that it's a pure string transform. So are hugoRef, mdCell, hugoShortcode, and dict, all pure functions whose only caller is the FuncMap. I grouped them with the parse block so the boundary is obvious: "these exist to support the template, reached by these registered names." Moving escape alone to util.go would split the group across files.

@lavishpal

Copy link
Copy Markdown
Member

Make sense.
/lgtm

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants