Safe Haskell | None |
---|---|
Language | GHC2021 |
Ondim.Extra.Standard
Description
Here we define a "standard library" of useful expansions. Examples in the Haddocks are given for HTML, but they work anagously for any supported format.
Synopsis
- standardMap :: NamespaceMap s
- bind :: HasCallStack => PolyExpansion s
- call :: forall s a. OndimNode a => Expansion s a
- open :: forall s a. OndimNode a => Expansion s a
- with :: forall s a. OndimNode a => Expansion s a
- ifBound :: forall s a. OndimNode a => Expansion s a
- anyBound :: forall s a. OndimNode a => Expansion s a
- matchBound :: forall s a. OndimNode a => Expansion s a
- ignore :: forall s a. OndimNode a => Expansion s a
- scope :: forall s a. OndimNode a => Expansion s a
Documentation
standardMap :: NamespaceMap s Source #
Namespace including all expansions defined in this module.
bind :: HasCallStack => PolyExpansion s Source #
This expansion adds the content of the node's children to the state as a
template. If you're familiar with Heist, it's like Heist's bind
splice.
<e:bind id=greet> Hello, <e:caller.attrs.name />. </e:bind> <e:greet name="Joseph" />
call :: forall s a. OndimNode a => Expansion s a Source #
This expansion calls other expansions.
<e:bind id=test> Hello, world. <e:caller.children /> </e:bind> <e:call id=test> How are you doing? </e:call>
open :: forall s a. OndimNode a => Expansion s a Source #
This expansion renames other expansions inside of it.
<e:bind id=hello>Hello,</e:bind> <e:bind id=world>world.</e:bind> <e:with new-hello="hello" new-world="world"> <e:new-hello /> <e:new-world /> <e:with/>
with :: forall s a. OndimNode a => Expansion s a Source #
This expansion renames other expansions inside of it.
<e:bind id=hello>Hello,</e:bind> <e:bind id=world>world.</e:bind> <e:with new-hello="hello" new-world="world"> <e:new-hello /> <e:new-world /> <e:with/>
ifBound :: forall s a. OndimNode a => Expansion s a Source #
This expansion expands its children depending on whether all the specified expansions are bound or not.
<e:bind id=joseph/> <e:if id="joseph,maria"> 'joseph' AND 'maria' are bound <e:else> 'joseph' OR 'maria' are not bound </e:else> </e:if>
anyBound :: forall s a. OndimNode a => Expansion s a Source #
This expansion expands its children depending on whether any of the specified expansions are bound or not.
<e:bind id=joseph/> <e:any id="joseph,maria"> 'joseph' OR 'maria' are bound <e:else> 'joseph' AND 'maria' are not bound </e:else> </e:any>
matchBound :: forall s a. OndimNode a => Expansion s a Source #
This expansion allows you to case match on the (textual) value of another expansion, or return a (optional) default clause.
<e:bind id=name>joseph</e:bind> <e:match id=name> <e:case maria>A dress</e:case> <e:case joseph>A nice hat</e:case> <e:default>Some shoes</e:default> </e:any>
ignore :: forall s a. OndimNode a => Expansion s a Source #
This expansion always return an empty list of nodes. It may be used for comments that should not be rendered in the output format.
<!-- I'll be rendered as a normal HTML comment --> <e:ignore>But I'll not be rendered in the output at all.</e:ignore>
scope :: forall s a. OndimNode a => Expansion s a Source #
This expansion creates a new scope for the its children, in the sense that the inner state does not leak outside.
For this reason, it can be used to call other expansions with "arguments":
<e:bind id=animal-entry>There is a <e:animal /> with age <e:age /></e:bind> <e:scope> <e:bind id=animal>Lion</e:bind> <e:bind id=age>9 years</e:bind> <e:animal-entry /> <e:scope/> <e:animal /> <!-- "not bound" error! -->