packages feed

heist 0.6.1 → 0.7.0

raw patch · 11 files changed

+182/−127 lines, 11 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Text.Templating.Heist: data TemplateState m
+ Text.Templating.Heist: callTemplateWithText :: Monad m => ByteString -> [(Text, Text)] -> HeistT m Template
+ Text.Templating.Heist: data HeistState m
+ Text.Templating.Heist: defaultHeistState :: MonadIO m => HeistState m
+ Text.Templating.Heist: type TemplateState = HeistState
+ Text.Templating.Heist: useOldAttributeSyntax :: HeistState m -> HeistState m
- Text.Templating.Heist: addOnLoadHook :: Monad m => (Template -> IO Template) -> TemplateState m -> TemplateState m
+ Text.Templating.Heist: addOnLoadHook :: Monad m => (Template -> IO Template) -> HeistState m -> HeistState m
- Text.Templating.Heist: addPostRunHook :: Monad m => (Template -> m Template) -> TemplateState m -> TemplateState m
+ Text.Templating.Heist: addPostRunHook :: Monad m => (Template -> m Template) -> HeistState m -> HeistState m
- Text.Templating.Heist: addPreRunHook :: Monad m => (Template -> m Template) -> TemplateState m -> TemplateState m
+ Text.Templating.Heist: addPreRunHook :: Monad m => (Template -> m Template) -> HeistState m -> HeistState m
- Text.Templating.Heist: addTemplate :: Monad m => ByteString -> Template -> Maybe FilePath -> TemplateState m -> TemplateState m
+ Text.Templating.Heist: addTemplate :: Monad m => ByteString -> Template -> Maybe FilePath -> HeistState m -> HeistState m
- Text.Templating.Heist: addTemplatePathPrefix :: ByteString -> TemplateState m -> TemplateState m
+ Text.Templating.Heist: addTemplatePathPrefix :: ByteString -> HeistState m -> HeistState m
- Text.Templating.Heist: addXMLTemplate :: Monad m => ByteString -> Template -> Maybe FilePath -> TemplateState m -> TemplateState m
+ Text.Templating.Heist: addXMLTemplate :: Monad m => ByteString -> Template -> Maybe FilePath -> HeistState m -> HeistState m
- Text.Templating.Heist: bindSplice :: Monad m => Text -> Splice m -> TemplateState m -> TemplateState m
+ Text.Templating.Heist: bindSplice :: Monad m => Text -> Splice m -> HeistState m -> HeistState m
- Text.Templating.Heist: bindSplices :: Monad m => [(Text, Splice m)] -> TemplateState m -> TemplateState m
+ Text.Templating.Heist: bindSplices :: Monad m => [(Text, Splice m)] -> HeistState m -> HeistState m
- Text.Templating.Heist: bindString :: Monad m => Text -> Text -> TemplateState m -> TemplateState m
+ Text.Templating.Heist: bindString :: Monad m => Text -> Text -> HeistState m -> HeistState m
- Text.Templating.Heist: bindStrings :: Monad m => [(Text, Text)] -> TemplateState m -> TemplateState m
+ Text.Templating.Heist: bindStrings :: Monad m => [(Text, Text)] -> HeistState m -> HeistState m
- Text.Templating.Heist: callTemplate :: Monad m => ByteString -> [(Text, Text)] -> HeistT m (Maybe Template)
+ Text.Templating.Heist: callTemplate :: Monad m => ByteString -> [(Text, Splice m)] -> HeistT m Template
- Text.Templating.Heist: emptyTemplateState :: MonadIO m => TemplateState m
+ Text.Templating.Heist: emptyTemplateState :: MonadIO m => HeistState m
- Text.Templating.Heist: getTS :: Monad m => TemplateMonad m (TemplateState m)
+ Text.Templating.Heist: getTS :: Monad m => TemplateMonad m (HeistState m)
- Text.Templating.Heist: getsTS :: Monad m => (TemplateState m -> r) -> TemplateMonad m r
+ Text.Templating.Heist: getsTS :: Monad m => (HeistState m -> r) -> TemplateMonad m r
- Text.Templating.Heist: hasTemplate :: Monad m => ByteString -> TemplateState m -> Bool
+ Text.Templating.Heist: hasTemplate :: Monad m => ByteString -> HeistState m -> Bool
- Text.Templating.Heist: loadTemplates :: Monad m => FilePath -> TemplateState m -> IO (Either String (TemplateState m))
+ Text.Templating.Heist: loadTemplates :: Monad m => FilePath -> HeistState m -> IO (Either String (HeistState m))
- Text.Templating.Heist: localTS :: Monad m => (TemplateState m -> TemplateState m) -> TemplateMonad m a -> TemplateMonad m a
+ Text.Templating.Heist: localTS :: Monad m => (HeistState m -> HeistState m) -> TemplateMonad m a -> TemplateMonad m a
- Text.Templating.Heist: lookupSplice :: Monad m => Text -> TemplateState m -> Maybe (Splice m)
+ Text.Templating.Heist: lookupSplice :: Monad m => Text -> HeistState m -> Maybe (Splice m)
- Text.Templating.Heist: mkCacheTag :: MonadIO m => IO (TemplateState m -> TemplateState m, CacheTagState)
+ Text.Templating.Heist: mkCacheTag :: MonadIO m => IO (HeistState m -> HeistState m, CacheTagState)
- Text.Templating.Heist: modifyTS :: Monad m => (TemplateState m -> TemplateState m) -> TemplateMonad m ()
+ Text.Templating.Heist: modifyTS :: Monad m => (HeistState m -> HeistState m) -> TemplateMonad m ()
- Text.Templating.Heist: putTS :: Monad m => TemplateState m -> TemplateMonad m ()
+ Text.Templating.Heist: putTS :: Monad m => HeistState m -> TemplateMonad m ()
- Text.Templating.Heist: renderTemplate :: Monad m => TemplateState m -> ByteString -> m (Maybe (Builder, MIMEType))
+ Text.Templating.Heist: renderTemplate :: Monad m => HeistState m -> ByteString -> m (Maybe (Builder, MIMEType))
- Text.Templating.Heist: renderWithArgs :: Monad m => [(Text, Text)] -> TemplateState m -> ByteString -> m (Maybe (Builder, MIMEType))
+ Text.Templating.Heist: renderWithArgs :: Monad m => [(Text, Text)] -> HeistState m -> ByteString -> m (Maybe (Builder, MIMEType))
- Text.Templating.Heist: restoreTS :: Monad m => TemplateState m -> TemplateMonad m ()
+ Text.Templating.Heist: restoreTS :: Monad m => HeistState m -> TemplateMonad m ()
- Text.Templating.Heist: setTemplates :: Monad m => TemplateMap -> TemplateState m -> TemplateState m
+ Text.Templating.Heist: setTemplates :: Monad m => TemplateMap -> HeistState m -> HeistState m
- Text.Templating.Heist: spliceNames :: TemplateState m -> [Text]
+ Text.Templating.Heist: spliceNames :: HeistState m -> [Text]
- Text.Templating.Heist: templateNames :: TemplateState m -> [TPath]
+ Text.Templating.Heist: templateNames :: HeistState m -> [TPath]
- Text.Templating.Heist.Splices.Cache: mkCacheTag :: MonadIO m => IO (TemplateState m -> TemplateState m, CacheTagState)
+ Text.Templating.Heist.Splices.Cache: mkCacheTag :: MonadIO m => IO (HeistState m -> HeistState m, CacheTagState)
- Text.Templating.Heist.Splices.Static: bindStaticTag :: MonadIO m => TemplateState m -> IO (TemplateState m, StaticTagState)
+ Text.Templating.Heist.Splices.Static: bindStaticTag :: MonadIO m => HeistState m -> IO (HeistState m, StaticTagState)
- Text.Templating.Heist.TemplateDirectory: getDirectoryTS :: (Monad m, MonadIO n) => TemplateDirectory m -> n (TemplateState m)
+ Text.Templating.Heist.TemplateDirectory: getDirectoryTS :: (Monad m, MonadIO n) => TemplateDirectory m -> n (HeistState m)
- Text.Templating.Heist.TemplateDirectory: newTemplateDirectory :: (MonadIO m, MonadIO n) => FilePath -> TemplateState m -> n (Either String (TemplateDirectory m))
+ Text.Templating.Heist.TemplateDirectory: newTemplateDirectory :: (MonadIO m, MonadIO n) => FilePath -> HeistState m -> n (Either String (TemplateDirectory m))
- Text.Templating.Heist.TemplateDirectory: newTemplateDirectory' :: (MonadIO m, MonadIO n) => FilePath -> TemplateState m -> n (TemplateDirectory m)
+ Text.Templating.Heist.TemplateDirectory: newTemplateDirectory' :: (MonadIO m, MonadIO n) => FilePath -> HeistState m -> n (TemplateDirectory m)

Files

heist.cabal view
@@ -1,7 +1,7 @@ name:           heist-version:        0.6.1-synopsis:       An xhtml templating system-description:    An xhtml templating system+version:        0.7.0+synopsis:       An (x)html templating system+description:    An (x)html templating system license:        BSD3 license-file:   LICENSE author:         Doug Beardsley, Gregory Collins@@ -9,7 +9,7 @@ build-type:     Simple cabal-version:  >= 1.6 homepage:       http://snapframework.com/-category:       Web+category:       Web, Snap  extra-source-files:   .ghci,
src/Text/Templating/Heist.hs view
@@ -47,22 +47,22 @@   >    Next, you need to bind that splice to a tag.  Heist stores information-  about splices and templates in the 'TemplateState' data structure.  The+  about splices and templates in the 'HeistState' data structure.  The   following code demonstrates how this splice would be used.    > mySplices = [ ("loginLogout", loginLogoutSplice) ]   >   > main = do   >     ets <- loadTemplates "templates" $-  >            bindSplices mySplices (emptyTemplateState "templates")+  >            bindSplices mySplices emptyHeistState   >     let ts = either error id ets   >     t <- runMyAppMonad $ renderTemplate ts "index"   >     print $ maybe "Page not found" (toByteString . fst) t -  Here we build up our 'TemplateState' by starting with emptyTemplateState and+  Here we build up our 'HeistState' by starting with emptyHeistState and   applying bindSplice for all the splices we want to add.  Then we pass this-  to loadTemplates our final 'TemplateState' wrapped in an Either to handle-  errors.  Then we use this 'TemplateState' to render our templates.+  to loadTemplates our final 'HeistState' wrapped in an Either to handle+  errors.  Then we use this 'HeistState' to render our templates.  -} @@ -74,14 +74,16 @@   , Splice   , TemplateMonad   , HeistT+  , HeistState   , TemplateState   , templateNames   , spliceNames -    -- * Functions and declarations on TemplateState values+    -- * Functions and declarations on HeistState values   , addTemplate   , addXMLTemplate   , emptyTemplateState+  , defaultHeistState   , bindSplice   , bindSplices   , lookupSplice@@ -114,6 +116,7 @@     -- * Functions for running splices and templates   , evalTemplate   , callTemplate+  , callTemplateWithText   , renderTemplate   , renderWithArgs   , bindStrings@@ -133,6 +136,8 @@   , getXMLDoc   , mkCacheTag +    -- * Temporary functions+  , useOldAttributeSyntax   ) where  import           Control.Monad.Trans@@ -154,13 +159,22 @@   ------------------------------------------------------------------------------+-- | An empty heist state, with Heist's default splices (@\<apply\>@,+-- @\<bind\>@, @\<ignore\>@, and @\<markdown\>@) mapped.  The cache tag is+-- not mapped here because it must be mapped manually in your application.+defaultHeistState :: MonadIO m => HeistState m+defaultHeistState =+    HeistState (defaultSpliceMap) Map.empty True [] 0+               return return return [] Nothing False+++{-# DEPRECATED emptyTemplateState "NOTICE: The name TemplateState is changing to HeistState.  Use defaultHeistState instead of emptyTemplateState." #-}+------------------------------------------------------------------------------ -- | An empty template state, with Heist's default splices (@\<apply\>@, -- @\<bind\>@, @\<ignore\>@, and @\<markdown\>@) mapped.  The static tag is -- not mapped here because it must be mapped manually in your application.-emptyTemplateState :: MonadIO m => TemplateState m-emptyTemplateState =-    TemplateState (defaultSpliceMap) Map.empty True [] 0-                  return return return [] Nothing+emptyTemplateState :: MonadIO m => HeistState m+emptyTemplateState = defaultHeistState   -- $hookDoc@@ -168,7 +182,7 @@ -- and after they are run.  Every time you call one of the addAbcHook -- functions the hook is added to onto the processing pipeline.  The hooks -- processes the template in the order that they were added to the--- TemplateState.+-- HeistState. -- -- The pre-run and post-run hooks are run before and after every template is -- run/rendered.  You should be careful what code you put in these hooks
src/Text/Templating/Heist/Internal.hs view
@@ -41,53 +41,53 @@   --------------------------------------------------------------------------------- TemplateState functions+-- HeistState functions ------------------------------------------------------------------------------   --------------------------------------------------------------------------------- | Adds an on-load hook to a `TemplateState`.+-- | Adds an on-load hook to a `HeistState`. addOnLoadHook :: (Monad m) =>                  (Template -> IO Template)-              -> TemplateState m-              -> TemplateState m+              -> HeistState m+              -> HeistState m addOnLoadHook hook ts = ts { _onLoadHook = _onLoadHook ts >=> hook }   --------------------------------------------------------------------------------- | Adds a pre-run hook to a `TemplateState`.+-- | Adds a pre-run hook to a `HeistState`. addPreRunHook :: (Monad m) =>                  (Template -> m Template)-              -> TemplateState m-              -> TemplateState m+              -> HeistState m+              -> HeistState m addPreRunHook hook ts = ts { _preRunHook = _preRunHook ts >=> hook }   --------------------------------------------------------------------------------- | Adds a post-run hook to a `TemplateState`.+-- | Adds a post-run hook to a `HeistState`. addPostRunHook :: (Monad m) =>                   (Template -> m Template)-               -> TemplateState m-               -> TemplateState m+               -> HeistState m+               -> HeistState m addPostRunHook hook ts = ts { _postRunHook = _postRunHook ts >=> hook }   --------------------------------------------------------------------------------- | Binds a new splice declaration to a tag name within a 'TemplateState'.+-- | Binds a new splice declaration to a tag name within a 'HeistState'. bindSplice :: Monad m =>               Text              -- ^ tag name            -> Splice m          -- ^ splice action-           -> TemplateState m   -- ^ source state-           -> TemplateState m+           -> HeistState m      -- ^ source state+           -> HeistState m bindSplice n v ts = ts {_spliceMap = Map.insert n v (_spliceMap ts)}   --------------------------------------------------------------------------------- | Binds a set of new splice declarations within a 'TemplateState'.+-- | Binds a set of new splice declarations within a 'HeistState'. bindSplices :: Monad m =>                [(Text, Splice m)] -- ^ splices to bind-            -> TemplateState m    -- ^ start state-            -> TemplateState m+            -> HeistState m       -- ^ start state+            -> HeistState m bindSplices ss ts = foldl' (flip id) ts acts   where     acts = map (uncurry bindSplice) ss@@ -96,7 +96,7 @@ ------------------------------------------------------------------------------ -- | Sets the current template file. setCurTemplateFile :: Monad m-                   => Maybe FilePath -> TemplateState m -> TemplateState m+                   => Maybe FilePath -> HeistState m -> HeistState m setCurTemplateFile fp ts = ts { _curTemplateFile = fp }  @@ -168,7 +168,7 @@ -- | Convenience function for looking up a splice. lookupSplice :: Monad m =>                 Text-             -> TemplateState m+             -> HeistState m              -> Maybe (Splice m) lookupSplice nm ts = Map.lookup nm $ _spliceMap ts @@ -220,10 +220,10 @@   --------------------------------------------------------------------------------- | Returns 'True' if the given template can be found in the template state.+-- | Returns 'True' if the given template can be found in the heist state. hasTemplate :: Monad m =>                ByteString-            -> TemplateState m+            -> HeistState m             -> Bool hasTemplate nameStr ts = isJust $ lookupTemplate nameStr ts @@ -232,7 +232,7 @@ -- | Convenience function for looking up a template. lookupTemplate :: Monad m =>                   ByteString-               -> TemplateState m+               -> HeistState m                -> Maybe (DocumentFile, TPath) lookupTemplate nameStr ts =     f (_templateMap ts) path name@@ -247,24 +247,24 @@   --------------------------------------------------------------------------------- | Sets the templateMap in a TemplateState.-setTemplates :: Monad m => TemplateMap -> TemplateState m -> TemplateState m+-- | Sets the templateMap in a HeistState.+setTemplates :: Monad m => TemplateMap -> HeistState m -> HeistState m setTemplates m ts = ts { _templateMap = m }   --------------------------------------------------------------------------------- | Adds a template to the template state.+-- | Adds a template to the heist state. insertTemplate :: Monad m =>                TPath             -> DocumentFile-            -> TemplateState m-            -> TemplateState m+            -> HeistState m+            -> HeistState m insertTemplate p t st =     setTemplates (Map.insert p t (_templateMap st)) st   --------------------------------------------------------------------------------- | Adds an HTML format template to the template state.+-- | Adds an HTML format template to the heist state. addTemplate :: Monad m             => ByteString             -- ^ Path that the template will be referenced by@@ -273,8 +273,8 @@             -> Maybe FilePath             -- ^ An optional path to the actual file on disk where the             -- template is stored-            -> TemplateState m-            -> TemplateState m+            -> HeistState m+            -> HeistState m addTemplate n t mfp st =     insertTemplate (splitTemplatePath n) doc st   where@@ -282,7 +282,7 @@   --------------------------------------------------------------------------------- | Adds an XML format template to the template state.+-- | Adds an XML format template to the heist state. addXMLTemplate :: Monad m                => ByteString                -- ^ Path that the template will be referenced by@@ -291,8 +291,8 @@                -> Maybe FilePath                -- ^ An optional path to the actual file on disk where the                -- template is stored-               -> TemplateState m-               -> TemplateState m+               -> HeistState m+               -> HeistState m addXMLTemplate n t mfp st =     insertTemplate (splitTemplatePath n) doc st   where@@ -366,7 +366,8 @@ -- appropriate substitution. parseAtt :: (Monad m) => Text -> HeistT m Text parseAtt bs = do-    let ast = case AP.feed (AP.parse attParser bs) "" of+    oldSyntax <- getsTS _oldAttributeSyntax+    let ast = case AP.feed (AP.parse (attParser oldSyntax) bs) "" of             (AP.Fail _ _ _) -> []             (AP.Done _ res) -> res             (AP.Partial _)  -> []@@ -387,14 +388,17 @@  ------------------------------------------------------------------------------ -- | Parser for attribute variable substitution.-attParser :: AP.Parser [AttAST]-attParser = AP.many1 (identParser <|> litParser)+attParser :: Bool -> AP.Parser [AttAST]+attParser oldSyntax = AP.many1 (identParser <|> litParser)   where     escChar = (AP.char '\\' *> AP.anyChar) <|>               AP.satisfy (AP.notInClass "\\$")     litParser = Literal <$> (T.pack <$> AP.many1 escChar)-    identParser = AP.string "$(" *>+    identParser = if oldSyntax then oldParser else newParser+    oldParser = AP.string "$(" *>         (Ident <$> AP.takeWhile (/=')')) <* AP.string ")"+    newParser = AP.string "${" *>+        (Ident <$> AP.takeWhile (/='}')) <* AP.string "}"   ------------------------------------------------------------------------------@@ -521,8 +525,8 @@ -- | Binds a list of constant string splices. bindStrings :: Monad m             => [(Text, Text)]-            -> TemplateState m-            -> TemplateState m+            -> HeistState m+            -> HeistState m bindStrings pairs ts = foldr (uncurry bindString) ts pairs  @@ -531,23 +535,37 @@ bindString :: Monad m             => Text             -> Text-            -> TemplateState m-            -> TemplateState m+            -> HeistState m+            -> HeistState m bindString n = bindSplice n . textSplice   ------------------------------------------------------------------------------ -- | Renders a template with the specified parameters.  This is the function -- to use when you want to "call" a template and pass in parameters from--- inside a splice.+-- inside a splice.  If the template does not exist, this version simply+-- returns an empty list. callTemplate :: Monad m-             => ByteString     -- ^ The name of the template-             -> [(Text, Text)] -- ^ Association list of-                               -- (name,value) parameter pairs-             -> HeistT m (Maybe Template)+             => ByteString         -- ^ The name of the template+             -> [(Text, Splice m)] -- ^ Association list of+                                   -- (name,value) parameter pairs+             -> HeistT m Template callTemplate name params = do+    modifyTS $ bindSplices params+    liftM (maybe [] id) $ evalTemplate name+++------------------------------------------------------------------------------+-- | Like callTemplate except the splices being bound are constant text+-- splices.+callTemplateWithText :: Monad m+                     => ByteString     -- ^ The name of the template+                     -> [(Text, Text)] -- ^ Association list of+                                       -- (name,value) parameter pairs+                     -> HeistT m Template+callTemplateWithText name params = do     modifyTS $ bindStrings params-    evalTemplate name+    liftM (maybe [] id) $ evalTemplate name   ------------------------------------------------------------------------------@@ -565,13 +583,13 @@   --------------------------------------------------------------------------------- | Renders a template from the specified TemplateState to a 'Builder'.  The+-- | Renders a template from the specified HeistState to a 'Builder'.  The -- MIME type returned is based on the detected character encoding, and whether -- the root template was an HTML or XML format template.  It will always be -- @text/html@ or @text/xml@.  If a more specific MIME type is needed for a -- particular XML application, it must be provided by the application. renderTemplate :: Monad m-               => TemplateState m+               => HeistState m                -> ByteString                -> m (Maybe (Builder, MIMEType)) renderTemplate ts name = evalTemplateMonad tpl (X.TextNode "") ts@@ -588,7 +606,7 @@ -- template. renderWithArgs :: Monad m                    => [(Text, Text)]-                   -> TemplateState m+                   -> HeistState m                    -> ByteString                    -> m (Maybe (Builder, MIMEType)) renderWithArgs args ts = renderTemplate (bindStrings args ts)@@ -653,10 +671,10 @@   --------------------------------------------------------------------------------- | Traverses the specified directory structure and builds a--- TemplateState by loading all the files with a ".tpl" or ".xtpl" extension.-loadTemplates :: Monad m => FilePath -> TemplateState m-              -> IO (Either String (TemplateState m))+-- | Traverses the specified directory structure and builds a HeistState by+-- loading all the files with a ".tpl" or ".xtpl" extension.+loadTemplates :: Monad m => FilePath -> HeistState m+              -> IO (Either String (HeistState m)) loadTemplates dir ts = do     d <- readDirectoryWith (loadTemplate dir) dir     let tlist = F.fold (free d)@@ -677,21 +695,21 @@   --------------------------------------------------------------------------------- | Runs the onLoad hook on the template and returns the 'TemplateState'+-- | Runs the onLoad hook on the template and returns the 'HeistState' -- with the result inserted.-loadHook :: Monad m => TemplateState m -> (TPath, DocumentFile)-         -> IO (TemplateState m)+loadHook :: Monad m => HeistState m -> (TPath, DocumentFile)+         -> IO (HeistState m) loadHook ts (tp, t) = do     t' <- runHook (_onLoadHook ts) t     return $ insertTemplate tp t' ts   --------------------------------------------------------------------------------- | Adds a path prefix to all the templates in the 'TemplateState'.  If you+-- | Adds a path prefix to all the templates in the 'HeistState'.  If you -- want to add multiple levels of directories, separate them with slashes as -- in "foo/bar".  Using an empty string as a path prefix will leave the--- 'TemplateState' unchanged.-addTemplatePathPrefix :: ByteString -> TemplateState m -> TemplateState m+-- 'HeistState' unchanged.+addTemplatePathPrefix :: ByteString -> HeistState m -> HeistState m addTemplatePathPrefix dir ts   | B.null dir = ts   | otherwise  = ts { _templateMap = Map.mapKeys f $ _templateMap ts }
src/Text/Templating/Heist/Splices/Cache.hs view
@@ -102,12 +102,12 @@   --------------------------------------------------------------------------------- | Returns a function that modifies a TemplateState to include a \"cache\"+-- | Returns a function that modifies a HeistState to include a \"cache\" -- tag.  The cache tag is not bound automatically with the other default Heist -- tags.  This is because this function also returns CacheTagState, so the -- user will be able to clear it with the 'clearCacheTagState' function. mkCacheTag :: MonadIO m-           => IO (TemplateState m -> TemplateState m, CacheTagState)+           => IO (HeistState m -> HeistState m, CacheTagState) mkCacheTag = do     sr <- newIORef $ Set.empty     mv <- liftM CTS $ newMVar Map.empty
src/Text/Templating/Heist/Splices/Static.hs view
@@ -67,13 +67,13 @@   --------------------------------------------------------------------------------- | Modifies a TemplateState to include a \"static\" tag.  The static tag is+-- | Modifies a HeistState to include a \"static\" tag.  The static tag is -- not bound automatically with the other default Heist tags.  This is because -- this function also returns StaticTagState, so the user will be able to -- clear it with the 'clearStaticTagCache' function. bindStaticTag :: MonadIO m-              => TemplateState m-              -> IO (TemplateState m, StaticTagState)+              => HeistState m+              -> IO (HeistState m, StaticTagState) bindStaticTag ts = do     sr <- newIORef $ Set.empty     mv <- liftM STS $ newMVar Map.empty
src/Text/Templating/Heist/TemplateDirectory.hs view
@@ -27,8 +27,8 @@ data TemplateDirectory m     = TemplateDirectory         FilePath-        (TemplateState m)-        (MVar (TemplateState m))+        (HeistState m)+        (MVar (HeistState m))         StaticTagState  @@ -37,7 +37,7 @@ -- error handling. newTemplateDirectory :: (MonadIO m, MonadIO n)                      => FilePath-                     -> TemplateState m+                     -> HeistState m                      -> n (Either String (TemplateDirectory m)) newTemplateDirectory dir templateState = liftIO $ do     (origTs,sts) <- bindStaticTag templateState@@ -52,16 +52,16 @@ -- function on error. newTemplateDirectory' :: (MonadIO m, MonadIO n)                       => FilePath-                      -> TemplateState m+                      -> HeistState m                       -> n (TemplateDirectory m) newTemplateDirectory' = ((either fail return =<<) .) . newTemplateDirectory   --------------------------------------------------------------------------------- | Gets the 'TemplateState' from a TemplateDirectory.+-- | Gets the 'HeistState' from a TemplateDirectory. getDirectoryTS :: (Monad m, MonadIO n)                => TemplateDirectory m-               -> n (TemplateState m)+               -> n (HeistState m) getDirectoryTS (TemplateDirectory _ _ tsMVar _) = liftIO $ readMVar $ tsMVar  
src/Text/Templating/Heist/Types.hs view
@@ -78,10 +78,10 @@  ------------------------------------------------------------------------------ -- | Holds all the state information needed for template processing.  You will--- build a @TemplateState@ using any of Heist's @TemplateState m ->--- TemplateState m@ \"filter\" functions.  Then you use the resulting--- @TemplateState@ in calls to @renderTemplate@.-data TemplateState m = TemplateState {+-- build a @HeistState@ using any of Heist's @HeistState m -> HeistState m@+-- \"filter\" functions.  Then you use the resulting @HeistState@ in calls to+-- @renderTemplate@.+data HeistState m = HeistState {     -- | A mapping of splice names to splice actions       _spliceMap       :: SpliceMap m     -- | A mapping of template names to templates@@ -103,30 +103,54 @@     , _doctypes        :: [X.DocType]     -- | The full path to the current template's file on disk.     , _curTemplateFile :: Maybe FilePath+    -- | Temporary flag for backwards compatibility with the old attribute+    -- syntax for splices.+    , _oldAttributeSyntax :: Bool }  +{-# DEPRECATED TemplateState "NOTICE: The name TemplateState is changing to HeistState.  Use HeistState instead of TemplateState." #-} --------------------------------------------------------------------------------- | Gets the names of all the templates defined in a TemplateState.-templateNames :: TemplateState m -> [TPath]+-- | Holds all the state information needed for template processing.  You will+-- build a @HeistState@ using any of Heist's @HeistState m -> HeistState m@+-- \"filter\" functions.  Then you use the resulting @HeistState@ in calls to+-- @renderTemplate@.+type TemplateState = HeistState+++{-# DEPRECATED useOldAttributeSyntax "NOTICE: This function is only here temporarily to ease the transition in attribute syntax.  It will be removed in the next major release.  Update your templates!" #-}+------------------------------------------------------------------------------+-- | Sets compatibility mode that uses the old $() syntax for splices in+-- attributes.  The old syntax conflicts with the ubiquitous jquery function.+-- The new syntax is ${}.  This compatibility mode will be removed in the next+-- major release.+--+-- See https://github.com/snapframework/heist/issues/12 for the discussion.+useOldAttributeSyntax :: HeistState m -> HeistState m+useOldAttributeSyntax ts = ts { _oldAttributeSyntax = True }+++------------------------------------------------------------------------------+-- | Gets the names of all the templates defined in a HeistState.+templateNames :: HeistState m -> [TPath] templateNames ts = Map.keys $ _templateMap ts   --------------------------------------------------------------------------------- | Gets the names of all the splices defined in a TemplateState.-spliceNames :: TemplateState m -> [Text]+-- | Gets the names of all the splices defined in a HeistState.+spliceNames :: HeistState m -> [Text] spliceNames ts = Map.keys $ _spliceMap ts   -------------------------------------------------------------------------------instance (Monad m) => Monoid (TemplateState m) where-    mempty = TemplateState Map.empty Map.empty True [] 0-                           return return return [] Nothing+instance (Monad m) => Monoid (HeistState m) where+    mempty = HeistState Map.empty Map.empty True [] 0+                           return return return [] Nothing False -    (TemplateState s1 t1 r1 _ d1 o1 b1 a1 dt1 ctf1) `mappend`-        (TemplateState s2 t2 r2 c2 d2 o2 b2 a2 dt2 ctf2) =-        TemplateState s t r c2 d (o1 >=> o2) (b1 >=> b2) (a1 >=> a2)-            (dt1 `mappend` dt2) ctf+    (HeistState s1 t1 r1 _ d1 o1 b1 a1 dt1 ctf1 oas1) `mappend`+        (HeistState s2 t2 r2 c2 d2 o2 b2 a2 dt2 ctf2 oas2) =+        HeistState s t r c2 d (o1 >=> o2) (b1 >=> b2) (a1 >=> a2)+            (dt1 `mappend` dt2) ctf (oas1 || oas2)       where         s = s1 `mappend` s2         t = t1 `mappend` t2@@ -136,7 +160,7 @@   -------------------------------------------------------------------------------instance Eq (TemplateState m) where+instance Eq (HeistState m) where     a == b = (_recurse a == _recurse b) &&              (_templateMap a == _templateMap b) &&              (_curContext a == _curContext b)@@ -146,10 +170,10 @@ -- | The Typeable instance is here so Heist can be dynamically executed with -- Hint. templateStateTyCon :: TyCon-templateStateTyCon = mkTyCon "Text.Templating.Heist.TemplateState"+templateStateTyCon = mkTyCon "Text.Templating.Heist.HeistState" {-# NOINLINE templateStateTyCon #-} -instance (Typeable1 m) => Typeable (TemplateState m) where+instance (Typeable1 m) => Typeable (HeistState m) where     typeOf _ = mkTyConApp templateStateTyCon [typeOf1 (undefined :: m ())]  @@ -160,8 +184,8 @@ -- the inner monad. newtype TemplateMonad m a = TemplateMonad {     runTemplateMonad :: X.Node-                     -> TemplateState m-                     -> m (a, TemplateState m)+                     -> HeistState m+                     -> m (a, HeistState m) } type HeistT = TemplateMonad @@ -171,7 +195,7 @@ evalTemplateMonad :: Monad m                   => TemplateMonad m a                   -> X.Node-                  -> TemplateState m+                  -> HeistState m                   -> m a evalTemplateMonad m r s = do     (a, _) <- runTemplateMonad m r s@@ -265,9 +289,9 @@  ------------------------------------------------------------------------------ -- | Helper for MonadError instance.-liftCatch :: (m (a,TemplateState m)-              -> (e -> m (a,TemplateState m))-              -> m (a,TemplateState m))+liftCatch :: (m (a,HeistState m)+              -> (e -> m (a,HeistState m))+              -> m (a,HeistState m))           -> TemplateMonad m a           -> (e -> TemplateMonad m a)           -> TemplateMonad m a@@ -286,9 +310,9 @@  ------------------------------------------------------------------------------ -- | Helper for MonadCont instance.-liftCallCC :: ((((a,TemplateState m) -> m (b, TemplateState m))-                  -> m (a, TemplateState m))-                -> m (a, TemplateState m))+liftCallCC :: ((((a,HeistState m) -> m (b, HeistState m))+                  -> m (a, HeistState m))+                -> m (a, HeistState m))            -> ((a -> TemplateMonad m b) -> TemplateMonad m a)            -> TemplateMonad m a liftCallCC ccc f = TemplateMonad $ \r s ->@@ -345,45 +369,45 @@  ------------------------------------------------------------------------------ -- | TemplateMonad's 'gets'.-getsTS :: Monad m => (TemplateState m -> r) -> TemplateMonad m r+getsTS :: Monad m => (HeistState m -> r) -> TemplateMonad m r getsTS f = TemplateMonad $ \_ s -> return (f s, s)   ------------------------------------------------------------------------------ -- | TemplateMonad's 'get'.-getTS :: Monad m => TemplateMonad m (TemplateState m)+getTS :: Monad m => TemplateMonad m (HeistState m) getTS = TemplateMonad $ \_ s -> return (s, s)   ------------------------------------------------------------------------------ -- | TemplateMonad's 'put'.-putTS :: Monad m => TemplateState m -> TemplateMonad m ()+putTS :: Monad m => HeistState m -> TemplateMonad m () putTS s = TemplateMonad $ \_ _ -> return ((), s)   ------------------------------------------------------------------------------ -- | TemplateMonad's 'modify'. modifyTS :: Monad m-                    => (TemplateState m -> TemplateState m)+                    => (HeistState m -> HeistState m)                     -> TemplateMonad m () modifyTS f = TemplateMonad $ \_ s -> return ((), f s)   --------------------------------------------------------------------------------- | Restores the TemplateState.  This function is almost like putTS except it+-- | Restores the HeistState.  This function is almost like putTS except it -- preserves the current doctypes.  You should use this function instead of -- @putTS@ to restore an old state.  This was needed because doctypes needs to -- be in a "global scope" as opposed to the template call "local scope" of -- state items such as recursionDepth, curContext, and spliceMap.-restoreTS :: Monad m => TemplateState m -> TemplateMonad m ()+restoreTS :: Monad m => HeistState m -> TemplateMonad m () restoreTS old = modifyTS (\cur -> old { _doctypes = _doctypes cur })   ------------------------------------------------------------------------------ -- | Abstracts the common pattern of running a TemplateMonad computation with--- a modified template state.+-- a modified heist state. localTS :: Monad m-        => (TemplateState m -> TemplateState m)+        => (HeistState m -> HeistState m)         -> TemplateMonad m a         -> TemplateMonad m a localTS f k = do
test/heist-testsuite.cabal view
@@ -9,8 +9,7 @@    build-depends:     QuickCheck >= 2,-    attoparsec >= 0.8.1 && < 0.10,-    attoparsec-text >= 0.8 && < 0.9,+    attoparsec >= 0.10 && < 0.11,     base >= 4 && < 5,     blaze-builder >= 0.2 && <0.4,     bytestring,
test/suite/Text/Templating/Heist/Tests.hs view
@@ -197,7 +197,7 @@         H.assertBool ("attr subst " ++ (show str)) $ not $ B.null $             snd $ B.breakSubstring str $ toByteString $ resDoc         H.assertBool ("attr subst foo") $ not $ B.null $-            snd $ B.breakSubstring "$(foo)" $ toByteString $ resDoc+            snd $ B.breakSubstring "${foo}" $ toByteString $ resDoc   ------------------------------------------------------------------------------@@ -213,7 +213,7 @@         H.assertBool ("attr subst " ++ (show str)) $ not $ B.null $             snd $ B.breakSubstring str $ toByteString $ resDoc         H.assertBool ("attr subst bar") $ B.null $-            snd $ B.breakSubstring "$(bar)" $ toByteString $ resDoc+            snd $ B.breakSubstring "${bar}" $ toByteString $ resDoc   ------------------------------------------------------------------------------
test/templates/attrs.tpl view
@@ -1,3 +1,3 @@ <mytag flag="">Empty attribute</mytag>-<mytag flag="abc\$(foo)">No ident capture</mytag>-<div id="pre_$(foo)_post"/>+<mytag flag="abc\${foo}">No ident capture</mytag>+<div id="pre_${foo}_post"/>
test/templates/bind-attrs.tpl view
@@ -1,2 +1,2 @@ <bind tag="bar">zzzzz</bind>-<div id="$(bar)"> </div>+<div id="${bar}"> </div>