packages feed

happstack-heist (empty) → 0.5.1

raw patch · 4 files changed

+113/−0 lines, 4 filesdep +basedep +bytestringdep +filepathsetup-changed

Dependencies added: base, bytestring, filepath, happstack-server, heist, hexpat, mtl

Files

+ Happstack/Server/Heist.hs view
@@ -0,0 +1,53 @@+-- | functions for using Heist with Happstack+--+-- See the Heist Section of the Happstack Crash Course for detailed documentation:+--+--  <http://happstack.com/docs/crashcourse/Templates.html#helloheist>+module Happstack.Server.Heist +    ( templateReloader+    , templateServe+    , render+    ) where++import Control.Monad                           (MonadPlus(mzero), msum)+import Control.Monad.Trans                     (MonadIO)+import           Data.ByteString.Char8         (ByteString)+import qualified Data.ByteString.Char8         as B+import qualified Data.ByteString.Lazy          as L+import Happstack.Server                        (Response, ServerMonad, askRq, nullDir, rqPaths, toResponseBS)+import System.FilePath                         (joinPath)+import Text.Templating.Heist                   (renderTemplate)+import Text.Templating.Heist.TemplateDirectory (TemplateDirectory, getDirectoryTS, reloadTemplateDirectory)+import qualified  Text.XML.Expat.Tree          as X++-- | serve the heist templates from the 'TemplateDirectory m'+templateServe :: (ServerMonad m, MonadPlus m, MonadIO m) =>+                 TemplateDirectory m +              -> m Response+templateServe td = +    msum [ nullDir >> render td (B.pack "index")+         , do rq <- askRq+              let safepath = joinPath $ filter (\x->not (null x) && x /= ".." && x /= ".") (rqPaths rq)+              render td (B.pack safepath)+         ]++-- | force a reload of the templates from disk+templateReloader :: (MonadIO m, MonadIO n) => +                    TemplateDirectory m +                 -> n Response+templateReloader td = do+    e <- reloadTemplateDirectory td+    return $ toResponseBS (B.pack "text/plain; charset=utf-8") $+        L.fromChunks [either B.pack (const $ B.pack "Templates loaded successfully.") e]+++-- | render the specified template+render:: (MonadPlus m, MonadIO m) => +         TemplateDirectory m  -- ^ 'TemplateDirectory' handle+      -> ByteString -- ^ template name+      -> m Response+render td template = do+    ts    <- getDirectoryTS td+    bytes <- renderTemplate ts template+    flip (maybe mzero) bytes $ \x -> do+        return (toResponseBS (B.pack "text/html; charset=utf-8") (L.fromChunks [x]))
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2010, Chris Smith, 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-heist.cabal view
@@ -0,0 +1,28 @@+Name:                happstack-heist+Version:             0.5.1+Synopsis:            Support for using Heist templates in Happstack+Description:         Happstack is a web application framework. Heist is an XML templating solution. This package makes it easy to use Heist templates with Happstack.+Homepage:            http://www.happstack.com/+License:             BSD3+License-file:        LICENSE+Author:              Chris Smith, Jeremy Shaw+Maintainer:          Happstack team <happs@googlegroups.com>+-- Copyright:           +Category:            Web+Build-type:          Simple+Cabal-version:       >=1.6++source-repository head+    type:     darcs+    subdir:   happstack-heist+    location: http://patch-tag.com/r/mae/happstack++Library+  Exposed-modules:     Happstack.Server.Heist+  Build-depends:       base >= 3.0 && < 5.0,+                       bytestring == 0.9.*,+                       filepath,+                       happstack-server >= 0.5.0.3 && < 7,+                       heist == 0.2.*,+                       hexpat == 0.19.*,+                       mtl == 2.*