components

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2026 License: UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OutboundDocs    = "docs"
	OutboundFaucet  = "faucet"
	OutboundStatus  = "status"
	OutboundGitHub  = "github"
	OutboundTwitter = "twitter"
	OutboundDiscord = "discord"
	OutboundYouTube = "youtube"
)

Outbound* labels are emitted as data-outbound on tagged links so the SimpleAnalytics auto-events script fires outbound_<label> events. The set must stay in sync with the enum in frontend/js/analytics.ts and the values documented in SIMPLEANALYTICS.md.

View Source
const (
	SourceViewType ViewType = "source-view"
	ReadmeFileName string   = "README.md"
)
View Source
const (
	UserContributionTypeRealm = iota
	UserContributionTypePackage
)
View Source
const MaxBannerLength = 400

MaxBannerLength is the maximum character length for banner markdown source.

View Source
const RedirectViewType = "redirect-view"

Variables

View Source
var ReLicenseFileName *regexp.Regexp = regexp.MustCompile(`(?i)^licen[cs]e(.md|.txt)?$`)

Functions

func ClassifyPageType

func ClassifyPageType(mode ViewMode, view ViewType) string

ClassifyPageType returns the page-type label for a given mode and view. View type takes precedence over mode: a Source view inside a Realm mode is classified as "source", not "realm", so the analytics label matches the rendered surface rather than the containing layout mode.

func FormatRelativeTimeSince

func FormatRelativeTimeSince(t time.Time) string

func RenderBreadcrumbComponent

func RenderBreadcrumbComponent(w io.Writer, data BreadcrumbData) error

Types

type AnalyticsData

type AnalyticsData struct {
	Enabled  bool
	PageType string
	// Path is the analytics pageview path (see analyticsPath) rendered as
	// data-sa-path; the client reports it to SimpleAnalytics in place of the
	// raw pathname.
	Path       string
	ChainId    string
	AssetsPath string
	BuildTime  string
	// Hostname, when non-empty, is rendered as data-hostname on the
	// SimpleAnalytics script tag to override the hostname SA reports.
	// Set this when the site listens on a host SA would otherwise report
	// incorrectly (for example a non-default port in local development).
	Hostname string
}

AnalyticsData holds the SimpleAnalytics metadata rendered into the page.

type ArticleData

type ArticleData struct {
	ComponentContent Component
	Classes          string
}

type BannerData

type BannerData struct {
	// contains filtered or unexported fields
}

BannerData holds pre-rendered inline HTML from markdown.

func NewBannerData

func NewBannerData(markdown, globalURL string) (BannerData, error)

NewBannerData parses inline markdown into a BannerData with pre-rendered HTML. Content after the first newline is discarded. Content is truncated to MaxBannerLength runes. If globalURL is non-empty (http/https only), the banner acts as a single clickable link and any inline markdown links are unwrapped to plain text.

func (BannerData) Enabled

func (b BannerData) Enabled() bool

func (BannerData) HasURL

func (b BannerData) HasURL() bool

func (BannerData) Render

func (b BannerData) Render(w io.Writer) (err error)

func (BannerData) URL

func (b BannerData) URL() string
type BreadcrumbData struct {
	Parts    []BreadcrumbPart
	ArgParts []BreadcrumbPart
	Queries  []QueryParam
}
type BreadcrumbPart struct {
	Name string
	URL  string
}

type CommandData

type CommandData struct {
	FuncName   string
	PkgPath    string
	ParamNames []string
	ChainId    string
	Remote     string
}

type Component

type Component interface {
	Render(w io.Writer) error
}

func IndexLayout

func IndexLayout(data IndexData) Component

func NewReaderComponent

func NewReaderComponent(reader io.Reader) Component

func NewTemplateComponent

func NewTemplateComponent(name string, data any) Component

type DirData

type DirData struct {
	PkgPath     string
	FileCounter int
	FilesLinks  FilesLinks
	Mode        ViewMode
	Readme      Component
}

type DirLinkType

type DirLinkType int
const (
	DirLinkTypeSource DirLinkType = iota
	DirLinkTypeFile
)

func (DirLinkType) LinkPrefix

func (d DirLinkType) LinkPrefix(pkgPath string) string

LinkPrefix returns the prefixed link depending on link type

type DocRenderer

type DocRenderer interface {
	RenderDocumentation(w io.Writer, src []byte) error
	RenderSource(w io.Writer, name string, src []byte) error
}

DocRenderer renders markdown doc strings and source code to HTML. RenderSource applies syntax highlighting based on the file extension in name. Implementations must be safe for concurrent use and HTML-safe by construction.

type FileClass

type FileClass struct {
	IsGno     bool
	IsTest    bool
	IsReadme  bool
	IsLicense bool
}

FileClass holds boolean classification flags for a package file name. IsGno is true for test files too (they end in ".gno").

func ClassifyFile

func ClassifyFile(name string) FileClass

ClassifyFile categorizes a file name once so callers don't re-implement the suffix checks. ReLicenseFileName is the shared license-name matcher.

type FileFetcher

type FileFetcher interface {
	Fetch(ctx context.Context, pkgPath, fileName string, height int64) ([]byte, error)
}

FileFetcher reads a single file from a package. `height = 0` queries the latest block; a positive value pins to that historical height.

type FileLink struct {
	Name      string
	Link      string
	IsTest    bool
	IsReadme  bool
	IsLicense bool
}

FileLink is a file entry rendered in the Files section.

type FilesLinks []FullFileLink

FilesLinks is a slice of FullFileLink

type FooterData

type FooterData struct {
	Analytics   AnalyticsData
	Sections    []FooterSection
	LegalNotice string
	LegalLinks  []FooterLink
}

func EnrichFooterData

func EnrichFooterData(data FooterData) FooterData
type FooterLink struct {
	Label string
	URL   string
	// Outbound, when set to one of the Outbound* constants, is rendered as
	// data-outbound on the link so SimpleAnalytics fires a named
	// outbound_<label> event instead of an anonymous outbound click.
	Outbound string
}

type FooterSection

type FooterSection struct {
	Title string
	Links []FooterLink
}
type FullFileLink struct {
	Link string
	Name string
}

FullFileLink represents a package entry in the directory listing.

type FuncEntry

type FuncEntry struct {
	Name               string
	SignatureComponent Component
	Doc                Component
	Receiver           string
	Crossing           bool
	IsMethod           bool
	ActionURL          string
	AnchorID           string
	SourceURL          string // links to the exact file + line in source view
}

FuncEntry is the view-owned representation of a function or method.

type HeadData

type HeadData struct {
	Title             string
	Description       string
	Canonical         string
	Image             string
	URL               string
	ChromaPath        string
	AssetsPath        string
	AnalyticsHostname string
	Remote            string
	ChainId           string
	BuildTime         string
}

type HeaderData

type HeaderData struct {
	RealmPath  string
	RealmURL   weburl.GnoURL
	Breadcrumb BreadcrumbData
	Links      HeaderLinks
	ChainId    string
	Remote     string
	Mode       ViewMode
	Static     bool
}

func EnrichHeaderData

func EnrichHeaderData(data HeaderData, mode ViewMode) HeaderData
type HeaderLink struct {
	Label    string
	URL      string
	Icon     string
	IsActive bool
	// Outbound, when set to one of the Outbound* constants, is rendered as
	// data-outbound on the link so SimpleAnalytics fires a named
	// outbound_<label> event instead of an anonymous outbound click.
	Outbound string
}
func StaticHeaderDevLinks(u weburl.GnoURL, mode ViewMode, static bool) []HeaderLink
func StaticHeaderGeneralLinks() []HeaderLink
type HeaderLinks struct {
	General []HeaderLink
	Dev     []HeaderLink
}

type HelpData

type HelpData struct {
	// Selected function
	SelectedFunc string
	SelectedArgs map[string]string
	SelectedSend string

	RealmName   string
	Functions   []HelpFunction
	ChainId     string
	Remote      string
	PkgPath     string
	PkgFullPath string
	Doc         Component
	Domain      string
	Origin      string // request scheme+host; makes help URLs shareable
}

type HelpFunction

type HelpFunction struct {
	*doc.JSONFunc
	DocComponent Component
}

HelpFunction pairs a doc.JSONFunc with its documentation already rendered as an HTML Component, so the template can embed it via `{{ render . }}`.

type HelpTocData

type HelpTocData struct {
	Icon  string
	Items []HelpTocItem
}

type HelpTocItem

type HelpTocItem struct {
	Link string
	Text string
}
type ImportLink struct {
	Path string
	Kind string // "stdlib" | "package" | "realm" | "external"
	Link string
}

ImportLink is a dependency edge rendered in the Imports section.

type IndexData

type IndexData struct {
	HeadData
	HeaderData
	FooterData
	BodyView *View
	Mode     ViewMode
	Theme    string
	Banner   BannerData
}

type License

type License struct {
	Kind     string
	FileName string
}

License describes a detected license file. Kind is empty when the file exists but its license type is unknown.

type OverviewData

type OverviewData struct {
	PkgPath    string
	Title      string
	Synopsis   string
	PackageDoc Component
	Readme     Component

	Info    PackageInfo
	Stats   PackageStats
	Quality PackageQuality

	Funcs       []FuncEntry
	Types       []TypeEntry
	Consts      []ValueGroup
	Vars        []ValueGroup
	Imports     []ImportLink
	Files       []FileLink
	Subpackages []SubpackageLink
	Bugs        []string

	// SymbolsTruncated is set when funcs/types/values were capped at
	// maxOverviewSymbols; the template then shows a "view full source" notice.
	SymbolsTruncated bool

	ComponentTOC Component
}

OverviewData is the full payload passed to the overview template.

func BuildOverview

func BuildOverview(in OverviewInput) OverviewData

BuildOverview is pure: given fetched inputs, it returns the rendered OverviewData.

type OverviewInput

type OverviewInput struct {
	URL         *weburl.GnoURL
	Files       []string
	Doc         *doc.JSONDocumentation
	Sources     map[string][]byte
	Subpaths    []string
	Readme      Component
	Domain      string
	DocRenderer DocRenderer
}

OverviewInput aggregates the data required to build an OverviewData.

type PackageInfo

type PackageInfo struct {
	Namespace   string
	PackagePath string
	PackageType string // "realm" | "pure"
	License     License
	GnoVersion  string
	Creator     string // gnomod [addpkg] creator address (on-chain deploys)
	Height      int    // gnomod [addpkg] deploy block height
	Draft       bool   // gnomod draft = not production-ready
	Private     bool   // gnomod private
}

PackageInfo carries identity metadata displayed in the sidebar.

type PackageQuality

type PackageQuality struct {
	HasReadme  bool
	HasTests   bool
	HasLicense bool
	HasPkgDoc  bool
}

PackageQuality exposes boolean presence flags used to render ✓/✗ indicators.

type PackageStats

type PackageStats struct {
	FileCount     int
	GnoFileCount  int
	TestCount     int
	FuncCount     int
	ExportedFunc  int
	TypeCount     int
	ConstCount    int
	VarCount      int
	ImportCount   int
	CrossingCount int
}

PackageStats aggregates numeric counters derived from files and qdoc.

type QueryParam

type QueryParam struct {
	Key   string
	Value string
}

type RealmData

type RealmData struct {
	ComponentContent Component
	TocItems         *RealmTOCData
}

type RealmTOCData

type RealmTOCData struct {
	Items []*TocItem
}

type RedirectData

type RedirectData struct {
	To        string
	Analytics AnalyticsData
}

type SnippetHighlighter

type SnippetHighlighter interface {
	Render(fileName string, source []byte) (template.HTML, error)
}

SnippetHighlighter returns template.HTML so the result is treated as already-safe markup by html/template.

type SourceData

type SourceData struct {
	PkgPath      string
	Files        []string
	FileName     string
	FileSize     string
	FileLines    int
	FileCounter  int
	FileDownload string
	FileSource   Component
}

SourceData holds data for rendering a source code view.

func (SourceData) ArticleClasses

func (d SourceData) ArticleClasses() string

ArticleClasses returns the CSS classes based on file type.

func (SourceData) WrappedSource

func (d SourceData) WrappedSource() Component

WrappedSource wraps the rendered file content in an element carrying the copy target. README.md is rendered markdown (not code), so it uses a plain wrapper; every other file uses the code frame. Both expose data-copy-target so the header Copy button has something to read.

type SourceTocData

type SourceTocData struct {
	Icon         string
	OverviewLink string
	ReadmeFile   SourceTocItem
	LicenseFile  SourceTocItem
	GnoFiles     []SourceTocItem
	GnoTestFiles []SourceTocItem
	TomlFiles    []SourceTocItem
}

type SourceTocItem

type SourceTocItem struct {
	Link string
	Text string
}

SourceTocItem represents an item in the source view table of contents.

type StatusData

type StatusData struct {
	Title      string
	Body       string
	ButtonURL  string
	ButtonText string
}

StatusData holds the dynamic fields for the "status" template

type SubpackageLink struct {
	Name     string
	Path     string
	Synopsis string
}

SubpackageLink is a direct child package rendered in the Subdirectories section.

type TemplateComponent

type TemplateComponent struct {
	// contains filtered or unexported fields
}

func (*TemplateComponent) Render

func (c *TemplateComponent) Render(w io.Writer) error

type TocItem

type TocItem struct {
	Title string
	ID    string
	// Icon is an optional sprite id suffix (e.g. "kind-func") rendered as a
	// leading kind glyph. Empty means no glyph — realm/action/source TOCs leave
	// it unset, so only the package overview surfaces icons.
	Icon  string
	Items []*TocItem
}

TocItem represents a table of contents item for the components package.

func (TocItem) Anchor

func (i TocItem) Anchor() string

Anchor returns the anchor link for this ToC item.

type TypeEntry

type TypeEntry struct {
	Name               string
	SignatureComponent Component
	Doc                Component
	Kind               string
	Methods            []FuncEntry
	AnchorID           string
	SourceURL          string
}

TypeEntry is the view-owned representation of a type declaration.

type UserContribution

type UserContribution struct {
	Title       string
	URL         string
	Type        UserContributionType
	Description string
	Size        int
	Date        *time.Time
}

type UserContributionType

type UserContributionType int

func (UserContributionType) String

func (typ UserContributionType) String() string

type UserData

type UserData struct {
	Username      string
	Handlename    string
	Bio           string
	Teams         []struct{}
	Links         []UserLink
	Contributions []UserContribution
	PackageCount  int
	RealmCount    int
	PureCount     int
	Content       Component
}

UserData contains data for the user view

type UserLink struct {
	Type  UserLinkType
	URL   string
	Title string
}

type UserLinkType

type UserLinkType string
const (
	UserLinkTypeGithub   UserLinkType = "github"
	UserLinkTypeTwitter  UserLinkType = "twitter"
	UserLinkTypeDiscord  UserLinkType = "discord"
	UserLinkTypeTelegram UserLinkType = "telegram"
	UserLinkTypeLink     UserLinkType = "link"
)

type ValueGroup

type ValueGroup struct {
	Kind               string // "const" | "var"
	Names              string
	SignatureComponent Component
	Doc                Component
	AnchorID           string
	SourceURL          string
}

ValueGroup is a const/var declaration group preserving source order.

type View

type View struct {
	Type ViewType
	Component
}

View represents a UI component with a type and underlying component.

func DirectoryView

func DirectoryView(pkgPath string, files []string, fileCounter int, linkType DirLinkType, mode ViewMode, readme ...Component) *View

DirectoryView creates a directory view

func HelpView

func HelpView(data HelpData) *View

func NewTemplateView

func NewTemplateView(typ ViewType, name string, data any) *View

NewTemplateView creates a new View with a template component and data.

func OverviewView

func OverviewView(data OverviewData) *View

OverviewView constructs a new overview View from pre-built data.

func RealmView

func RealmView(data RealmData) *View

func RedirectView

func RedirectView(data RedirectData) *View

func SourceView

func SourceView(data SourceData) *View

SourceView creates a new View for displaying source code and its table of contents.

func StatusErrorComponent

func StatusErrorComponent(message string) *View

StatusErrorComponent returns a view for error scenarios with a message.

func StatusNoRenderComponent

func StatusNoRenderComponent(pkgPath string) *View

StatusNoRenderComponent returns a view for non-error notifications when Render() is not implemented.

func UserView

func UserView(data UserData) *View

UserView creates a new user view component

func (*View) Render

func (v *View) Render(w io.Writer) error

Render renders the view to the provided writer.

func (*View) String

func (v *View) String() string

type ViewMode

type ViewMode int

ViewMode represents the current view mode of the application It affects the layout, navigation, and display of content

const (
	ViewModeExplorer ViewMode = iota // For exploring packages and paths
	ViewModeRealm                    // For realm content display
	ViewModePackage                  // For package content display
	ViewModeHome                     // For home page display
	ViewModeUser                     // For user page display
)

func (ViewMode) IsExplorer

func (m ViewMode) IsExplorer() bool

View mode predicates

func (ViewMode) IsHome

func (m ViewMode) IsHome() bool

func (ViewMode) IsPackage

func (m ViewMode) IsPackage() bool

func (ViewMode) IsRealm

func (m ViewMode) IsRealm() bool

func (ViewMode) IsUser

func (m ViewMode) IsUser() bool

func (ViewMode) ShouldShowDevTools

func (m ViewMode) ShouldShowDevTools() bool

ShouldShowDevTools returns whether dev tools should be shown for this mode

func (m ViewMode) ShouldShowGeneralLinks() bool

ShouldShowGeneralLinks returns whether general navigation links should be shown

type ViewType

type ViewType string

ViewType represents the type of a view component.

const DirectoryViewType ViewType = "dir-view"
const HelpViewType ViewType = "help-view"
const OverviewViewType ViewType = "overview-view"
const RealmViewType ViewType = "realm-view"
const StateViewType ViewType = "state-view"

StateViewType identifies the state-explorer body view so layout_index.go can branch on it (dev-mode chrome) without importing feature/state, which would create a cycle: feature/state already imports components.

The canonical Kind* constants and OID helpers (TruncOID, ShortenOID) live in feature/state — components is no longer in that path.

const StatusViewType ViewType = "status-view"
const UserViewType ViewType = "user-view"

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL