Documentation
¶
Overview ¶
Package page holds the state of one page render and the substitutions that run before ftml sees the source.
Index ¶
- Constants
- func ApplyTemplate(template string, resolve func(name string) (string, bool)) string
- func Buttons(source string) string
- func Galleries(source string) string
- func Inputs(source string) string
- func ListingVars(template string, vars *Vars, index, total int, limit string, shown int) string
- func OutsideModules(source string, hasBody func(name string) bool, fill func(string) string) string
- func PageVars(template string, vars *Vars, index, total int) string
- func PreRender(source string, vars *Vars) string
- func QuoteAll(s string) string
- func RatingMode(siteMode, categoryMode string) string
- func TemplateLayout(source string) string
- func ThisVars(source string, vars *Vars) string
- type Comment
- type Context
- type PathParam
- type PathParams
- type Rating
- type ThemeDrop
- type VarSource
- type Vars
Constants ¶
const ( RatingModeDefault = "default" RatingModeDisabled = "disabled" RatingModeUpDown = "updown" RatingModeStars = "stars" )
Variables ¶
This section is empty.
Functions ¶
func ApplyTemplate ¶
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 ¶
This runs on the source rather than the tree, because the renderer knows modules and does not know buttons.
func ListingVars ¶
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 PageVars ¶
PageVars is the pass the category template goes through, where a variable carries no prefix. index and total exist nowhere else.
func PreRender ¶
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 RatingMode ¶
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 ¶
Types ¶
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 (*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.
type PathParam ¶
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) Put ¶
func (p PathParams) Put(param PathParam) PathParams
type Rating ¶
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
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 (*Vars) Err ¶
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 ¶
Lookup resolves a bare %%name%%. The name is matched exactly, so %%Title%% is not %%title%%.
func (*Vars) SetContent ¶
SetContent hands the variables a source that is not in the database yet, which is what a preview renders.
func (*Vars) SetTagPrefix ¶
A prefix written into the variable itself still wins over this one.