heist 0.14.1.2 → 0.14.1.3
raw patch · 5 files changed
+53/−4 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Heist.Internal.Types: [_numNamespacedTags] :: HeistState m -> Int
+ Heist.Internal.Types: incNamespacedTags :: Monad m => HeistT n m ()
- Heist.Internal.Types: HeistState :: HashMap Text (HeistT m m Template) -> HashMap TPath DocumentFile -> HashMap Text (HeistT m IO (DList (Chunk m))) -> !(HashMap TPath ([Chunk m], MIMEType)) -> HashMap Text (AttrSplice m) -> Bool -> TPath -> Int -> [DocType] -> Maybe FilePath -> KeyGen -> Bool -> Markup -> Text -> [Text] -> Bool -> HeistState m
+ Heist.Internal.Types: HeistState :: HashMap Text (HeistT m m Template) -> HashMap TPath DocumentFile -> HashMap Text (HeistT m IO (DList (Chunk m))) -> !(HashMap TPath ([Chunk m], MIMEType)) -> HashMap Text (AttrSplice m) -> Bool -> TPath -> Int -> [DocType] -> Maybe FilePath -> KeyGen -> Bool -> Markup -> Text -> [Text] -> Bool -> Int -> HeistState m
Files
- heist.cabal +1/−1
- src/Heist.hs +1/−1
- src/Heist/Compiled/Internal.hs +22/−2
- src/Heist/Internal/Types/HeistState.hs +8/−0
- test/suite/Heist/Compiled/Tests.hs +21/−0
heist.cabal view
@@ -1,5 +1,5 @@ name: heist-version: 0.14.1.2+version: 0.14.1.3 synopsis: An Haskell template system supporting both HTML5 and XML. description: Heist is a powerful template system that supports both HTML5 and XML.
src/Heist.hs view
@@ -202,7 +202,7 @@ -- | Creates an empty HeistState. emptyHS :: HE.KeyGen -> HeistState m emptyHS kg = HeistState Map.empty Map.empty Map.empty Map.empty Map.empty- True [] 0 [] Nothing kg False Html "" [] False+ True [] 0 [] Nothing kg False Html "" [] False 0 ------------------------------------------------------------------------------
src/Heist/Compiled/Internal.hs view
@@ -29,6 +29,7 @@ import qualified Data.Text as T import qualified Data.Text.Encoding as T import qualified Data.Vector as V+import Text.Printf import qualified Text.XmlHtml as X import qualified Text.XmlHtml.HTML.Meta as X ------------------------------------------------------------------------------@@ -161,12 +162,28 @@ -> IO (Either [String] (HeistState n)) compileTemplates hs = do (tmap, hs') <- runHeistT compileTemplates' (X.TextNode "") hs+ let pre = _splicePrefix hs'+ let nsErr = if not (T.null pre) && (_numNamespacedTags hs' == 0)+ then Left [noNamespaceSplicesMsg $ T.unpack pre]+ else Right () return $ case _spliceErrors hs' of- [] -> Right $! hs { _compiledTemplateMap = tmap }- es -> Left $ map T.unpack es+ [] -> nsErr >> (Right $! hs { _compiledTemplateMap = tmap })+ es -> Left $ either (++) (const id) nsErr $ map T.unpack es ------------------------------------------------------------------------------+noNamespaceSplicesMsg :: String -> String+noNamespaceSplicesMsg pre = unwords+ [ printf "You are using a namespace of '%s', but you don't have any" ns+ , printf "tags starting with '%s'. If you have not defined any" pre+ , "splices, then change your namespace to the empty string to get rid"+ , "of this message."+ ]+ where+ ns = reverse $ drop 1 $ reverse pre+++------------------------------------------------------------------------------ compileTemplates' :: Monad n => HeistT n IO (H.HashMap TPath ([Chunk n], MIMEType))@@ -253,6 +270,9 @@ -- compileNode to generate the appropriate runtime computation. runNode :: Monad n => X.Node -> Splice n runNode node = localParamNode (const node) $ do+ pre <- getsHS _splicePrefix+ let hasPrefix = (T.isPrefixOf pre `fmap` X.tagName node) == Just True+ when (not (T.null pre) && hasPrefix) incNamespacedTags isStatic <- subtreeIsStatic node markup <- getsHS _curMarkup if isStatic
src/Heist/Internal/Types/HeistState.hs view
@@ -204,6 +204,7 @@ -- correspond to a bound splice. When not using a namespace, this flag is -- ignored. , _errorNotBound :: Bool+ , _numNamespacedTags :: Int #if MIN_VERSION_base(4,7,0) } deriving (Typeable) #else@@ -532,6 +533,13 @@ modRecursionDepth :: Monad m => (Int -> Int) -> HeistT n m () modRecursionDepth f = modifyHS (\st -> st { _recursionDepth = f (_recursionDepth st) })+++------------------------------------------------------------------------------+-- | Increments the namespaced tag count+incNamespacedTags :: Monad m => HeistT n m ()+incNamespacedTags =+ modifyHS (\st -> st { _numNamespacedTags = _numNamespacedTags st + 1 }) ------------------------------------------------------------------------------
test/suite/Heist/Compiled/Tests.hs view
@@ -18,6 +18,7 @@ ------------------------------------------------------------------------------ import Heist import Heist.Compiled+import Heist.Compiled.Internal import Heist.Internal.Types import Heist.Tutorial.CompiledSplices import Heist.TestCommon@@ -35,6 +36,7 @@ , testCase "compiled/namespace3" namespaceTest3 , testCase "compiled/namespace4" namespaceTest4 , testCase "compiled/namespace5" namespaceTest5+ , testCase "compiled/no-ns-splices" noNsSplices , testCase "compiled/nsbind" nsBindTest , testCase "compiled/nsbinderr" nsBindErrorTest ]@@ -131,6 +133,25 @@ return $ toByteString b H.assertEqual "namespace test" (Left ["templates/namespaces.tpl: No splice bound for h:foo"]) res++------------------------------------------------------------------------------+-- | The templates-no-ns directory should have no tags beginning with h: so+-- this test will throw an error.+noNsSplices :: IO ()+noNsSplices = do+ res <- runEitherT $ do+ hs <- initHeist hc+ runner <- noteT ["Error rendering"] $ hoistMaybe $+ renderTemplate hs "test"+ b <- lift $ fst runner+ return $ toByteString b++ H.assertEqual "namespace test" (Left [noNamespaceSplicesMsg "h:"]) res+ where+ hc = HeistConfig sc "h" True+ sc = mempty & scLoadTimeSplices .~ defaultLoadTimeSplices+ & scCompiledSplices .~ ("foo" ## return (yieldPureText "aoeu"))+ & scTemplateLocations .~ [loadTemplates "templates-no-ns"] nsBindTemplateHC :: HeistConfig IO