headroom-0.4.2.0: License Header Manager
Copyright(c) 2019-2021 Vaclav Svejcar
LicenseBSD-3-Clause
Maintainervaclav.svejcar@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Headroom.Variables

Description

Module containing costructor and useful functions for the Variables data type.

Synopsis

Constructing Variables

mkVariables Source #

Arguments

:: [(Text, Text)]

pairs of key-value

-> Variables

constructed variables

Constructor function for Variables data type.

>>> mkVariables [("key1", "value1")]
Variables (fromList [("key1","value1")])

dynamicVariables Source #

Arguments

:: CurrentYear

current year

-> Variables

map of dynamic variables

Dynamic variables that are common for all parsed files.

  • _current_year - current year

Parsing Variables

parseVariables Source #

Arguments

:: MonadThrow m 
=> [Text]

list of raw variables

-> m Variables

parsed variables

Parses variables from raw input in key=value format.

>>> parseVariables ["key1=value1"]
Variables (fromList [("key1","value1")])

Processing Variables

compileVariables Source #

Arguments

:: forall a m. (Template a, MonadThrow m) 
=> Variables

input variables to compile

-> m Variables

compiled variables

Compiles variable values that are itself mini-templates, where their variables will be substituted by other variable values (if possible). Note that recursive variable reference and/or cyclic references are not supported.

>>> :set -XTypeApplications
>>> import Headroom.Template.Mustache (Mustache)
>>> let compiled = compileVariables @Mustache $ mkVariables [("name", "John"), ("msg", "Hello, {{ name }}")]
>>> let expected = mkVariables [("name", "John"), ("msg", "Hello, John")]
>>> compiled == Just expected
True