packages feed

hack-contrib-press (empty) → 0.1.0

raw patch · 4 files changed

+64/−0 lines, 4 filesdep +basedep +bytestringdep +bytestring-classsetup-changed

Dependencies added: base, bytestring, bytestring-class, containers, hack, json, mtl, parsec, press

Files

+ Hack/Contrib/Press.hs view
@@ -0,0 +1,43 @@+module Hack.Contrib.Press (renderToResponse, envToJS, defaultContext) where++import Data.ByteString.Class+import Data.Data+import Hack+import Text.JSON+import Text.JSON.Generic (toJSON)+import Text.Press.Run+import qualified Hack++-- converts a context and template name or body into a response++renderToResponse :: Hack.Env -> String -> [JSValue] -> IO Response+renderToResponse env filename context = runJSValuesWithPath sl filename >>= resultToResponse+    where sl = context ++ (defaultContext env)++envToJS :: Hack.Env -> JSValue+envToJS env = env'+    where+        env' = JSObject $ toJSObject [+            ("requestMethod", toJSON . show $ requestMethod env),+            ("scriptName", toJSON $ scriptName env),+            ("queryString", toJSON $ queryString env),+            ("serverName", toJSON $ serverName env),+            ("serverPort", toJSON $ serverPort env),+            ("http", toJSON $ http env),+            ("hackVersion", toJSON $ hackVersion env),+            ("hackHeaders", toJSON $ hackHeaders env), +            ("hackUrlScheme", toJSON . show $ hackUrlScheme env)+            ]++defaultContext :: Hack.Env -> [JSValue]+defaultContext env = [JSObject $ toJSObject [("env", envToJS env)]]++resultToResponse result = do+    case result of +        Left err -> error $ show err+        Right succ -> do+            return $ Hack.Response {+                status = 200,+                headers = [("Content-Type", "text/html")],+                body = toLazyByteString $ foldl (++) "" succ+            }
+ LICENSE view
@@ -0,0 +1,1 @@+GPL v3 or Later.
+ Setup.hs view
@@ -0,0 +1,4 @@+#!/usr/bin/env runhaskell+import Distribution.Simple++main = defaultMain 
+ hack-contrib-press.cabal view
@@ -0,0 +1,16 @@+Name:                hack-contrib-press+Version:             0.1.0+Synopsis:            Hack helper that renders Press templates+Description:         Hack helper that renders Press templates+Category:            Text, Web+License:             GPL+License-File:        LICENSE+Author:              Brandon Bickford <bickfordb@gmail.com>+Maintainer:          bickfordb@gmail.com+Homepage:            http://github.com/bickfordb/hack-contrib-press+Build-Type:          Simple+Cabal-Version:       >= 1.2++Library+  Build-Depends:     base < 4, bytestring, bytestring-class, containers, mtl, hack >= 2009.7.15, parsec >= 3.0.0, press, json+  Exposed-Modules:   Hack.Contrib.Press