alerts (empty) → 0.1.0.0
raw patch · 9 files changed
+294/−0 lines, 9 filesdep +basedep +blaze-htmldep +textsetup-changed
Dependencies added: base, blaze-html, text
Files
- LICENSE +30/−0
- README.md +12/−0
- Setup.hs +2/−0
- alerts.cabal +37/−0
- src/Web/Alert.hs +21/−0
- src/Web/Alert/Renderer/Bootstrap3.hs +47/−0
- src/Web/Alert/Renderer/Bootstrap4.hs +48/−0
- src/Web/Alert/Renderer/Common.hs +39/−0
- src/Web/Alert/Renderer/Foundation5.hs +58/−0
+ 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,12 @@+# alerts++Generate Alerts for web applications++```haskell+alert1 = Alert Success "Yay!"+alert2 = Alert Error "Oops!"++html1 = renderAlertsBootstrap3 [alert1, alert2]+html2 = renderAlertsBootstrap4 [alert1, alert2]+html3 = renderAlertsFoundation5 Round [alert1, alert2]+```
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ alerts.cabal view
@@ -0,0 +1,37 @@+name: alerts+version: 0.1.0.0+synopsis: Alert messages for web applications+description: Alert messages for web applications:+ .+ * Bootstrap 3+ .+ * Bootstrap 4+ .+ * Foundation 5+homepage: https://github.com/alx741/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: Web.Alert+ , Web.Alert.Renderer.Bootstrap3+ , Web.Alert.Renderer.Bootstrap4+ , Web.Alert.Renderer.Foundation5+ other-modules: Web.Alert.Renderer.Common+ ghc-options: -Wall -fwarn-tabs -O2+ build-depends: base >= 4.7 && < 5+ , text >= 0.11 && < 2.0+ , blaze-html+ default-language: Haskell2010++source-repository head+ type: git+ location: https://github.com/alx741/alerts
+ src/Web/Alert.hs view
@@ -0,0 +1,21 @@+-- | Create web 'Alert's of a given 'AlertStatus'++module Web.Alert+ ( Alert(..)+ , AlertStatus(..)+ ) where++import Data.Text.Lazy++data Alert = Alert+ { alertStatus :: AlertStatus+ , alertMessage :: Text+ } deriving (Eq, Show, Read)++data AlertStatus+ = Default+ | Info+ | Success+ | Warning+ | Error+ deriving (Bounded, Eq, Show, Read)
+ src/Web/Alert/Renderer/Bootstrap3.hs view
@@ -0,0 +1,47 @@+{-# LANGUAGE OverloadedStrings #-}++-- | 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 Web.Alert.Renderer.Bootstrap3+ ( renderAlertsBootstrap3+ ) where++import Data.Text.Lazy+import Text.Blaze.Html+import qualified Text.Blaze.Html5 as H+import qualified Text.Blaze.Html5.Attributes as A++import Web.Alert+import Web.Alert.Renderer.Common++-- | Render alerts using Bootstrap v3.x alerts+renderAlertsBootstrap3 :: [Alert] -> Text+renderAlertsBootstrap3 = renderAlerts+ "alert"+ []+ (Just $ customAttribute "role" "alert")+ (Just close)+ bootstrap3Clases++close :: Html+close =+ H.button+ ! A.class_ "close"+ ! A.type_ "button"+ ! dataAttribute "dismiss" "alert"+ ! customAttribute "aria-label" "x" $ do+ H.span ! customAttribute "aria-hidden" "true"+ $ preEscapedToHtml ("×" :: Text)++bootstrap3Clases :: AlertStatus -> AttributeValue+bootstrap3Clases Default = "alert-default"+bootstrap3Clases Info = "alert-info"+bootstrap3Clases Success = "alert-success"+bootstrap3Clases Warning = "alert-warning"+bootstrap3Clases Error = "alert-danger"
+ src/Web/Alert/Renderer/Bootstrap4.hs view
@@ -0,0 +1,48 @@+{-# LANGUAGE OverloadedStrings #-}++-- | 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 Web.Alert.Renderer.Bootstrap4+ ( renderAlertsBootstrap4+ ) where++import Data.Text.Lazy+import Text.Blaze.Html+import qualified Text.Blaze.Html5 as H+import qualified Text.Blaze.Html5.Attributes as A++import Web.Alert+import Web.Alert.Renderer.Common++-- | Render alerts using Bootstrap v4.x alerts+renderAlertsBootstrap4 :: [Alert] -> Text+renderAlertsBootstrap4 = renderAlerts+ "alert"+ ["alert-dismissible", "fade", "show"]+ (Just $ customAttribute "role" "alert")+ (Just close)+ bootstrap4Clases++close :: Html+close =+ H.button+ ! A.class_ "close"+ ! A.type_ "button"+ ! dataAttribute "dismiss" "alert"+ ! customAttribute "aria-label" "x" $ do+ H.span ! customAttribute "aria-hidden" "true"+ $ preEscapedToHtml ("×" :: Text)+++bootstrap4Clases :: AlertStatus -> AttributeValue+bootstrap4Clases Default = "alert-primary"+bootstrap4Clases Info = "alert-info"+bootstrap4Clases Success = "alert-success"+bootstrap4Clases Warning = "alert-warning"+bootstrap4Clases Error = "alert-danger"
+ src/Web/Alert/Renderer/Common.hs view
@@ -0,0 +1,39 @@+{-# LANGUAGE OverloadedStrings #-}++module Web.Alert.Renderer.Common+ ( renderAlerts+ ) where++import Data.Maybe++import Data.Text.Lazy hiding (intersperse)+import Data.Monoid+import Data.List (intersperse)+import Data.Foldable (fold)+import Text.Blaze.Html+import Text.Blaze.Html.Renderer.Text+import qualified Text.Blaze.Html5 as H+import qualified Text.Blaze.Html5.Attributes as A++import Web.Alert++renderAlerts+ :: AttributeValue+ -> [AttributeValue]+ -> Maybe Attribute+ -> Maybe Html+ -> (AlertStatus -> AttributeValue)+ -> [Alert]+ -> Text+renderAlerts _ _ _ _ _ [] = mempty+renderAlerts baseClass extraClass mAttr mInternal clases msgs =+ renderHtml $ foldMap makeDivs msgs+ where+ attr = fromMaybe mempty mAttr+ internal = fromMaybe mempty mInternal+ extras = fold $ intersperse " " extraClass+ makeDivs (Alert stat msg) =+ H.div+ ! attr+ ! A.class_ (baseClass <> " " <> (clases stat) <> " " <> extras)+ $ internal <> (toHtml msg)
+ src/Web/Alert/Renderer/Foundation5.hs view
@@ -0,0 +1,58 @@+{-# LANGUAGE OverloadedStrings #-}++-- | Render 'Alert's using Foundation v5.x+--+-- Dependencies (These should be accessible in your app):+--+-- * Foundation's CSS and JS+--+-- * Modernizr+--+-- * JQuery++module Web.Alert.Renderer.Foundation5+ ( renderAlertsFoundation5+ , AlertType(..)+ ) where++import Data.Text.Lazy+import Text.Blaze.Html+import qualified Text.Blaze.Html5 as H+import qualified Text.Blaze.Html5.Attributes as A++import Web.Alert+import Web.Alert.Renderer.Common++-- | Render alerts using Foundation v5.x alerts+renderAlertsFoundation5 :: AlertType -> [Alert] -> Text+renderAlertsFoundation5 atype = renderAlerts+ "alert-box"+ [alertTypeClass atype]+ (Just $ dataAttribute "alert" "")+ (Just close)+ foundation5Clases++-- | Foundation 5.x alert type+data AlertType+ = Radius -- ^ Slightly rounded corners+ | Round -- ^ Fully rounded corners+ deriving (Eq, Show, Read)++close :: Html+close =+ H.button+ ! A.class_ "close"+ ! customAttribute "aria-label" "x"+ $ preEscapedToHtml ("×" :: Text)+++alertTypeClass :: AlertType -> AttributeValue+alertTypeClass Radius = "radius"+alertTypeClass Round = "round"++foundation5Clases :: AlertStatus -> AttributeValue+foundation5Clases Default = "secondary"+foundation5Clases Info = "info"+foundation5Clases Success = "success"+foundation5Clases Warning = "warning"+foundation5Clases Error = "alert"