summaryrefslogtreecommitdiff
path: root/standalone/android/haskell-patches/hamlet_1.1.6.1_0001-remove-TH.patch
blob: 1c511a132101b5115a3deac474b8e59b5f8bd3d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
From b2c677ed39f1aca3a1111691ba51b26f7fd414a4 Mon Sep 17 00:00:00 2001
From: Joey Hess <joey@kitenet.net>
Date: Wed, 8 May 2013 01:50:58 -0400
Subject: [PATCH] remove TH

---
 Text/Hamlet.hs |  219 ++------------------------------------------------------
 hamlet.cabal   |    2 +-
 2 files changed, 7 insertions(+), 214 deletions(-)

diff --git a/Text/Hamlet.hs b/Text/Hamlet.hs
index 4ac870a..63b8555 100644
--- a/Text/Hamlet.hs
+++ b/Text/Hamlet.hs
@@ -11,35 +11,26 @@
 module Text.Hamlet
     ( -- * Plain HTML
       Html
-    , shamlet
-    , shamletFile
-    , xshamlet
-    , xshamletFile
       -- * Hamlet
     , HtmlUrl
-    , hamlet
-    , hamletFile
-    , xhamlet
-    , xhamletFile
       -- * I18N Hamlet
     , HtmlUrlI18n
-    , ihamlet
-    , ihamletFile
       -- * Type classes
     , ToAttributes (..)
       -- * Internal, for making more
     , HamletSettings (..)
     , NewlineStyle (..)
-    , hamletWithSettings
-    , hamletFileWithSettings
     , defaultHamletSettings
     , xhtmlHamletSettings
     , Env (..)
     , HamletRules (..)
-    , hamletRules
-    , ihamletRules
-    , htmlRules
     , CloseStyle (..)
+    , condH
+    , maybeH
+
+    -- referred to in TH splices
+    , attrsToHtml
+    , asHtmlUrl
     ) where
 
 import Text.Shakespeare.Base
@@ -90,14 +81,6 @@ type HtmlUrl url = Render url -> Html
 -- | A function generating an 'Html' given a message translator and a URL rendering function.
 type HtmlUrlI18n msg url = Translate msg -> Render url -> Html
 
-docsToExp :: Env -> HamletRules -> Scope -> [Doc] -> Q Exp
-docsToExp env hr scope docs = do
-    exps <- mapM (docToExp env hr scope) docs
-    case exps of
-        [] -> [|return ()|]
-        [x] -> return x
-        _ -> return $ DoE $ map NoBindS exps
-
 unIdent :: Ident -> String
 unIdent (Ident s) = s
 
@@ -159,169 +142,9 @@ recordToFieldNames conStr = do
   [fields] <- return [fields | RecC name fields <- cons, name == conName]
   return [fieldName | (fieldName, _, _) <- fields]
 
-docToExp :: Env -> HamletRules -> Scope -> Doc -> Q Exp
-docToExp env hr scope (DocForall list idents inside) = do
-    let list' = derefToExp scope list
-    (pat, extraScope) <- bindingPattern idents
-    let scope' = extraScope ++ scope
-    mh <- [|F.mapM_|]
-    inside' <- docsToExp env hr scope' inside
-    let lam = LamE [pat] inside'
-    return $ mh `AppE` lam `AppE` list'
-docToExp env hr scope (DocWith [] inside) = do
-    inside' <- docsToExp env hr scope inside
-    return $ inside'
-docToExp env hr scope (DocWith ((deref, idents):dis) inside) = do
-    let deref' = derefToExp scope deref
-    (pat, extraScope) <- bindingPattern idents
-    let scope' = extraScope ++ scope
-    inside' <- docToExp env hr scope' (DocWith dis inside)
-    let lam = LamE [pat] inside'
-    return $ lam `AppE` deref'
-docToExp env hr scope (DocMaybe val idents inside mno) = do
-    let val' = derefToExp scope val
-    (pat, extraScope) <- bindingPattern idents
-    let scope' = extraScope ++ scope
-    inside' <- docsToExp env hr scope' inside
-    let inside'' = LamE [pat] inside'
-    ninside' <- case mno of
-                    Nothing -> [|Nothing|]
-                    Just no -> do
-                        no' <- docsToExp env hr scope no
-                        j <- [|Just|]
-                        return $ j `AppE` no'
-    mh <- [|maybeH|]
-    return $ mh `AppE` val' `AppE` inside'' `AppE` ninside'
-docToExp env hr scope (DocCond conds final) = do
-    conds' <- mapM go conds
-    final' <- case final of
-                Nothing -> [|Nothing|]
-                Just f -> do
-                    f' <- docsToExp env hr scope f
-                    j <- [|Just|]
-                    return $ j `AppE` f'
-    ch <- [|condH|]
-    return $ ch `AppE` ListE conds' `AppE` final'
-  where
-    go :: (Deref, [Doc]) -> Q Exp
-    go (d, docs) = do
-        let d' = derefToExp scope d
-        docs' <- docsToExp env hr scope docs
-        return $ TupE [d', docs']
-docToExp env hr scope (DocCase deref cases) = do
-    let exp_ = derefToExp scope deref
-    matches <- mapM toMatch cases
-    return $ CaseE exp_ matches
-  where
-    readMay s =
-        case reads s of
-            (x, ""):_ -> Just x
-            _ -> Nothing
-    toMatch (idents, inside) = do
-        let pat = case map unIdent idents of
-                    ["_"] -> WildP
-                    [str]
-                        | Just i <- readMay str -> LitP $ IntegerL i
-                    strs -> let (constr:fields) = map mkName strs
-                            in ConP constr (map VarP fields)
-        insideExp <- docsToExp env hr scope inside
-        return $ Match pat (NormalB insideExp) []
-docToExp env hr v (DocContent c) = contentToExp env hr v c
-
-contentToExp :: Env -> HamletRules -> Scope -> Content -> Q Exp
-contentToExp _ hr _ (ContentRaw s) = do
-    os <- [|preEscapedText . pack|]
-    let s' = LitE $ StringL s
-    return $ hrFromHtml hr `AppE` (os `AppE` s')
-contentToExp _ hr scope (ContentVar d) = do
-    str <- [|toHtml|]
-    return $ hrFromHtml hr `AppE` (str `AppE` derefToExp scope d)
-contentToExp env hr scope (ContentUrl hasParams d) =
-    case urlRender env of
-        Nothing -> error "URL interpolation used, but no URL renderer provided"
-        Just wrender -> wrender $ \render -> do
-            let render' = return render
-            ou <- if hasParams
-                    then [|\(u, p) -> $(render') u p|]
-                    else [|\u -> $(render') u []|]
-            let d' = derefToExp scope d
-            pet <- [|toHtml|]
-            return $ hrFromHtml hr `AppE` (pet `AppE` (ou `AppE` d'))
-contentToExp env hr scope (ContentEmbed d) = hrEmbed hr env $ derefToExp scope d
-contentToExp env hr scope (ContentMsg d) =
-    case msgRender env of
-        Nothing -> error "Message interpolation used, but no message renderer provided"
-        Just wrender -> wrender $ \render ->
-            return $ hrFromHtml hr `AppE` (render `AppE` derefToExp scope d)
-contentToExp _ hr scope (ContentAttrs d) = do
-    html <- [|attrsToHtml . toAttributes|]
-    return $ hrFromHtml hr `AppE` (html `AppE` derefToExp scope d)
-
-shamlet :: QuasiQuoter
-shamlet = hamletWithSettings htmlRules defaultHamletSettings
-
-xshamlet :: QuasiQuoter
-xshamlet = hamletWithSettings htmlRules xhtmlHamletSettings
-
-htmlRules :: Q HamletRules
-htmlRules = do
-    i <- [|id|]
-    return $ HamletRules i ($ (Env Nothing Nothing)) (\_ b -> return b)
-
-hamlet :: QuasiQuoter
-hamlet = hamletWithSettings hamletRules defaultHamletSettings
-
-xhamlet :: QuasiQuoter
-xhamlet = hamletWithSettings hamletRules xhtmlHamletSettings
-
 asHtmlUrl :: HtmlUrl url -> HtmlUrl url
 asHtmlUrl = id
 
-hamletRules :: Q HamletRules
-hamletRules = do
-    i <- [|id|]
-    let ur f = do
-            r <- newName "_render"
-            let env = Env
-                    { urlRender = Just ($ (VarE r))
-                    , msgRender = Nothing
-                    }
-            h <- f env
-            return $ LamE [VarP r] h
-    return $ HamletRules i ur em
-  where
-    em (Env (Just urender) Nothing) e = do
-        asHtmlUrl' <- [|asHtmlUrl|]
-        urender $ \ur' -> return ((asHtmlUrl' `AppE` e) `AppE` ur')
-    em _ _ = error "bad Env"
-
-ihamlet :: QuasiQuoter
-ihamlet = hamletWithSettings ihamletRules defaultHamletSettings
-
-ihamletRules :: Q HamletRules
-ihamletRules = do
-    i <- [|id|]
-    let ur f = do
-            u <- newName "_urender"
-            m <- newName "_mrender"
-            let env = Env
-                    { urlRender = Just ($ (VarE u))
-                    , msgRender = Just ($ (VarE m))
-                    }
-            h <- f env
-            return $ LamE [VarP m, VarP u] h
-    return $ HamletRules i ur em
-  where
-    em (Env (Just urender) (Just mrender)) e =
-          urender $ \ur' -> mrender $ \mr -> return (e `AppE` mr `AppE` ur')
-    em _ _ = error "bad Env"
-
-hamletWithSettings :: Q HamletRules -> HamletSettings -> QuasiQuoter
-hamletWithSettings hr set =
-    QuasiQuoter
-        { quoteExp = hamletFromString hr set
-        }
-
 data HamletRules = HamletRules
     { hrFromHtml :: Exp
     , hrWithEnv :: (Env -> Q Exp) -> Q Exp
@@ -333,36 +156,6 @@ data Env = Env
     , msgRender :: Maybe ((Exp -> Q Exp) -> Q Exp)
     }
 
-hamletFromString :: Q HamletRules -> HamletSettings -> String -> Q Exp
-hamletFromString qhr set s = do
-    hr <- qhr
-    case parseDoc set s of
-        Error s' -> error s'
-        Ok (_mnl, d) -> hrWithEnv hr $ \env -> docsToExp env hr [] d
-
-hamletFileWithSettings :: Q HamletRules -> HamletSettings -> FilePath -> Q Exp
-hamletFileWithSettings qhr set fp = do
-#ifdef GHC_7_4
-    qAddDependentFile fp
-#endif
-    contents <- fmap TL.unpack $ qRunIO $ readUtf8File fp
-    hamletFromString qhr set contents
-
-hamletFile :: FilePath -> Q Exp
-hamletFile = hamletFileWithSettings hamletRules defaultHamletSettings
-
-xhamletFile :: FilePath -> Q Exp
-xhamletFile = hamletFileWithSettings hamletRules xhtmlHamletSettings
-
-shamletFile :: FilePath -> Q Exp
-shamletFile = hamletFileWithSettings htmlRules defaultHamletSettings
-
-xshamletFile :: FilePath -> Q Exp
-xshamletFile = hamletFileWithSettings htmlRules xhtmlHamletSettings
-
-ihamletFile :: FilePath -> Q Exp
-ihamletFile = hamletFileWithSettings ihamletRules defaultHamletSettings
-
 varName :: Scope -> String -> Exp
 varName _ "" = error "Illegal empty varName"
 varName scope v@(_:_) = fromMaybe (strToExp v) $ lookup (Ident v) scope
diff --git a/hamlet.cabal b/hamlet.cabal
index 73fa6a8..4348508 100644
--- a/hamlet.cabal
+++ b/hamlet.cabal
@@ -50,7 +50,7 @@ library
                    , text             >= 0.7     && < 0.12
                    , containers       >= 0.2
                    , blaze-builder    >= 0.2     && < 0.4
-                   , process          >= 1.0     && < 1.2
+                   , process          >= 1.0     && < 1.3
                    , blaze-html       >= 0.5     && < 0.6
                    , blaze-markup     >= 0.5.1   && < 0.6
 
-- 
1.7.10.4