happstack-hsp-7.3.7.4/ 0000755 0000000 0000000 00000000000 13564530773 012643 5 ustar 00 0000000 0000000 happstack-hsp-7.3.7.4/happstack-hsp.cabal 0000644 0000000 0000000 00000003060 13564530773 016374 0 ustar 00 0000000 0000000 Name: 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.hs 0000644 0000000 0000000 00000000056 13564530773 014300 0 ustar 00 0000000 0000000 import Distribution.Simple
main = defaultMain
happstack-hsp-7.3.7.4/LICENSE 0000644 0000000 0000000 00000002757 13564530773 013663 0 ustar 00 0000000 0000000 Copyright (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/ 0000755 0000000 0000000 00000000000 13564530773 013432 5 ustar 00 0000000 0000000 happstack-hsp-7.3.7.4/src/HSP/ 0000755 0000000 0000000 00000000000 13564530773 014064 5 ustar 00 0000000 0000000 happstack-hsp-7.3.7.4/src/HSP/ServerPartT.hs 0000644 0000000 0000000 00000011124 13564530773 016640 0 ustar 00 0000000 0000000 -- |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/ 0000755 0000000 0000000 00000000000 13564530773 015300 5 ustar 00 0000000 0000000 happstack-hsp-7.3.7.4/src/HSP/Google/Analytics.hs 0000644 0000000 0000000 00000010603 13564530773 017563 0 ustar 00 0000000 0000000 {-# 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
tags.
-> m (XMLType m)
defaultTemplate title headers body =
unXMLGenT $ [hsx|
<% title %>
<% headers %>
<% body %>
|]