Permalink
Browse files

Change code generated by iSplices to match old interpreted splice style

  • Loading branch information...
1 parent dbcc412 commit 701771af6753eca4b30405b52442e5a0dc5b2c64 Doug Beardsley committed Mar 1, 2013
Showing with 10 additions and 10 deletions.
  1. +1 −1 restful-snap.cabal
  2. +5 −7 src/Snap/Restful.hs
  3. +4 −2 src/Snap/Restful/TH.hs
View
@@ -34,7 +34,7 @@ library
readable >= 0.1 && < 0.2,
snap-core >= 0.9 && < 0.10,
snap >= 0.11 && < 0.12,
- template-haskell >= 2.8 && < 2.9,
+ template-haskell >= 2.4 && < 2.9,
text >= 0.11 && < 0.12,
time >= 1.4 && < 1.5,
xmlhtml >= 0.2 && < 0.3
View
@@ -1,5 +1,4 @@
{-# LANGUAGE DeriveDataTypeable #-}
-{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
@@ -73,7 +72,6 @@ import qualified Data.Text.Encoding as T
import Data.Time
import Data.Typeable
import Data.Word
-import GHC.Generics
import Heist
import qualified Heist.Compiled as C
import qualified Heist.Interpreted as I
@@ -116,7 +114,7 @@ data CRUD = RIndex
newtype DBId = DBId { unDBId :: Word64 }
- deriving (Eq,Show,Read,Ord,Num,Generic,Typeable)
+ deriving (Eq,Show,Read,Ord,Num,Typeable)
instance Default DBId where
@@ -430,12 +428,12 @@ simpleDateFormlet d = validate validDate $
------------------------------------------------------------------------------
-- |
class PrimSplice a where
- iPrimSplice :: a -> [X.Node]
+ iPrimSplice :: Monad m => a -> m [X.Node]
cPrimSplice :: a -> Builder
-iPrimText :: Text -> [X.Node]
-iPrimText t = [X.TextNode t]
-iPrimShow :: Show a => a -> [X.Node]
+iPrimText :: Monad m => Text -> m [X.Node]
+iPrimText t = return [X.TextNode t]
+iPrimShow :: (Monad m, Show a) => a -> m [X.Node]
iPrimShow = iPrimText . T.pack . show
cPrimShow :: Show a => a -> Builder
View
@@ -72,17 +72,19 @@ deriveHasFormlet n = do
--
-- Usage:
--
+-- > fooSplices :: Monad m => Foo -> [(Text, I.Splice m)]
-- > fooSplices = $(iSplices ''Foo)
iSplices :: Name -> Q Exp
iSplices n = do
cons <- nameCons n
case cons of
[RecC conName fields] -> do
+ param <- newName "x"
let fieldToTuple (fn,_,_) = do
- f <- [| iPrimSplice . $(varE fn) |]
+ f <- [| iPrimSplice $ $(appE (varE fn) (varE param)) |]
return $ TupE [LitE $ StringL $ nameBase fn, f]
fs <- mapM fieldToTuple fields
- return $ ListE fs
+ return $ LamE [VarP param] (ListE fs)
_ -> error "You can only generate splices for a data type with a single constructor and named record fields"

0 comments on commit 701771a

Please sign in to comment.