page

package
v0.9.0-rc.53 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package page holds the state of one page render and the substitutions that run before ftml sees the source.

Index

Constants

View Source
const (
	RatingModeDefault  = "default"
	RatingModeDisabled = "disabled"
	RatingModeUpDown   = "updown"
	RatingModeStars    = "stars"
)

Variables

This section is empty.

Functions

func ApplyTemplate

func ApplyTemplate(template string, resolve func(name string) (string, bool)) string

ApplyTemplate replaces every %%name%% the resolver knows. An unresolved name is put back verbatim rather than dropped, which is what lets a page carrying %% in its prose survive the pass.

func Buttons

func Buttons(source string) string

This runs on the source rather than the tree, because the renderer knows modules and does not know buttons.

func Galleries

func Galleries(source string) string

func Inputs

func Inputs(source string) string

func ListingVars

func ListingVars(template string, vars *Vars, index, total int, limit string, shown int) string

Limit is empty when the module was given none, and shown is how many rows the listing holds once the limit is applied.

func OutsideModules

func OutsideModules(source string, hasBody func(name string) bool, fill func(string) string) string

func PageVars

func PageVars(template string, vars *Vars, index, total int) string

PageVars is the pass the category template goes through, where a variable carries no prefix. index and total exist nowhere else.

func PreRender

func PreRender(source string, vars *Vars) string

PreRender is everything the source goes through on its way to the renderer. Both passes are blind to code blocks, the way a %% pair in prose already is.

func QuoteAll

func QuoteAll(s string) string

func RatingMode

func RatingMode(siteMode, categoryMode string) string

RatingMode walks the settings chain, where the built-in default is updown and a level that says default hands the question to the level above it.

func TemplateLayout

func TemplateLayout(source string) string

func ThisVars

func ThisVars(source string, vars *Vars) string

ThisVars is the pass an included page goes through. %%this|name%% reaches the page that pulled it in, and every other name is left standing for whatever pass claims it later.

Types

type Comment

type Comment struct {
	At     time.Time
	Author *db.User
}

type Context

type Context struct {
	Article       *db.Article
	SourceArticle *db.Article
	PathParams    PathParams
	User          *db.User

	// The handler owns this because it is the only layer that can also plant
	// the cookie a form needs.
	CSRF string

	// An empty list means every module, which is what an article gets.
	OnlyModules []string

	Title      string
	Status     int
	RedirectTo string
	NoIndex    bool

	Depth int

	Draft bool

	AddCSS         string
	ComputedStyles []string
	DropTheme      ThemeDrop
	OGDescription  string
	OGImage        string
}

Context is the state one render writes back to the page around it. Modules reach it through the render callback, which is why a module can set the HTTP status or redirect the whole page.

func NewContext

func NewContext(article, sourceArticle *db.Article, pathParams PathParams, user *db.User) *Context

func (*Context) CloneWith

func (c *Context) CloneWith(article, sourceArticle *db.Article, pathParams PathParams, user *db.User) *Context

CloneWith starts a nested render. Only the three fields listed carry over: the styles and the Open Graph fields belong to the page that produced them, and Merge is what brings the styles back.

func (*Context) Merge

func (c *Context) Merge(other *Context)

Merge folds a nested render back. ComputedStyles accumulates; the rest is overwritten, so the innermost render decides the status and the title.

type PathParam

type PathParam struct {
	Key   string
	Value string
	Bare  bool
}

A trailing key with nothing after it arrives Bare, which the substitutions answer differently from a key whose value is the empty string.

type PathParams

type PathParams []PathParam

func ParsePathParams

func ParsePathParams(raw string) PathParams

The order the caller wrote is kept, since the variables that read a path print them back in it.

func (PathParams) Get

func (p PathParams) Get(key string) string

func (PathParams) Has

func (p PathParams) Has(key string) bool

func (PathParams) Lookup

func (p PathParams) Lookup(key string) (PathParam, bool)

func (PathParams) Put

func (p PathParams) Put(param PathParam) PathParams

type Rating

type Rating struct {
	Value      any
	Votes      int
	Popularity int
	Mode       string
}

Rating is what the page options carry. Value is an int under updown and a float under stars, and the difference reaches the frontend as written.

func DisabledRating

func DisabledRating() Rating

func RatingOf

func RatingOf(mode string, stats db.VoteStats) Rating

type ThemeDrop

type ThemeDrop int
const (
	KeepTheme ThemeDrop = iota
	DropSiteTheme
	DropAllThemes
)

type VarSource

type VarSource interface {
	LatestSource(articleID int64) (string, error)
	Authors(articleID int64) ([]db.User, error)
	LatestEditor(articleID int64) (*db.User, error)
	RevisionCount(articleID int64) (int, error)
	Tags(articleID int64) ([]string, error)
	VoteStats(articleID int64) (db.VoteStats, error)
	SiteRatingMode() (string, error)
	CategoryRatingMode(category string) (string, error)
	HasVoted(articleID int64, userID *int64) (bool, error)
	ArticleByID(id int64) (*db.Article, error)
	CategoryForm(category string) (*form.Definition, error)
	ChildCount(articleID int64) (int, error)
	CommentCount(articleID int64) (int, error)
	LastComment(articleID int64) (*Comment, error)
	SiteName() string
	SiteTitle() string
	SiteDomain() string
}

VarSource is everything a page variable may have to read. Each method is one query, because a page that mentions no variable must issue none of them.

type Vars

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

Vars resolves the page variables of one article. Every value is computed at most once and only when asked for, because content pulls a whole revision and the rating runs an aggregate.

func NewDraftVars

func NewDraftVars(fullName, title string, user *db.User, src VarSource, loc *i18n.Localizer) *Vars

func NewVars

func NewVars(article *db.Article, user *db.User, src VarSource, loc *i18n.Localizer) *Vars

func (*Vars) Err

func (v *Vars) Err() error

Err reports the first query that failed. A failed lookup leaves the variable unresolved, so the page still renders, with %%name%% in it, unless the caller checks this.

func (*Vars) Lookup

func (v *Vars) Lookup(name string) (string, bool)

Lookup resolves a bare %%name%%. The name is matched exactly, so %%Title%% is not %%title%%.

func (*Vars) SetContent

func (v *Vars) SetContent(source string)

SetContent hands the variables a source that is not in the database yet, which is what a preview renders.

func (*Vars) SetTagPrefix

func (v *Vars) SetTagPrefix(prefix string)

A prefix written into the variable itself still wins over this one.

func (*Vars) This

func (v *Vars) This(param string) (string, bool)

This resolves %%this|name%%, the form an included page uses to reach the page that included it. Unlike a bare name this one is case insensitive and takes no date format.

Jump to

Keyboard shortcuts

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