| Copyright | (c) Nathan Bloomfield 2017 |
|---|---|
| License | GPL-3 |
| Maintainer | nbloomf@gmail.com |
| Stability | experimental |
| Safe Haskell | None |
| Language | Haskell2010 |
Hakyll.Shortcode.Service.Example
Description
Do you want to make more shortcodes? Of course, we all do.
This module demonstrates how to implement a type-safe shortcode. The basic steps are as follows:
- Define a type
twhich represents the state of a shortcode. Typicallytwill be a record type, and the fields should all be Maybes or Lists of instances of theValidateclass. - Define a default instance of your shortcode state. This may
consist of a bunch of
Nothings and[]s, or maybe you prefer nontrivial defaults. This is theemptycodemethod of theShortcodeclass. - Declare the usable keys for your shortcode by giving a list of
'ShortcodeAttribute t's. This type lets us define our keys in
a declarative way, sort of like GetOpt. This is the
attributesmethod of theShortcodeclass. - Provide a map
t -> String, to be used to convert abstract shortcodes to their expanded form. This is theembedcodemethod of theShortcodeclass. - Last but not least, declare which tag will be used to name your shortcode.
And that's it! The shortcode API and type library will take care of
parsing, validation, and sanitization for you, giving you a function
String -> String that expands your new shortcode while making sure
only input conforming to your type model is allowed.
Now let's walk through a sample shortcode module. To read along, view the source of this module.
Documentation
expandExampleShortcodes :: String -> String Source #
This is the function that finds and replaces example
shortcodes. It is just a type-specific version of the
expandShortcodes function, that takes a shortcode specification
and generates a find-and-replace function for it.