packages feed

yesod-alerts (empty) → 0.1.0.0

raw patch · 8 files changed

+259/−0 lines, 8 filesdep +alertsdep +basedep +blaze-htmlsetup-changed

Dependencies added: alerts, base, blaze-html, blaze-markup, safe, text, yesod-core

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Daniel Campoverde [alx741] (c) 2017++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 Daniel Campoverde [alx741] 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.
+ README.md view
@@ -0,0 +1,49 @@+# yesod-alerts++Alert messages for the [Yesod framework](http://www.yesodweb.com/)+++## Setup++Modify your definition of `defaultLayout` in *Foundation.hs*:++```haskell+defaultLayout widget = do+    ...+    alerts  <- getAlerts+    ...+```++Then Include a renderer in *default-layout.hamlet*+++```haskell+...+#{renderAlertsBootstrap3 alerts}+...+^{widget}+...+```+++## Usage++Set alerts from your handlers++```haskell+getHomeR :: Handler Html+getHomeR = do+    ...+    setAlert (Alert Error "oops")+    setSuccessAlert "Yay!"+    ...+    defautlLayout $ do+        $(widgetFile "homepage")+```+++## Renderers++* Bootstrap v3+* Bootstrap v4+* Foundation v5
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Yesod/Alert.hs view
@@ -0,0 +1,87 @@+-- | Setup this package by modifying your definition of *defaultLayout* in+-- *Foundation.hs*+--+-- @+--      ...+--      defaultLayout widget = do+--      ...+--      alerts  <- getAlerts+--      ...+-- @+--+--+--  Then Include a renderer in *default-layout.hamlet*+--+-- @+--      ...+--      #{renderAlertsBootstrap3 alerts}+--      ...+--      ^{widget}+--      ...+-- @+--+--  Set alerts from your handlers+--+-- @+--      getHomeR :: Handler Html+--      getHomeR = do+--          ...+--          setAlert (Alert Error "oops")+--          setSuccessAlert "Yay!"+--          ...+--          defautlLayout $ do+--              $(widgetFile "homepage")+-- @++module Yesod.Alert+    ( -- * Setting alerts+      setAlert++      -- ** Shortcuts+    , setDefaultAlert+    , setInfoAlert+    , setSuccessAlert+    , setWarningAlert+    , setErrorAlert++    -- * Getting alerts+    , getAlerts++    , Alert(..)+    , AlertStatus(..)+    ) where++import Data.Maybe (fromMaybe)+import Data.Text+import Safe (readMay)+import Text.Blaze.Html.Renderer.Text+import Web.Alert+import Yesod.Core+import qualified Data.Text.Lazy as TL++-- Set an 'Alert'+setAlert :: MonadHandler m => Alert -> m ()+setAlert (Alert alert msg) = addMessage (pack $ show alert) $ toHtml msg++setDefaultAlert :: MonadHandler m => TL.Text -> m ()+setDefaultAlert msg = setAlert (Alert Default msg)++setInfoAlert :: MonadHandler m => TL.Text -> m ()+setInfoAlert msg = setAlert (Alert Info msg)++setSuccessAlert :: MonadHandler m => TL.Text -> m ()+setSuccessAlert msg = setAlert (Alert Success msg)++setWarningAlert :: MonadHandler m => TL.Text -> m ()+setWarningAlert msg = setAlert (Alert Warning msg)++setErrorAlert :: MonadHandler m => TL.Text -> m ()+setErrorAlert msg = setAlert (Alert Error msg)++-- Get available 'Alert's+getAlerts :: MonadHandler m => m [Alert]+getAlerts = do+    msgs <- getMessages+    return $ fmap mkAlert msgs+    where+        mkAlert (stat, msg) = Alert (fromMaybe Default (readMay $ unpack stat)) (renderHtml msg)
+ src/Yesod/Alert/Bootstrap3.hs view
@@ -0,0 +1,18 @@+-- | Render 'Alert's using Bootstrap v3.x+--+--  Dependencies (These should be accessible in your app):+--+-- * Bootstrap's CSS and JS+--+-- * JQuery >= 1.12.4++module Yesod.Alert.Bootstrap3+    ( renderAlertsBootstrap3+    ) where++import Text.Blaze+import Web.Alert+import qualified Web.Alert.Renderer.Bootstrap3 as B3++renderAlertsBootstrap3 :: [Alert] -> Markup+renderAlertsBootstrap3 = preEscapedToMarkup . B3.renderAlertsBootstrap3
+ src/Yesod/Alert/Bootstrap4.hs view
@@ -0,0 +1,18 @@+-- | Render 'Alert's using Bootstrap v4.x+--+--  Dependencies (These should be accessible in your app):+--+-- * Bootstrap's CSS and JS+--+-- * JQuery >= 3.2.1++module Yesod.Alert.Bootstrap4+    ( renderAlertsBootstrap4+    ) where++import Text.Blaze+import Web.Alert+import qualified Web.Alert.Renderer.Bootstrap4 as B4++renderAlertsBootstrap4 :: [Alert] -> Markup+renderAlertsBootstrap4 = preEscapedToMarkup . B4.renderAlertsBootstrap4
+ src/Yesod/Alert/Foundation5.hs view
@@ -0,0 +1,21 @@+-- | Render 'Alert's using Foundation v5.x+--+--  Dependencies (These should be accessible in your app):+--+-- * Foundation's CSS and JS+--+-- * Modernizr+--+-- * JQuery++module Yesod.Alert.Foundation5+    ( renderAlertsFoundation5+    , F5.AlertType(..)+    ) where++import Text.Blaze+import Web.Alert+import qualified Web.Alert.Renderer.Foundation5 as F5++renderAlertsFoundation5 :: F5.AlertType -> [Alert] -> Markup+renderAlertsFoundation5 at as = preEscapedToMarkup $ F5.renderAlertsFoundation5 at as
+ yesod-alerts.cabal view
@@ -0,0 +1,34 @@+name:                yesod-alerts+version:             0.1.0.0+synopsis:            Alert messages for the Yesod framework+description:         Use the "alerts" package with the Yesod framework+homepage:            https://github.com/alx741/yesod-alerts#readme+license:             BSD3+license-file:        LICENSE+author:              Daniel Campoverde+maintainer:          alx@sillybytes.net+copyright:           2017 Daniel Campoverde+category:            Web+build-type:          Simple+extra-source-files:  README.md+cabal-version:       >=1.10++library+  hs-source-dirs:      src+  exposed-modules:     Yesod.Alert+                     , Yesod.Alert.Bootstrap3+                     , Yesod.Alert.Bootstrap4+                     , Yesod.Alert.Foundation5+  build-depends:       base >= 4.7 && < 5+                     , alerts >= 0.1.0.0 && < 0.2.0.0+                     , text >= 0.11 && < 2.0+                     , safe >= 0.3.14 && < 0.4+                     , yesod-core >= 1.4.32 && < 1.5+                     , blaze-html+                     , blaze-markup+  ghc-options:         -Wall -fwarn-tabs -O2+  default-language:    Haskell2010++source-repository head+  type:     git+  location: https://github.com/alx741/yesod-alerts