packages feed

wai-hastache (empty) → 0.1

raw patch · 5 files changed

+132/−0 lines, 5 filesdep +basedep +bytestringdep +hastachesetup-changed

Dependencies added: base, bytestring, hastache, http-types, transformers, wai

Files

+ COPYING view
@@ -0,0 +1,13 @@+Copyright © 2012, Stephen Paul Weber <singpolyma.net>++Permission to use, copy, modify, and/or distribute this software for any+purpose with or without fee is hereby granted, provided that the above+copyright notice and this permission notice appear in all copies.++THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ Network/Wai/Hastache.hs view
@@ -0,0 +1,77 @@+module Network.Wai.Hastache (+		hastache,+		hastacheHTML,+		hastacheText,+		hastacheStr,+		hastacheStrHTML,+		hastacheStrText,+		MuConfig(..),+		MuContext,+		MuType(..)+	) where++import Data.String (IsString, fromString)+import Control.Monad.IO.Class (MonadIO)++import Network.Wai (Response(..))+import Network.HTTP.Types (Status, ResponseHeaders, Header)++import Text.Hastache (hastacheFileBuilder, hastacheStrBuilder, htmlEscape, emptyEscape, MuConfig(..), MuContext, MuType(..))+import Data.ByteString (ByteString)++mapHeader :: (ResponseHeaders -> ResponseHeaders) -> Response -> Response+mapHeader f (ResponseFile s h b1 b2) = ResponseFile s (f h) b1 b2+mapHeader f (ResponseBuilder s h b) = ResponseBuilder s (f h) b+mapHeader f (ResponseSource s h b) = ResponseSource s (f h) b++defHeader :: Header -> Response -> Response+defHeader h = mapHeader (defHeader' h)++defHeader' :: Header -> ResponseHeaders -> ResponseHeaders+defHeader' (n, v) headers = case lookup n headers of+		Just _  -> headers+		Nothing -> (n, v):headers++-- | Build a response based on a configuration and a template in a file.+hastache :: (Functor m, MonadIO m) => Status -> ResponseHeaders -> MuConfig -> FilePath -> MuContext m -> m Response+hastache status headers cfg pth ctx = fmap (ResponseBuilder status headers) (+		hastacheFileBuilder cfg pth ctx+	)++-- | Build an HTML-escaped response based on a template in a file.+--   Defaults Content-Type to text/html if you do not specify.+hastacheHTML :: (Functor m, MonadIO m) => Status -> ResponseHeaders -> FilePath -> MuContext m -> m Response+hastacheHTML status headers pth ctx = defHeader defCT `fmap` hastache status headers+	(MuConfig htmlEscape Nothing (Just "mustache")) pth ctx+	where+	defCT = (fromString "Content-Type", fromString "text/html; charset=utf-8")++-- | Build an unescaped response based on a template in a file.+--   Defaults Content-Type to text/plain if you do not specify.+hastacheText :: (Functor m, MonadIO m) => Status -> ResponseHeaders -> FilePath -> MuContext m -> m Response+hastacheText status headers pth ctx = defHeader defCT `fmap` hastache status headers+	(MuConfig emptyEscape Nothing (Just "mustache")) pth ctx+	where+	defCT = (fromString "Content-Type", fromString "text/plain; charset=utf-8")++-- | Build a response based on a configuration and a template in a 'ByteString'.+hastacheStr :: (Functor m, MonadIO m) => Status -> ResponseHeaders -> MuConfig -> ByteString -> MuContext m -> m Response+hastacheStr status headers cfg tpl ctx = fmap (ResponseBuilder status headers) (+		hastacheStrBuilder cfg tpl ctx+	)++-- | Build an HTML-escaped response based on a template in a 'ByteString'.+--   Defaults Content-Type to text/html if you do not specify.+hastacheStrHTML :: (Functor m, MonadIO m) => Status -> ResponseHeaders -> ByteString -> MuContext m -> m Response+hastacheStrHTML status headers tpl ctx = defHeader defCT `fmap` hastacheStr status headers+	(MuConfig htmlEscape Nothing (Just "mustache")) tpl ctx+	where+	defCT = (fromString "Content-Type", fromString "text/html; charset=utf-8")++-- | Build an unescaped response based on a template in a 'ByteString'.+--   Defaults Content-Type to text/plain if you do not specify.+hastacheStrText :: (Functor m, MonadIO m) => Status -> ResponseHeaders -> ByteString -> MuContext m -> m Response+hastacheStrText status headers tpl ctx = defHeader defCT `fmap` hastacheStr status headers+	(MuConfig htmlEscape Nothing (Just "mustache")) tpl ctx+	where+	defCT = (fromString "Content-Type", fromString "text/plain; charset=utf-8")
+ README view
@@ -0,0 +1,2 @@+Provides smart constructors for WAI responses using Hastache for+rendering mustache templates.
+ Setup.hs view
@@ -0,0 +1,3 @@+import Distribution.Simple++main = defaultMain
+ wai-hastache.cabal view
@@ -0,0 +1,37 @@+name:            wai-hastache+version:         0.1+cabal-version:   >= 1.8+license:         OtherLicense+license-file:    COPYING+category:        Web+copyright:       © 2012 Stephen Paul Weber+author:          Stephen Paul Weber <singpolyma@singpolyma.net>+maintainer:      Stephen Paul Weber <singpolyma@singpolyma.net>+stability:       experimental+tested-with:     GHC == 7.0.3+synopsis:        Nice wrapper around hastache for use with WAI+homepage:        https://github.com/singpolyma/wai-hastache+bug-reports:     https://github.com/singpolyma/wai-hastache/issues+build-type:      Simple+description:+        Provides smart constructors for WAI responses using Hastache for+        rendering mustache templates.++extra-source-files:+        README++library+        exposed-modules:+                Network.Wai.Hastache++        build-depends:+                base == 4.*,+                hastache,+                wai,+                http-types,+                bytestring,+                transformers++source-repository head+        type:     git+        location: git://github.com/singpolyma/wai-hastache.git