packages feed

yesod-pnotify 1.0.0 → 1.0.1

raw patch · 2 files changed

+32/−12 lines, 2 files

Files

Yesod/Goodies/PNotify.hs view
@@ -12,12 +12,13 @@ import Yesod import Yesod.Form.Jquery hiding (urlJqueryJs, urlJqueryUiCss) -import Data.Text (Text)+import Control.Monad.Trans.Maybe+import Data.Char (toLower)+import Data.List (nub) import Data.Monoid ((<>), mempty)+import Data.Text (Text) import qualified Data.Text as T import qualified Data.Text.Lazy as TL-import Control.Monad.Trans.Maybe-import Data.Char (toLower) import Text.Julius (RawJS(..))  data PNotify = PNotify @@ -26,13 +27,13 @@                , ttl :: Text                , msg :: Text                }-             deriving (Show, Read)+             deriving (Show, Read, Eq)  data NotifyType = Notice | Info | Success | Error-                deriving (Show, Read)+                deriving (Show, Read, Eq)  data NotifyStyling = JqueryUI | Bootstrap3 | BrightTheme | FontAwesome-                   deriving (Show, Read)+                   deriving (Show, Read, Eq)  class YesodJquery a => YesodJqueryPnotify a where   urlJqueryJs :: a -> Either (Route a) Text@@ -74,11 +75,28 @@   lift $ deleteSession notifyKey   return $ fromText ns + setPNotify :: PNotify -> HandlerT site IO () setPNotify n = do   mns <- getPNotify   _setPNotify (n:maybe [] id mns) +optionalLoadJsCss :: (MonadWidget m, YesodJqueryPnotify (HandlerSite m)) =>+                     HandlerSite m -> [PNotify] -> m()+optionalLoadJsCss y = sequence_ . map trans . nub . map sty+    where+      trans s = case s of+        JqueryUI+          -> addStylesheetEither $ urlJqueryUiCss y+        Bootstrap3+          -> do { addScriptEither $ urlBootstrap3Js y+                ; addStylesheetEither $ urlBootstrap3Css y+                }+        BrightTheme+          -> addStylesheetEither $ urlBrightThemeCss y+        FontAwesome+          -> addStylesheetEither $ urlFontAwesomeCss y+ pnotify :: YesodJqueryPnotify site => site -> WidgetT site IO () pnotify y = do   mnotify <- handlerToWidget getPNotify@@ -88,11 +106,9 @@       addScriptEither $ urlJqueryJs y       addScriptEither $ urlPnotifyJs y       addStylesheetEither $ urlPnotifyCss y-      addScriptEither $ urlBootstrap3Js y-      addStylesheetEither $ urlBootstrap3Css y-      addStylesheetEither $ urlBrightThemeCss y-      addStylesheetEither $ urlJqueryUiCss y-      addStylesheetEither $ urlFontAwesomeCss y++      optionalLoadJsCss y ps+       let toJs p = [julius|{styling:'#{rawJS $ map toLower $ show $ sty p}'                            ,title:'#{rawJS $ ttl p}'                            ,text:'#{rawJS $ msg p}'@@ -100,3 +116,5 @@                            },|]           ws = foldr ((<>).toJs) mempty ps       toWidget [julius|$(function(){var ws=[^{ws}];for(var i in ws){new PNotify(ws[i]);}});|]+    where+      when b f = if b then f else return ()
yesod-pnotify.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                yesod-pnotify-version:             1.0.0+version:             1.0.1 synopsis:            Yet another getMessage/setMessage using pnotify jquery plugins description:         Yet another getMessage/setMessage using pnotify jquery plugins homepage:            https://github.com/cutsea110/yesod-pnotify@@ -25,6 +25,7 @@                      , TemplateHaskell                      , MultiParamTypeClasses                      , TypeFamilies+                     , FlexibleContexts    build-depends:         base >= 4.6 && < 4.9                        , yesod >= 1.2 && < 1.5@@ -41,6 +42,7 @@                      , TemplateHaskell                      , MultiParamTypeClasses                      , TypeFamilies+                     , FlexibleContexts    build-depends:         base >= 4.6 && < 4.9                        , yesod >= 1.2 && < 1.5