Documentation
¶
Overview ¶
Package partials hosts the partial functions assembled by the classic template. Each partial is a templates.PartialFunc that takes a PartialContext and returns the SVG fragment it owns.
Partials follow three rules:
- Empty when nil-safe: missing data (e.g. Data.User == nil) must yield "" without panicking.
- XML safety: dynamic strings flow through classic.EscapeXML.
- Magnitude shortening: integer counts flow through classic.FormatCount.
The classic template owns the call order via partials/_.json.
Index ¶
- Variables
- func BaseActivityCommunity(_ context.Context, pc *templates.PartialContext) (string, error)
- func BaseHeader(_ context.Context, pc *templates.PartialContext) (string, error)
- func BaseRepositories(_ context.Context, pc *templates.PartialContext) (string, error)
- func EscapeXML(s string) string
- func FormatCount(n int64) string
- func Introduction(_ context.Context, pc *templates.PartialContext) (string, error)
- func Lookup(name string) (templates.PartialFunc, bool)
- func Register(name string, fn templates.PartialFunc)
- func SetNowForTest(now func() time.Time) func()
Constants ¶
This section is empty.
Variables ¶
var PluginPartialOrder = []string{
"languages",
"activity",
"achievements",
"repositories",
"isocalendar",
"calendar",
"habits",
"stars",
"people",
"notable",
"contributors",
"reactions",
"projects",
"sponsors",
"sponsorships",
"stargazers",
"traffic",
"topics",
"starlists",
}
PluginPartialOrder defines the M4 plugin partial render order. It mirrors the upstream lowlighter/metrics classic ordering: P1 MVP 5 plugins first, then P2 GraphQL/REST 12 plugins, then P3 chromedp/ heavy 4 plugins. classic.go iterates this slice; slugs whose partial is not yet registered are silently skipped during incremental M4 landing so the build stays green between US1/US2/US3 PRs.
Functions ¶
func BaseActivityCommunity ¶
BaseActivityCommunity renders the Activity + Community-stats two-column block, mirroring upstream `base.activity+community.ejs`.
The Activity column shows the lifetime contribution aggregates (commits, PRs reviewed, PRs opened, issues opened, issue comments) sourced from Data.User — the base plugin populates these from the always-fetched User query's `contributionsCollection.*` aggregate fields plus `issueComments.totalCount` (#442), so the section renders for a plain `base` run without requiring an indepth-dependent plugin.
The Community column shows the user-relationship counters (organizations, following, sponsoring, starred, watching) also sourced from Data.User. Per upstream every community row renders unconditionally — including "Sponsoring 0 repositories" — so the column reflects the GitHub profile exactly.
Each column is independently gated by the resolved `base` sections: the Activity column only appears when `activity` is enabled, the Community column only when `community` is enabled. The classic dispatcher already skips this partial entirely when neither flag is set, so reaching here means at least one column is active.
Per #419 the partial returns "" (no wrapper at all) when neither active column has any data — i.e. the base plugin has not populated the User contribution/community counters (the gen-doc-samples base sample, or a degraded GraphQL response). That keeps a base-only render from emitting an empty `<section data-section="activity-community">` band that previously inflated the card height.
func BaseHeader ¶
BaseHeader renders the avatar + display name block at the top of the classic SVG. Returns "" when the User payload is absent.
429 Phase 1: also renders the upstream base.header.ejs sub-row with "Joined GitHub <age>", "Followed by N users", and "Following N users" when those fields are populated. Each row field carries a :octicon-<name>: text marker so the ReplaceOcticons() pipeline step can inject the real SVG path.
493: Restructured to use the upstream two-column layout: left <section> holds joined/followers/following, right <section> holds the contribution calendar and contributed-to count.
func BaseRepositories ¶
BaseRepositories renders the count / stargazers / forks row. Returns "" when Repositories.Count is zero so the section disappears for fresh accounts.
429 Phase 1: also surfaces "N watching" and "N sponsors" sourced from Data.User.{Watching,SponsorshipsAsMaintainer}. Both labels are suppressed when their counter is zero so accounts with no watch/sponsorship activity do not gain noise rows.
429 Phase 2: surfaces "N releases", "N packages", "<disk> used", and the License-preference top-3 row sourced from Data.Computed.Repositories.{Releases,Packages,DiskUsage, LicensePreference}. Each label is hidden when its counter is zero (or the license slice is empty), so the partial stays dense on accounts that lack the corresponding signal.
func EscapeXML ¶
EscapeXML escapes the five XML predefined entities so dynamic strings (login, display name, repository name, etc.) can be safely embedded in the SVG output. The function is intentionally re-entrant: an already-escaped fragment will be re-escaped, which keeps the rule simple — callers must never pre-escape.
func FormatCount ¶
FormatCount renders integer magnitudes with the k/m/b/t short form used by the upstream classic template. It is a thin wrapper around format.Format so callers in this package can stay terse.
func Introduction ¶
Introduction is a stub: the introduction plugin lands in M4. Until then the partial returns "" so the partial dispatch order stays stable.
func Lookup ¶
func Lookup(name string) (templates.PartialFunc, bool)
Lookup returns the registered partial by canonical name. M2 base.* partials are registered during package init(); M4 plugin partials register themselves via Register from their owning plugin package's init(). Returns (nil, false) for unknown names; the classic template treats that as a contract failure for _.json entries and as a silent skip for M4 plugin partials still in flight (US1/US2/US3 land incrementally).
func Register ¶
func Register(name string, fn templates.PartialFunc)
Register adds a PartialFunc under the given name. Subsequent calls with the same name overwrite the previous registration — this is the expected behavior for both the M2 init-based base partial setup and the M4 plugin partial registration path where each plugin package registers itself at process start. Not goroutine-safe; intended to run from init() only.
func SetNowForTest ¶ added in v1.1.0
SetNowForTest overrides the time source used by BaseHeader. The returned function restores the previous value.
Types ¶
This section is empty.