From 7cd2f9f6c40c94d37fca68a0c43ad0ca45625378 Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Sun, 5 Jun 2011 01:24:54 +0400 Subject: [PATCH] Use macro to chose quasyquote syntax. Reduce clutter caused by --- Yesod/Auth.hs | 22 +++++----------------- Yesod/Auth/Dummy.hs | 8 +++----- Yesod/Auth/Email.hs | 36 +++++++----------------------------- Yesod/Auth/Facebook.hs | 8 +++----- Yesod/Auth/HashDB.hs | 31 ++++++------------------------- Yesod/Auth/OAuth.hs | 11 ++++------- Yesod/Auth/OpenId.hs | 14 ++++---------- Yesod/Auth/Rpxnow.hs | 8 +++----- include/qq.h | 10 ++++++++++ yesod-auth.cabal | 2 ++ 10 files changed, 47 insertions(+), 103 deletions(-) create mode 100644 include/qq.h diff --git a/Yesod/Auth.hs b/Yesod/Auth.hs index 2e087002..7142eaa6 100644 --- a/Yesod/Auth.hs +++ b/Yesod/Auth.hs @@ -22,6 +22,8 @@ module Yesod.Auth , requireAuth ) where +#include "qq.h" + import Yesod.Core import Yesod.Persist import Yesod.Json @@ -91,11 +93,7 @@ mkYesodSub "Auth" [ ClassP ''YesodAuth [VarT $ mkName "master"] ] #define STRINGS *Texts -#if GHC7 - [parseRoutes| -#else - [$parseRoutes| -#endif + [QQ(parseRoutes)| /check CheckR GET /login LoginR GET /logout LogoutR GET POST @@ -117,13 +115,7 @@ setCreds doRedirects creds = do case authRoute y of Nothing -> do rh <- defaultLayout -#if GHC7 - [hamlet| -#else - [$hamlet| -#endif -

Invalid login -|] + [QQ(hamlet)|

Invalid login |] sendResponse rh Just ar -> do setMessageI Msg.InvalidLogin @@ -145,11 +137,7 @@ getCheckR = do addHtml $ html creds) (json' creds) where html creds = -#if GHC7 - [hamlet| -#else - [$hamlet| -#endif + [QQ(hamlet)|

Authentication Status $maybe _ <- creds

Logged in. diff --git a/Yesod/Auth/Dummy.hs b/Yesod/Auth/Dummy.hs index d210f0d4..494268f1 100644 --- a/Yesod/Auth/Dummy.hs +++ b/Yesod/Auth/Dummy.hs @@ -8,6 +8,8 @@ module Yesod.Auth.Dummy ( authDummy ) where +#include "qq.h" + import Yesod.Auth import Yesod.Form (runInputPost, textField, ireq) import Yesod.Handler (notFound) @@ -23,11 +25,7 @@ authDummy = dispatch _ _ = notFound url = PluginR "dummy" [] login authToMaster = -#if GHC7 - [hamlet| -#else - [$hamlet| -#endif + [QQ(hamlet)|

\Your new identifier is: diff --git a/Yesod/Auth/Email.hs b/Yesod/Auth/Email.hs index 645201cc..797a0510 100644 --- a/Yesod/Auth/Email.hs +++ b/Yesod/Auth/Email.hs @@ -14,6 +14,8 @@ module Yesod.Auth.Email , setpassR ) where +#include "qq.h" + import Network.Mail.Mime (randomString) import Yesod.Auth import System.Random @@ -81,11 +83,7 @@ authEmail = AuthPlugin "email" dispatch $ \tm -> do y <- lift getYesod l <- lift languages -#if GHC7 - [whamlet| -#else - [$whamlet| -#endif + [QQ(whamlet)| @@ -119,11 +117,7 @@ getRegisterR = do defaultLayout $ do setTitleI Msg.RegisterLong addWidget -#if GHC7 - [whamlet| -#else - [$whamlet| -#endif + [QQ(whamlet)|

_{Msg.EnterEmail}

_{Msg.ConfirmationEmailSent email} -|] + [QQ(whamlet)|

_{Msg.ConfirmationEmailSent email} |] getVerifyR :: YesodAuthEmail m => AuthEmailId m -> Text -> GHandler Auth m RepHtml @@ -181,13 +169,7 @@ getVerifyR lid key = do defaultLayout $ do setTitleI Msg.InvalidKey addWidget -#if GHC7 - [whamlet| -#else - [$whamlet| -#endif -

_{Msg.InvalidKey} -|] + [QQ(whamlet)|

_{Msg.InvalidKey} |] postLoginR :: YesodAuthEmail master => GHandler Auth master () postLoginR = do @@ -226,11 +208,7 @@ getPasswordR = do defaultLayout $ do setTitleI Msg.SetPassTitle addWidget -#if GHC7 - [whamlet| -#else - [$whamlet| -#endif + [QQ(whamlet)|

_{Msg.SetPass}

diff --git a/Yesod/Auth/Facebook.hs b/Yesod/Auth/Facebook.hs index 29531057..f8715e63 100644 --- a/Yesod/Auth/Facebook.hs +++ b/Yesod/Auth/Facebook.hs @@ -6,6 +6,8 @@ module Yesod.Auth.Facebook , facebookUrl ) where +#include "qq.h" + import Yesod.Auth import qualified Web.Authenticate.Facebook as Facebook import Data.Aeson @@ -56,11 +58,7 @@ authFacebook cid secret perms = render <- lift getUrlRender let fb = Facebook.Facebook cid secret $ render $ tm url let furl = Facebook.getForwardUrl fb $ perms -#if GHC7 - [whamlet| -#else - [$whamlet| -#endif + [QQ(whamlet)|

_{Msg.Facebook} |] diff --git a/Yesod/Auth/HashDB.hs b/Yesod/Auth/HashDB.hs index 96cd1459..30837793 100644 --- a/Yesod/Auth/HashDB.hs +++ b/Yesod/Auth/HashDB.hs @@ -64,6 +64,8 @@ module Yesod.Auth.HashDB , migrateUsers ) where +#include "qq.h" + import Yesod.Persist import Yesod.Handler import Yesod.Form @@ -82,11 +84,7 @@ sha1String = showDigest . sha1 . pack -- | Generate data base instances for a valid user share2 mkPersist (mkMigrate "migrateUsers") -#if GHC7 - [persist| -#else - [$persist| -#endif + [QQ(persist)| User username Text Eq password Text @@ -128,13 +126,7 @@ postLoginR = do then setCreds True $ Creds "hashdb" (fromMaybe "" mu) [] else do setMessage -#if GHC7 - [hamlet| -#else - [$hamlet| -#endif - Invalid username/password -|] + [QQ(hamlet)| Invalid username/password |] toMaster <- getRouteToMaster redirect RedirectTemporary $ toMaster LoginR @@ -158,14 +150,7 @@ getAuthIdHashDB authR creds = do -- user exists Just (uid, _) -> return $ Just uid Nothing -> do - setMessage -#if GHC7 - [hamlet| -#else - [$hamlet| -#endif - User not found -|] + setMessage [QQ(hamlet)| User not found |] redirect RedirectTemporary $ authR LoginR -- | Prompt for username and password, validate that against a database @@ -175,11 +160,7 @@ authHashDB :: (YesodAuth y, PersistBackend (YesodDB y (GGHandler Auth y IO))) => AuthPlugin y authHashDB = AuthPlugin "hashdb" dispatch $ \tm -> -#if GHC7 - [hamlet| -#else - [$hamlet| -#endif + [QQ(hamlet)|