packages feed

digestive-functors-heist 0.3.0.1 → 0.3.1.0

raw patch · 2 files changed

+46/−20 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Text.Digestive.Heist: dfIfChildErrors :: Monad m => View v -> Splice m

Files

digestive-functors-heist.cabal view
@@ -1,5 +1,5 @@ Name:          digestive-functors-heist-Version:       0.3.0.1+Version:       0.3.1.0 Synopsis:      Heist frontend for the digestive-functors library Description:   Heist frontend for the digestive-functors library Homepage:      http://github.com/jaspervdj/digestive-functors
src/Text/Digestive/Heist.hs view
@@ -27,7 +27,7 @@       digestiveSplices     , bindDigestiveSplices -      -- * Splices+      -- * Main splices     , dfInputText     , dfInputTextArea     , dfInputPassword@@ -41,9 +41,12 @@     , dfErrorList     , dfChildErrorList     , dfSubView++      -- * Utility splices+    , dfIfChildErrors     ) where -import Control.Monad (liftM)+import Control.Monad (liftM, mplus) import Data.Maybe (fromMaybe) import Data.Monoid (mappend) @@ -72,6 +75,7 @@     , ("dfErrorList",      dfErrorList view)     , ("dfChildErrorList", dfChildErrorList view)     , ("dfSubView",        dfSubView view)+    , ("dfIfChildErrors",  dfIfChildErrors view)     ]  attr :: Bool -> (Text, Text) -> [(Text, Text)] -> [(Text, Text)]@@ -81,13 +85,15 @@ makeElement :: Text -> [X.Node] -> [(Text, Text)] -> [X.Node] makeElement name nodes = return . flip (X.Element name) nodes -getRefAttributes :: Monad m => HeistT m (Text, [(Text, Text)])-getRefAttributes = do+getRefAttributes :: Monad m+                 => Maybe Text                       -- ^ Optional default ref+                 -> HeistT m (Text, [(Text, Text)])  -- ^ (Ref, other attrs)+getRefAttributes defaultRef = do     node <- getParamNode     return $ case node of         X.Element _ as _ ->             let ref = fromMaybe (error $ show node ++ ": missing ref") $-                        lookup "ref" as+                        lookup "ref" as `mplus` defaultRef             in (ref, filter ((/= "ref") . fst) as)         _                -> (error "Wrong type of node!", []) @@ -99,7 +105,7 @@ -- > <dfInputText ref="user.name" /> dfInputText :: Monad m => View v -> Splice m dfInputText view = do-    (ref, attrs) <- getRefAttributes+    (ref, attrs) <- getRefAttributes Nothing     let ref'  = absoluteRef ref view         value = fieldInputText ref view     return $ makeElement "input" [] $@@ -111,7 +117,7 @@ -- > <dfInputTextArea ref="user.about" /> dfInputTextArea :: Monad m => View v -> Splice m dfInputTextArea view = do-    (ref, attrs) <- getRefAttributes+    (ref, attrs) <- getRefAttributes Nothing     let ref'  = absoluteRef ref view         value = fieldInputText ref view     return $ makeElement "textarea" [X.TextNode value] $@@ -122,7 +128,7 @@ -- > <dfInputPassword ref="user.password" /> dfInputPassword :: Monad m => View v -> Splice m dfInputPassword view = do-    (ref, attrs) <- getRefAttributes+    (ref, attrs) <- getRefAttributes Nothing     let ref'  = absoluteRef ref view         value = fieldInputText ref view     return $ makeElement "input" [] $@@ -134,7 +140,7 @@ -- > <dfInputHidden ref="user.forgery" /> dfInputHidden :: Monad m => View v -> Splice m dfInputHidden view = do-    (ref, attrs) <- getRefAttributes+    (ref, attrs) <- getRefAttributes Nothing     let ref'  = absoluteRef ref view         value = fieldInputText ref view     return $ makeElement "input" [] $@@ -146,7 +152,7 @@ -- > <dfInputSelect ref="user.sex" /> dfInputSelect :: Monad m => View Text -> Splice m dfInputSelect view = do-    (ref, attrs) <- getRefAttributes+    (ref, attrs) <- getRefAttributes Nothing     let ref'           = absoluteRef ref view         (choices, idx) = fieldInputChoice ref view         children       = zipWith makeOption choices [0 ..]@@ -162,7 +168,7 @@ -- > <dfInputRadio ref="user.sex" /> dfInputRadio :: Monad m => View Text -> Splice m dfInputRadio view = do-    (ref, attrs) <- getRefAttributes+    (ref, attrs) <- getRefAttributes Nothing      let ref'           = absoluteRef ref view         (choices, idx) = fieldInputChoice ref view@@ -185,7 +191,7 @@ -- > <dfInputCheckbox ref="user.married" /> dfInputCheckbox :: Monad m => View Text -> Splice m dfInputCheckbox view = do-    (ref, attrs) <- getRefAttributes+    (ref, attrs) <- getRefAttributes Nothing     let ref'  = absoluteRef ref view         value = fieldInputBool ref view     return $ makeElement "input" [] $ attr value ("checked", "checked") $@@ -196,7 +202,7 @@ -- > <dfInputFile ref="user.avatar" /> dfInputFile :: Monad m => View Text -> Splice m dfInputFile view = do-    (ref, attrs) <- getRefAttributes+    (ref, attrs) <- getRefAttributes Nothing     let ref'  = absoluteRef ref view         value = maybe "" T.pack $ fieldInputFile ref view     return $ makeElement "input" [] $@@ -208,7 +214,7 @@ -- > <dfInputSubmit /> dfInputSubmit :: Monad m => View v -> Splice m dfInputSubmit _ = do-    (_, attrs) <- getRefAttributes+    (_, attrs) <- getRefAttributes Nothing     return $ makeElement "input" [] $ ("type", "submit") : attrs  -- | Generate a label for a field. Example:@@ -217,7 +223,7 @@ -- > <dfInputCheckbox ref="user.married" /> dfLabel :: Monad m => View v -> Splice m dfLabel view = do-    (ref, attrs) <- getRefAttributes+    (ref, attrs) <- getRefAttributes Nothing     content      <- getContent     let ref' = absoluteRef ref view     return $ makeElement "label" content $ ("for", ref') : attrs@@ -234,7 +240,7 @@ -- > </dfForm> dfForm :: Monad m => View v -> Splice m dfForm view = do-    (_, attrs) <- getRefAttributes+    (_, attrs) <- getRefAttributes Nothing     content    <- getContent     return $ makeElement "form" content $         attrs ++ @@ -253,7 +259,7 @@ -- > <dfInputText ref="user.name" /> dfErrorList :: Monad m => View Text -> Splice m dfErrorList view = do-    (ref, attrs) <- getRefAttributes+    (ref, attrs) <- getRefAttributes Nothing     return $ errorList (errors ref view) attrs  -- | Display the list of errors for a certain form and all forms below it. E.g.,@@ -264,9 +270,13 @@ -- Or display /all/ errors for the form: -- -- > <dfChildErrorList ref="" />+--+-- Which is more conveniently written as:+--+-- > <dfChildErrorList /> dfChildErrorList :: Monad m => View Text -> Splice m dfChildErrorList view = do-    (ref, attrs) <- getRefAttributes+    (ref, attrs) <- getRefAttributes $ Just ""     return $ errorList (childErrors ref view) attrs  -- | This splice allows reuse of templates by selecting some child of a form@@ -294,8 +304,24 @@ -- > <dfInputTextArea ref="comment.body" /> dfSubView :: Monad m => View Text -> Splice m dfSubView view = do-    (ref, _) <- getRefAttributes+    (ref, _) <- getRefAttributes Nothing     content  <- getContent     let view' = subView ref view     nodes <- localTS (bindDigestiveSplices view') $ runNodeList content     return nodes++-- | Render some content only if there are any errors. This is useful for markup+-- purposes.+--+-- > <dfIfChildErrors ref="user">+-- >     Content to be rendered if there are any errors...+-- > </dfIfChildErrors>+--+-- The @ref@ attribute can be omitted if you want to check the entire form.+dfIfChildErrors :: Monad m => View v -> Splice m+dfIfChildErrors view = do+    (ref, _) <- getRefAttributes $ Just ""+    content  <- getContent+    if null (childErrors ref view)+        then return []+        else runNodeList content