diff --git a/src/Text/Glabrous.hs b/src/Text/Glabrous.hs index 3153638..bf4eb4f 100644 --- a/src/Text/Glabrous.hs +++ b/src/Text/Glabrous.hs @@ -161,7 +161,11 @@ fromTagsList ts = fromList $ (,T.empty) <$> ts -- | Build an unset ad hoc 'Context' from the given 'Template'. fromTemplate :: Template -> Context -fromTemplate t = setVariables ((\(Tag e) -> (e,T.empty)) <$> tagsOf t) initContext +fromTemplate t = + setVariables (toPair <$> tagsOf t) initContext + where + toPair (Tag e) = (e,T.empty) + toPair _ = undefined -- | Get a 'Context' from a JSON file. readContextFile :: FilePath -> IO (Maybe Context) diff --git a/src/Text/Glabrous/Types.hs b/src/Text/Glabrous/Types.hs index bf347dc..2031170 100644 --- a/src/Text/Glabrous/Types.hs +++ b/src/Text/Glabrous/Types.hs @@ -6,7 +6,7 @@ module Text.Glabrous.Types where import Data.Aeson #if MIN_VERSION_aeson(2,0,0) -import qualified Data.Aeson.KeyMap as KM +import qualified Data.Aeson.KeyMap as KM #endif import qualified Data.HashMap.Strict as H import qualified Data.Text as T @@ -45,9 +45,9 @@ instance ToJSON Context where instance FromJSON Context where parseJSON (Object o) = return #if MIN_VERSION_aeson(2,0,0) - Context { variables = H.fromList ((\(k,String v) -> (k,v)) <$> H.toList (KM.toHashMapText o)) } + Context { variables = H.fromList (fromJSONString <$> H.toList (KM.toHashMapText o)) } #else - Context { variables = H.fromList ((\(k,String v) -> (k,v)) <$> H.toList o) } + Context { variables = H.fromList (fromJSONString <$> H.toList o) } #endif parseJSON _ = fail "expected an object" @@ -56,3 +56,7 @@ data Result | Partial { template :: !Template, context :: !Context } deriving (Eq, Show) +fromJSONString :: (T.Text,Value) -> (T.Text,T.Text) +fromJSONString (k,String v) = (k,v) +fromJSONString (_,_) = undefined +