happstack-hamlet (empty) → 0.1
raw patch · 4 files changed
+127/−0 lines, 4 filesdep +basedep +bytestringdep +containerssetup-changed
Dependencies added: base, bytestring, containers, hamlet, happstack-server, text
Files
- Happstack/Server/Hamlet.hs +57/−0
- LICENSE +30/−0
- Setup.hs +2/−0
- happstack-hamlet.cabal +38/−0
+ Happstack/Server/Hamlet.hs view
@@ -0,0 +1,57 @@+{-# LANGUAGE QuasiQuotes, ScopedTypeVariables, FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, UndecidableInstances #-}+module Happstack.Server.Hamlet + ( hamletToResponse + )+ where++import qualified Data.ByteString.Char8 as B+import qualified Data.ByteString.Lazy.Char8 as L+import qualified Data.Map as M+import qualified Data.Text.Lazy.Encoding as T ++import Text.Hamlet+import Text.Hamlet.Monad (hamletToText, liftHamlet)+import Happstack.Server+++-- |turn a 'Hamlet' template into a Happstack 'Response'+hamletToResponse :: (Monad m) => + (url -> String) -> -- ^ function to 'url' values in the template into their 'String' representation+ Hamlet url m () -> -- ^ a 'Hamlet' template+ m Response+hamletToResponse showFn hamlet = + do msg <- hamletToText showFn hamlet+ return $ toResponse_ (B.pack "text/html; charset=UTF-8") (T.encodeUtf8 msg)++-- available as toResponseBS in happstack-server >= 0.5+toResponse_ :: B.ByteString -> L.ByteString -> Response+toResponse_ contentType message =+ let res = Response 200 M.empty nullRsFlags message Nothing+ in setHeaderBS (B.pack "Content-Type") contentType res++mapHamlet :: forall a b url m. (Monad m) => (m a -> m b) -> Hamlet url m a -> Hamlet url m b+mapHamlet f m = + Hamlet $ \showFn seed iteratee -> f' (runHamlet m showFn seed iteratee)+ where+ f' :: m (Either seed (a, seed)) -> m (Either seed (b, seed))+ f' m =+ do e <- m+ case e of+ (Left s) -> return (Left s)+ (Right (a, seed)) -> + do b <- f (return a)+ return (Right (b, seed))++instance (ServerMonad m) => ServerMonad (Hamlet url m) where+ askRq = liftHamlet askRq+ localRq f = mapHamlet (localRq f)++instance (FilterMonad r m) => FilterMonad r (Hamlet url m) where+ setFilter = liftHamlet . setFilter+ composeFilter = liftHamlet . composeFilter+ getFilter = mapHamlet getFilter++instance (WebMonad a m) => WebMonad a (Hamlet url m) where+ finishWith = liftHamlet . finishWith++
+ LICENSE view
@@ -0,0 +1,30 @@+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.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ happstack-hamlet.cabal view
@@ -0,0 +1,38 @@+Name: happstack-hamlet+Version: 0.1+Synopsis: Support for Hamlet HTML templates in Happstack++Description: Happstack is a web application development framework. + Hamlet provides HTML templates which are checked for + correctness at compile time. This package add support+ for using Hamlet templates with Happstack.+Homepage: http://www.happstack.com/+License: BSD3+License-file: LICENSE+Author: Jeremy Shaw+Maintainer: jeremy@seereason.com+Copyright: 2010 Jeremy Shaw+Category: Web+Build-type: Simple+Cabal-version: >=1.6++source-repository head+ type: darcs+ subdir: happstack-hamlet+ location: http://patch-tag.com/r/mae/happstack/pullrepo++Library+ Exposed-modules: Happstack.Server.Hamlet+ Build-depends: base >= 3 && <5,+ bytestring,+ containers,+ happstack-server >= 0.4.3 && <0.6 ,+ hamlet,+ text+ + -- Modules not exported by this package.+ -- Other-modules: + + -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.+ -- Build-tools: +