ogmarkup-5.0: src/Text/Ogmarkup/Private/Config.hs
{-# LANGUAGE AllowAmbiguousTypes #-}
{-|
Module : Text.Ogmarkup.Private.Config
Copyright : (c) Ogma Project, 2016
License : MIT
Stability : experimental
This module provides the 'GenConf' typeclass which is used to configure the
'Text.Ogmarkup.Private.Generator's monad.
-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Text.Ogmarkup.Private.Config where
import Data.Maybe
import Data.Monoid
import Data.String
import Text.Ogmarkup.Private.Typography
-- | A 'Template' is just synonym for a template of one argument.
type Template a = a -> a
-- | An instance of the 'GenConf' typeclass can be given as a parameter to
-- a 'Text.Ogmarkup.Private.Generator.Generator'. In order to prevent GHC
-- to overabstract this typeclass, there can be only one instance of
-- GenConf for one datatype. In other words, one datatype can only handle
-- one return type @c@.
--
-- For each template, we give a prefered layout and some hints about the
-- default implementation (which is almost always the identity function,
-- ignoring all the parameters but the generated output.
--
-- __Warning:__ 'GenConf' is a multiparam typeclass (see
-- @MultiParamTypeClasses@ GHC extension). In order to make new instances,
-- the following extensions need to be enabled:
--
-- * @FlexibleInstances@
-- * @MultiParamTypeClasses@
--
-- Otherwise, GHC will not accept your instance statement.
class (IsString o, Monoid o) => GenConf c o | c -> o where
-- | Returns a 'Typography' instance to be used by the
-- 'Text.Ogmarkup.Private.Generator.Generator'.
--
-- * __Default implementation:__ returns 'englishTypo'.
typography :: Typography o
typography = unicodeEnglishTypo
-- | This template is used once the output has been completely generated.
--
-- * __Layout:__ block
-- * __Default implementation:__ the identity function
documentTemplate :: Template o
documentTemplate = id
-- | This template is used on the ill-formed portion of the ogmarkup
-- document which have been ignored during the best-effort compilation.
--
-- * __Layout:__ inline
-- * __Default implementation:__ the identity function
errorTemplate :: Template o
errorTemplate = id
-- | This template is used on regular sections which focus on telling the
-- story.
--
-- * __Layout:__ block
-- * __Default implementation:__ the identity function
storyTemplate :: Template o
storyTemplate = id
-- | This template is used on aside sections which may comprised
-- flashbacks, letters or songs, for instance.
--
-- * __Layout:__ block
-- * __Default implementation:__ the identity function (it ignores the
-- class name)
asideTemplate :: Maybe o -- ^ An optional class name
-> Template o
asideTemplate _ = id
-- | This template is used on paragraphs within a section.
--
-- * __Layout:__ block
-- * __Default implementation:__ the identity function
paragraphTemplate :: Template o
paragraphTemplate = id
-- | This template is used on the narrative portion of an ogmarkup
-- document.
--
-- * __Layout:__ inline
-- * __Default implementation:__ the identity function
tellerTemplate :: Template o
tellerTemplate = id
-- | This template is used on audible dialogue. The class name is
-- mandatory even if the character name is optional for dialogues and
-- thoughts in the ogmarkup grammar. The `authorNormalize` function is
-- used by the generator to get a default value when no character names
-- are provided.
--
-- * __Layout:__ inline
-- * __Default implementation:__ the identity function
dialogueTemplate :: o -- ^ The class name produced by 'authorNormalize'
-> Template o
dialogueTemplate _ = id
-- | This template is used on unaudible dialogue. See 'dialogueTemplate' to
-- get more information on why the class name is not
-- optional.
--
-- * __Layout:__ inline
-- * __Default implementation:__ the identity function
thoughtTemplate :: o -- ^ The class name produced by 'authorNormalize'
-> Template o
thoughtTemplate _ = id
-- __Default implementation:__ the identity function
replyTemplate :: Template o
replyTemplate = id
-- | Return a marker to insert between two consecutive dialogues. The
-- default use case is to return the concatenation of the ending mark and
-- the opening mark of a paragraph.
-- a paragrap
--
-- * __Layout:__ inline
-- * __Default implementation:__ `mempty`
betweenDialogue :: o
betweenDialogue = mempty
-- | A template to apply emphasis to an piece of text.
--
-- __Default implementation:__ the identity function
emphTemplate :: Template o
emphTemplate = id
-- | A template to apply stong emphasis (often bold) to a piece of text.
--
-- * __Layout:__ inline
-- * __Default implementation:__ `mempty`
strongEmphTemplate :: Template o
strongEmphTemplate = id
-- | This function is called by a Generator to derive a class name for an
-- optional character name.
--
-- * __Default implementation:__ simply unwrap the Maybe value, if
-- Nothing return 'mempty'.
authorNormalize :: Maybe o
-> o
authorNormalize = fromMaybe mempty
-- | Generate an output from a 'Space'.
printSpace :: Space
-> o