gemoire-1.0.1: yet another static gemlog generator + converter
Copyright(c) 2024 Sena
LicenseGPL-3.0-or-later
Maintainercontact@sena.pink
Stabilitystable
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Gemoire.Template

Description

A minimal template parser to use with generated static gemlogs

Gemoire uses its own template system, where the templates are plain texts with special inline components. The valid components are:

  • {$pholder$} - A placeholder with the key pholder
  • {$pholder:default value$} - A placeholder with a default value
  • {&pholder:fallback&} - With a fallback key to use in case pholder has no value
  • {&pholder:fallback:default value&} - With a fallback key and a default value
  • {# comment! #} - An unrendered comment
  • {\ constant \} - An unevaluated block, akin to escaping things inside it

All inline components can be multiline in any way, including placeholder keys. The arguments can also be surrounded by any amount of whitespace, which will get stripped except when specifying a default value.

The surrounding braces are parsed in order, so the components can not be nested.

Synopsis

Formatting

template :: Text -> Template Source #

Construct a Template from the given Text.

See the module description for how the templates are formed.

The whitespaces in the arguments will be stripped except for default values.

The surrounding braces are parsed in order, so the components can not be nested.

format :: Template -> Values -> Text Source #

Format the Template using given Values map.

Types

type Values = HashMap Text Text Source #

An unordered HashMap of formatting keys and values

type Template = [Either Text Component] Source #

A basic template, in the form of a string of either plain text blocks or meaningful components

data Component Source #

A parsed template component with a special meaning

Constructors

Placeholder !Text !(Maybe Text)

A placeholder with an optional default value

Fallback !Text !Text !(Maybe Text)

A placeholder with another key to fallback to if the first one has no value, and an optional default value

Instances

Instances details
Show Component Source # 
Instance details

Defined in Gemoire.Template

Eq Component Source # 
Instance details

Defined in Gemoire.Template

Utility

vempty :: Values Source #

An empty Values map for convenience

vlist :: [(Text, Text)] -> Values Source #

fromList for convenience