{-# OPTIONS_GHC -fno-warn-orphans #-}
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 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 Val a
NullVal = () -> Lua ()
forall a. Pushable a => a -> Lua ()
Lua.push ()
push (BoolVal Bool
b) = Bool -> Lua ()
forall a. Pushable a => a -> Lua ()
Lua.push Bool
b
push (MapVal Context a
ctx) = Context a -> Lua ()
forall a. Pushable a => a -> Lua ()
Lua.push Context a
ctx
push (ListVal [Val a]
xs) = [Val a] -> Lua ()
forall a. Pushable a => a -> Lua ()
Lua.push [Val a]
xs
push (SimpleVal 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