packages feed

yesod-pnotify (empty) → 0.1.0.0

raw patch · 4 files changed

+133/−0 lines, 4 filesdep +basedep +textdep +transformerssetup-changed

Dependencies added: base, text, transformers, yesod, yesod-form

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2012, Katsutoshi Itoh++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Katsutoshi Itoh nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Yesod/Goodies/PNotify.hs view
@@ -0,0 +1,76 @@+{-# LANGUAGE OverloadedStrings, QuasiQuotes, TemplateHaskell, MultiParamTypeClasses, TypeFamilies #-}+module Yesod.Goodies.PNotify +       ( PNotify(..)+       , NotifyType(..)+       , NotifyStyling(..)+       , YesodJqueryPnotify(..)+       , getPNotify+       , setPNotify+         -- Utility+       , pnotify+       ) where++import Yesod+import Yesod.Form.Jquery++import Data.Text (Text)+import Data.Monoid ((<>), mempty)+import qualified Data.Text as T+import qualified Data.Text.Lazy as TL+import Control.Monad.Trans.Maybe+import Data.Char (toLower)++data PNotify = PNotify +               { sty :: NotifyStyling+               , typ :: NotifyType+               , ttl :: Text+               , msg :: Text+               }+             deriving (Show, Read)++data NotifyType = Notice | Info | Success | Error+                deriving (Show, Read)++data NotifyStyling = JqueryUI | Bootstrap+                   deriving (Show, Read)++class YesodJquery a => YesodJqueryPnotify a where+  urlPnotifyJs :: a -> Either (Route a) Text+  urlPnotifyJs _ = Right "http://pinesframework.org/pnotify/jquery.pnotify.min.js"+  urlPnotifyCss :: a -> Either (Route a) Text+  urlPnotifyCss _ = Right "http://pinesframework.org/pnotify/jquery.pnotify.default.css"+  urlPnotifyIconsCss :: a -> Either (Route a) Text+  urlPnotifyIconsCss _ = Right "http://pinesframework.org/pnotify/jquery.pnotify.default.icons.css"++notifyKey :: Text+notifyKey = "_PNotify"++_setPNotify :: [PNotify] -> GHandler sub master ()+_setPNotify = setSession notifyKey . T.concat . TL.toChunks . TL.pack . show++getPNotify :: GHandler sub master (Maybe [PNotify])+getPNotify = runMaybeT $ do+  ns <- MaybeT $ lookupSession notifyKey+  lift $ deleteSession notifyKey+  return $ read $ T.unpack ns++setPNotify :: PNotify -> GHandler sub master ()+setPNotify n = do+  mns <- getPNotify+  _setPNotify (n:maybe [] id mns)++pnotify :: YesodJqueryPnotify m => m -> GWidget s m ()+pnotify y = do+  mnotify <- lift getPNotify+  case mnotify of+    Nothing -> return ()+    Just ps -> do+      addScriptEither $ urlJqueryJs y+      addScriptEither $ urlJqueryUiJs y+      addStylesheetEither $ urlJqueryUiCss y+      addScriptEither $ urlPnotifyJs y+      addStylesheetEither $ urlPnotifyCss y+      addStylesheetEither $ urlPnotifyIconsCss y+      let toJs p = [julius|{styling:'#{map toLower $ show $ sty p}',title:'#{ttl p}',text:'#{msg p}',type:'#{map toLower $ show $ typ p}'},|]+          ws = foldr ((<>).toJs) mempty ps+      toWidget [julius|$(document).ready(function(e){var ws=[^{ws}];for(var i in ws){$.pnotify(ws[i]);}});|]
+ yesod-pnotify.cabal view
@@ -0,0 +1,25 @@+-- Initial yesod-pnotify.cabal generated by cabal init.  For further +-- documentation, see http://haskell.org/cabal/users-guide/++name:                yesod-pnotify+version:             0.1.0.0+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+license:             BSD3+license-file:        LICENSE+author:              Katsutoshi Itoh+maintainer:          cutsea110@gmail.com+-- copyright:           +category:            Web, Yesod+build-type:          Simple+cabal-version:       >=1.8++library+  exposed-modules:     Yesod.Goodies.PNotify+  -- other-modules:       +  build-depends:         base ==4.5.*+                       , yesod ==1.1.*+                       , yesod-form ==1.1.*+                       , text ==0.11.*+                       , transformers ==0.3.*