mathiassm
Safe HaskellNone
LanguageGHC2024

MathiasSM.Context.Data

Description

Generic data files: any YAML under contentdata, exposed to templates.

Each file becomes a template context named after its path (directories joined with -, extension dropped). A file holding a top-level list is looped with $for(name)$; a top-level map is read with $name.key$ (nested maps flatten to dotted keys). Scalars render as strings.

A list item with _show: false is left out of the loop entirely.

Any scalar field whose name contains icon also gets two derived fields: fieldHref (the icon URL) and fieldRaw (the SVG markup, inlined).

Synopsis

Documentation

dataContext :: SiteConfig -> Context a Source #

A dynamic context for every data file under dataDir

Pure helpers (also used by the tests)

renderScalar :: Value -> String Source #

A scalar as the string templates should see

scalarString :: Value -> Maybe String Source #

The text of a scalar value, if it is one

iconName :: Value -> Maybe String Source #

The bare name of an icon value, if it is a string

lookupLeaf :: String -> Value -> Maybe Value Source #

The dotted path of a scalar leaf inside a value, if any

isShown :: Value -> Bool Source #

Whether a list item should appear: only an explicit _show: false hides it

nameToRelPath :: String -> FilePath Source #

The file name (directories joined with -) is a path relative to dataDir

breakOnDot :: String -> (String, String) Source #

The key up to the first dot, and the dotted path after it

data IconVariant Source #

Whether a key names a derived icon field (baseHref / baseRaw)

Constructors

Href 
Raw 

Instances

Instances details
Show IconVariant Source # 
Instance details

Defined in MathiasSM.Context.Data

Eq IconVariant Source # 
Instance details

Defined in MathiasSM.Context.Data

checkAgainstSchema :: Value -> Value -> Either [String] () Source #

Validates value against schema, returning the rendered violations