happstack-hsp-7.3.7.4/0000755000000000000000000000000013564530773012643 5ustar0000000000000000happstack-hsp-7.3.7.4/happstack-hsp.cabal0000644000000000000000000000306013564530773016374 0ustar0000000000000000Name: happstack-hsp Version: 7.3.7.4 Synopsis: Support for using HSP templates in Happstack Description: Happstack is a web application framework. HSP is an XML templating solution. This package makes it easy to use HSP templates with Happstack. Homepage: http://www.happstack.com/ License: BSD3 License-file: LICENSE Author: Jeremy Shaw Maintainer: Happstack team Copyright: 2011-2015 Jeremy Shaw Category: Web, Happstack Build-type: Simple Cabal-version: >=1.6 tested-with: GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.1 source-repository head type: git location: https://github.com/Happstack/happstack-hsp.git Library Hs-source-dirs: src Exposed-modules: Happstack.Server.HSP.HTML Happstack.Server.XMLGenT HSP.ServerPartT HSP.Google.Analytics Build-depends: base >= 3.0 && < 5.0, bytestring >= 0.9 && < 0.11, happstack-server >= 6.0 && < 7.7, harp >= 0.4 && < 0.5, hsp >= 0.9.2 && < 0.11, hsx2hs >= 0.13.0 && < 0.15, mtl >= 1.1 && < 2.3, utf8-string >= 0.3 && < 1.1, syb >= 0.3 && < 0.8, text >= 0.10 && < 1.3 happstack-hsp-7.3.7.4/Setup.hs0000644000000000000000000000005613564530773014300 0ustar0000000000000000import Distribution.Simple main = defaultMain happstack-hsp-7.3.7.4/LICENSE0000644000000000000000000000275713564530773013663 0ustar0000000000000000Copyright (c)2010, Jeremy Shaw 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 Jeremy Shaw 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. happstack-hsp-7.3.7.4/src/0000755000000000000000000000000013564530773013432 5ustar0000000000000000happstack-hsp-7.3.7.4/src/HSP/0000755000000000000000000000000013564530773014064 5ustar0000000000000000happstack-hsp-7.3.7.4/src/HSP/ServerPartT.hs0000644000000000000000000001112413564530773016640 0ustar0000000000000000-- |This module provides, @instance 'XMLGenerator' ('ServerPartT' m)@ {-# LANGUAGE CPP, MultiParamTypeClasses, TypeSynonymInstances, FlexibleContexts, FlexibleInstances, TypeFamilies, OverloadedStrings #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module HSP.ServerPartT () where import Control.Monad (liftM) import Data.Monoid ((<>)) import qualified Data.Text as T import qualified Data.Text.Lazy as TL import HSP.XML import HSP.XMLGenerator import Happstack.Server (ServerPartT) instance (Monad m) => XMLGen (ServerPartT m) where type XMLType (ServerPartT m) = XML type StringType (ServerPartT m) = TL.Text newtype ChildType (ServerPartT m) = SChild { unSChild :: XML } newtype AttributeType (ServerPartT m) = SAttr { unSAttr :: Attribute } genElement n attrs children = do attribs <- map unSAttr `liftM` asAttr attrs childer <- (flattenCDATA . map unSChild) `liftM`asChild children return (Element (toName n) attribs childer ) xmlToChild = SChild pcdataToChild = xmlToChild . pcdata flattenCDATA :: [XML] -> [XML] flattenCDATA cxml = case flP cxml [] of [] -> [] [CDATA _ ""] -> [] xs -> xs where flP :: [XML] -> [XML] -> [XML] flP [] bs = reverse bs flP [x] bs = reverse (x:bs) flP (x:y:xs) bs = case (x,y) of (CDATA e1 s1, CDATA e2 s2) | e1 == e2 -> flP (CDATA e1 (s1<>s2) : xs) bs _ -> flP (y:xs) (x:bs) {- instance (Monad m) => IsAttrValue (ServerPartT m) T.Text where toAttrValue = toAttrValue . T.unpack instance (Monad m) => IsAttrValue (ServerPartT m) TL.Text where toAttrValue = toAttrValue . TL.unpack -} instance (Functor m, Monad m) => EmbedAsAttr (ServerPartT m) Attribute where asAttr = return . (:[]) . SAttr instance (Functor m, Monad m, IsName n TL.Text) => EmbedAsAttr (ServerPartT m) (Attr n Char) where asAttr (n := c) = asAttr (n := [c]) instance (Functor m, Monad m, IsName n TL.Text) => EmbedAsAttr (ServerPartT m) (Attr n String) where asAttr (n := str) = asAttr $ MkAttr (toName n, pAttrVal $ TL.pack str) instance (Functor m, Monad m, IsName n TL.Text) => EmbedAsAttr (ServerPartT m) (Attr n Bool) where asAttr (n := True) = asAttr $ MkAttr (toName n, pAttrVal "true") asAttr (n := False) = asAttr $ MkAttr (toName n, pAttrVal "false") instance (Functor m, Monad m, IsName n TL.Text) => EmbedAsAttr (ServerPartT m) (Attr n Int) where asAttr (n := i) = asAttr $ MkAttr (toName n, pAttrVal (TL.pack $ show i)) instance (Functor m, Monad m, IsName n TL.Text) => (EmbedAsAttr (ServerPartT m) (Attr n TL.Text)) where asAttr (n := a) = asAttr $ MkAttr (toName n, pAttrVal $ a) instance (Functor m, Monad m, IsName n TL.Text) => (EmbedAsAttr (ServerPartT m) (Attr n T.Text)) where asAttr (n := a) = asAttr $ MkAttr (toName n, pAttrVal $ TL.fromStrict a) instance (Functor m, Monad m) => EmbedAsChild (ServerPartT m) Char where asChild = XMLGenT . return . (:[]) . SChild . pcdata . TL.singleton instance (Functor m, Monad m) => EmbedAsChild (ServerPartT m) String where asChild = XMLGenT . return . (:[]) . SChild . pcdata . TL.pack instance (Functor m, Monad m) => EmbedAsChild (ServerPartT m) Int where asChild = XMLGenT . return . (:[]) . SChild . pcdata . TL.pack . show instance (Functor m, Monad m) => EmbedAsChild (ServerPartT m) Integer where asChild = XMLGenT . return . (:[]) . SChild . pcdata . TL.pack . show instance (Functor m, Monad m) => EmbedAsChild (ServerPartT m) XML where asChild = XMLGenT . return . (:[]) . SChild instance Monad m => EmbedAsChild (ServerPartT m) () where asChild () = return [] instance (Functor m, Monad m) => (EmbedAsChild (ServerPartT m) TL.Text) where asChild = asChild . TL.unpack instance (Functor m, Monad m) => (EmbedAsChild (ServerPartT m) T.Text) where asChild = asChild . T.unpack instance (Functor m, Monad m) => AppendChild (ServerPartT m) XML where appAll xml children = do chs <- children case xml of CDATA _ _ -> return xml Element n as cs -> return $ Element n as (cs ++ (map unSChild chs)) instance (Functor m, Monad m) => SetAttr (ServerPartT m) XML where setAll xml hats = do attrs <- hats case xml of CDATA _ _ -> return xml Element n as cs -> return $ Element n (foldr (:) as (map unSAttr attrs)) cs instance (Functor m, Monad m) => XMLGenerator (ServerPartT m) happstack-hsp-7.3.7.4/src/HSP/Google/0000755000000000000000000000000013564530773015300 5ustar0000000000000000happstack-hsp-7.3.7.4/src/HSP/Google/Analytics.hs0000644000000000000000000001060313564530773017563 0ustar0000000000000000{-# LANGUAGE DeriveDataTypeable, PatternGuards, FlexibleContexts, TypeFamilies, OverloadedStrings, QuasiQuotes #-} module HSP.Google.Analytics ( UACCT(..) , analytics , analyticsAsync , universalAnalytics ) where import Data.Generics (Data, Typeable) import Data.Text.Lazy (Text,pack) import HSP import Prelude hiding (head) import Language.Haskell.HSX.QQ (hsx) newtype UACCT = UACCT String -- ^ The UACCT provided to you by Google (looks like: @UA-XXXXX-X@) deriving (Read, Show, Eq, Ord, Typeable, Data) -- | create the google analytics asynchronous tracking script tag -- -- This uses the now dubbed 'classic google analytics' -- -- NOTE: you must put this right before the \<\/head\> tag -- see also: universalAnalytics analyticsAsync :: (XMLGenerator m, StringType m ~ Text) => UACCT -- ^ web property ID (looks like: @UA-XXXXX-X@) -> GenXML m analyticsAsync (UACCT uacct) = [hsx| |] universalAnalytics :: (XMLGenerator m, StringType m ~ Text) => UACCT -- ^ web property ID (looks like: @UA-XXXXX-X@) -> GenXML m universalAnalytics (UACCT uacct) = [hsx| |] -- | create the (even older) google analytics script tags -- -- NOTE: you must put the <% analytics yourUACCT %> immediately before the tag -- -- You probably want to use 'analyticsAsync' instead. -- -- See also: 'addAnalytics', 'analyticsAsync', 'universalAnalytics' analytics :: (XMLGenerator m, StringType m ~ Text) => UACCT -> GenXMLList m analytics (UACCT uacct) = do a <- [hsx| |] b <- [hsx| |] return [a,b] {- removed because the hsx qq does not currently support patterns. -- | automatically add the google analytics scipt tags immediately before the element -- NOTE: this function is not idepotent addAnalytics :: ( AppendChild m XML , EmbedAsChild m XML , EmbedAsAttr m Attribute , XMLGenerator m , XMLType m ~ XML , StringType m ~ Text ) => UACCT -> XMLGenT m XML -> GenXML m addAnalytics uacct pg = do page <- pg a <- analytics uacct case page of [hsx| <[ head, body ]> |] -> [hsx| <% head %> <% body <: (a :: [XML]) %> |] o -> error ("Failed to add analytics." ++ show o) -} {- Example Analytics Code from Google: -} happstack-hsp-7.3.7.4/src/Happstack/0000755000000000000000000000000013564530773015350 5ustar0000000000000000happstack-hsp-7.3.7.4/src/Happstack/Server/0000755000000000000000000000000013564530773016616 5ustar0000000000000000happstack-hsp-7.3.7.4/src/Happstack/Server/XMLGenT.hs0000644000000000000000000000434713564530773020400 0ustar0000000000000000-- | This module contains orphan 'XMLGenT' instances for 'ServerMonad', 'FilterMonad', 'WebMonad', 'HasRqData', and 'Happstack'. It does not export any functions. {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, TypeFamilies, UndecidableInstances #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Happstack.Server.XMLGenT where import Control.Applicative (Alternative(..)) import Control.Monad (MonadPlus(..)) import Control.Monad.Trans (MonadIO(..)) import Happstack.Server.SimpleHTTP (ServerMonad(..), FilterMonad(..), WebMonad(..), HasRqData(..), Happstack(..), Response) import HSP.XMLGenerator (XMLGenT(..)) import HSP.Monad (HSPT(..)) instance (ServerMonad m) => ServerMonad (XMLGenT m) where askRq = XMLGenT askRq localRq f (XMLGenT m) = XMLGenT (localRq f m) instance (FilterMonad a m) => FilterMonad a (XMLGenT m) where setFilter = XMLGenT . setFilter composeFilter f = XMLGenT (composeFilter f) getFilter (XMLGenT m) = XMLGenT (getFilter m) instance (WebMonad a m) => WebMonad a (XMLGenT m) where finishWith r = XMLGenT $ finishWith r instance (HasRqData m) => (HasRqData (XMLGenT m)) where askRqEnv = XMLGenT askRqEnv localRqEnv f (XMLGenT m) = XMLGenT (localRqEnv f m) rqDataError = XMLGenT . rqDataError instance (Alternative m, MonadPlus m, Functor m, MonadIO m, ServerMonad m, FilterMonad a m, WebMonad a m, HasRqData m, a ~ Response) => Happstack (XMLGenT m) instance (ServerMonad m) => ServerMonad (HSPT xml m) where askRq = HSPT askRq localRq f (HSPT m) = HSPT (localRq f m) instance (FilterMonad a m) => FilterMonad a (HSPT xml m) where setFilter = HSPT . setFilter composeFilter f = HSPT (composeFilter f) getFilter (HSPT m) = HSPT (getFilter m) instance (WebMonad a m) => WebMonad a (HSPT xml m) where finishWith r = HSPT $ finishWith r instance (HasRqData m) => (HasRqData (HSPT xml m)) where askRqEnv = HSPT askRqEnv localRqEnv f (HSPT m) = HSPT (localRqEnv f m) rqDataError = HSPT . rqDataError instance (Alternative m, MonadPlus m, Functor m, MonadIO m, ServerMonad m, FilterMonad a m, WebMonad a m, HasRqData m, a ~ Response) => Happstack (HSPT xml m) happstack-hsp-7.3.7.4/src/Happstack/Server/HSP/0000755000000000000000000000000013564530773017250 5ustar0000000000000000happstack-hsp-7.3.7.4/src/Happstack/Server/HSP/HTML.hs0000644000000000000000000000355713564530773020362 0ustar0000000000000000-- | support for using HSP+Happstack for rendering HTML {-# LANGUAGE FlexibleInstances, FlexibleContexts, QuasiQuotes, TypeFamilies, OverloadedStrings #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Happstack.Server.HSP.HTML ( defaultTemplate ) where import Control.Monad.Trans (MonadIO(), liftIO) import Data.Monoid ((<>)) import qualified Data.Text.Encoding as T import qualified Data.Text.Lazy.Builder as TL import qualified Data.Text.Lazy.Encoding as TL import qualified Data.Text.Lazy as TL import Data.Text.Lazy (Text) import Language.Haskell.HSX.QQ (hsx) import Control.Monad (liftM) import Happstack.Server ( ToMessage(toMessage, toContentType, toResponse) , Response ) import HSP import HSP.HTML4 instance ToMessage (Maybe XMLMetaData, XML) where toContentType (Just md,_) = T.encodeUtf8 $ TL.toStrict (contentType md) toContentType _ = "text/html;charset=utf-8" toMessage (Just (XMLMetaData (showDt, dt) _ pr), xml) = TL.encodeUtf8 $ TL.toLazyText ((if showDt then ((TL.fromLazyText dt) <>) else id) (pr xml)) toMessage (Nothing, xml) = TL.encodeUtf8 (renderAsHTML xml) instance ToMessage XML where toContentType _ = "text/html;charset=utf-8" toMessage xml = toMessage (html4Strict, xml) -- | A generic webpage template defaultTemplate :: ( XMLGenerator m, EmbedAsChild m headers , EmbedAsChild m body, StringType m ~ Text) => TL.Text -- ^ text to use in \ tag -> headers -- ^ extra headers to insert in \ tag. Use @()@ if none. -> body -- ^ content to put between the \ tags. -> m (XMLType m) defaultTemplate title headers body = unXMLGenT $ [hsx| <% title %> <% headers %> <% body %> |]