    {-# OPTIONS_GHC -fno-warn-orphans #-}
    {- |
       Module      : Text.Pandoc.Lua.Marshaling.Context
       Copyright   : © 2012-2020 John MacFarlane
                     © 2017-2020 Albert Krewinkel
       License     : GNU GPL, version 2 or above

       Maintainer  : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
       Stability   : alpha

    Marshaling instance for doctemplates Context and its components.
    -}
    module Text.Pandoc.Lua.Marshaling.Context () where

    import qualified Foreign.Lua as Lua
    import Foreign.Lua (Pushable)
    import Text.DocTemplates (Context(..), Val(..), TemplateTarget)
    import Text.DocLayout (render)

    instance (TemplateTarget a, Pushable a) => Pushable (Context a) where
      push :: Context a -> Lua ()
    push (Context m :: Map Text (Val a)
    m) = Map Text (Val a) -> Lua ()
    forall a. Pushable a => a -> Lua ()
    Lua.push Map Text (Val a)
    m

    instance (TemplateTarget a, Pushable a) => Pushable (Val a) where
      push :: Val a -> Lua ()
    push NullVal = () -> Lua ()
    forall a. Pushable a => a -> Lua ()
    Lua.push ()
      push (MapVal ctx :: Context a
    ctx) = Context a -> Lua ()
    forall a. Pushable a => a -> Lua ()
    Lua.push Context a
    ctx
      push (ListVal xs :: [Val a]
    xs) = [Val a] -> Lua ()
    forall a. Pushable a => a -> Lua ()
    Lua.push [Val a]
    xs
      push (SimpleVal d :: Doc a
    d) = a -> Lua ()
    forall a. Pushable a => a -> Lua ()
    Lua.push (a -> Lua ()) -> a -> Lua ()
    forall a b. (a -> b) -> a -> b
    $ Maybe Int -> Doc a -> a
    forall a. HasChars a => Maybe Int -> Doc a -> a
    render Maybe Int
    forall a. Maybe a
    Nothing Doc a
    d