{-# LANGUAGE TemplateHaskellQuotes, DeriveLift, DeriveGeneric #-}
module Metadata.Drasil.DrasilMeta where
import Data.Aeson (decodeFileStrict, FromJSON, ToJSON)
import GHC.Generics (Generic)
import Language.Haskell.TH.Syntax (Lift, addDependentFile)
import Language.Haskell.TH (Exp, Q, runIO)
newtype DrasilMeta = DrasilMeta {DrasilMeta -> String
version :: String} deriving ((forall x. DrasilMeta -> Rep DrasilMeta x)
-> (forall x. Rep DrasilMeta x -> DrasilMeta) -> Generic DrasilMeta
forall x. Rep DrasilMeta x -> DrasilMeta
forall x. DrasilMeta -> Rep DrasilMeta x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. DrasilMeta -> Rep DrasilMeta x
from :: forall x. DrasilMeta -> Rep DrasilMeta x
$cto :: forall x. Rep DrasilMeta x -> DrasilMeta
to :: forall x. Rep DrasilMeta x -> DrasilMeta
Generic, Int -> DrasilMeta -> ShowS
[DrasilMeta] -> ShowS
DrasilMeta -> String
(Int -> DrasilMeta -> ShowS)
-> (DrasilMeta -> String)
-> ([DrasilMeta] -> ShowS)
-> Show DrasilMeta
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DrasilMeta -> ShowS
showsPrec :: Int -> DrasilMeta -> ShowS
$cshow :: DrasilMeta -> String
show :: DrasilMeta -> String
$cshowList :: [DrasilMeta] -> ShowS
showList :: [DrasilMeta] -> ShowS
Show, (forall (m :: * -> *). Quote m => DrasilMeta -> m Exp)
-> (forall (m :: * -> *).
Quote m =>
DrasilMeta -> Code m DrasilMeta)
-> Lift DrasilMeta
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => DrasilMeta -> m Exp
forall (m :: * -> *). Quote m => DrasilMeta -> Code m DrasilMeta
$clift :: forall (m :: * -> *). Quote m => DrasilMeta -> m Exp
lift :: forall (m :: * -> *). Quote m => DrasilMeta -> m Exp
$cliftTyped :: forall (m :: * -> *). Quote m => DrasilMeta -> Code m DrasilMeta
liftTyped :: forall (m :: * -> *). Quote m => DrasilMeta -> Code m DrasilMeta
Lift)
instance ToJSON DrasilMeta
instance FromJSON DrasilMeta
drasilMetaCfg :: Q Exp
drasilMetaCfg :: Q Exp
drasilMetaCfg = do
let fp :: String
fp = String
"lib/Metadata/Drasil/DrasilMetadata.json"
Maybe DrasilMeta
maybeDM <- IO (Maybe DrasilMeta) -> Q (Maybe DrasilMeta)
forall a. IO a -> Q a
runIO (String -> IO (Maybe DrasilMeta)
forall a. FromJSON a => String -> IO (Maybe a)
decodeFileStrict String
fp :: IO (Maybe DrasilMeta))
String -> Q ()
addDependentFile String
fp
[|fromMaybe (error "could not read in the drasil metadata file") maybeDM|]