summaryrefslogtreecommitdiff
path: root/standalone/android/haskell-patches/yesod-core_1.1.8_0002-replaced-TH-in-Yesod.Internal.Core.patch
blob: af0b3d15b6468ca06c1d423a66388ab280a2cc8f (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
From 9ae3db0b3292b53715232fecec3c5e2bf03b89cd Mon Sep 17 00:00:00 2001
From: Joey Hess <joey@kitenet.net>
Date: Fri, 1 Mar 2013 01:02:53 -0400
Subject: [PATCH 2/2] replaced TH in Yesod.Internal.Core

Done by running a build with -ddump-splices and manually pasting in the
spliced code, and then modifying it until it compiles.

(This predated the Evil Splicer, and both this and the previous patch need
to be redone to use it.)
---
 Yesod/Internal/Core.hs |  211 +++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 201 insertions(+), 10 deletions(-)

diff --git a/Yesod/Internal/Core.hs b/Yesod/Internal/Core.hs
index 90c05fc..b9a0ae8 100644
--- a/Yesod/Internal/Core.hs
+++ b/Yesod/Internal/Core.hs
@@ -96,6 +96,9 @@ import System.Log.FastLogger (Logger, mkLogger, loggerDate, LogStr (..), loggerP
 import Control.Monad.Logger (LogLevel (LevelInfo, LevelOther), LogSource)
 import System.Log.FastLogger.Date (ZonedDate)
 import System.IO (stdout)
+import qualified Data.Foldable
+import qualified Text.Blaze.Internal
+import qualified Text.Hamlet
 
 yesodVersion :: String
 yesodVersion = showVersion Paths_yesod_core.version
@@ -164,7 +167,28 @@ class RenderRoute a => Yesod a where
 
     -- | Applies some form of layout to the contents of a page.
     defaultLayout :: GWidget sub a () -> GHandler sub a RepHtml
-    defaultLayout w = error "defaultLayout not implemented"
+    defaultLayout w = do
+        p <- widgetToPageContent w
+        mmsg <- getMessage
+        hamletToRepHtml $ \ _render_ay88 -> do { id
+                ((Text.Blaze.Internal.preEscapedText . T.pack)
+                   "<!DOCTYPE html>\n<html><head><title>");
+              id (TBH.toHtml (pageTitle p));
+              id ((Text.Blaze.Internal.preEscapedText . T.pack) "</title>");
+              id (pageHead p) _render_ay88;
+              id ((Text.Blaze.Internal.preEscapedText . T.pack) "</head><body>");
+              Text.Hamlet.maybeH
+                mmsg
+                (\ msg_ay89
+                   -> do { id
+                             ((Text.Blaze.Internal.preEscapedText . T.pack)
+                                "<p class=\"message\">");
+                           id (TBH.toHtml msg_ay89);
+                           id ((Text.Blaze.Internal.preEscapedText . T.pack) "</p>") })
+                Nothing;
+              id (pageBody p) _render_ay88;
+              id
+                ((Text.Blaze.Internal.preEscapedText . T.pack) "</body></html>") }
 
     -- | Override the rendering function for a particular URL. One use case for
     -- this is to offload static hosting to a different domain name to avoid
@@ -505,11 +529,45 @@ applyLayout' title body = fmap chooseRep $ defaultLayout $ do
 
 -- | The default error handler for 'errorHandler'.
 defaultErrorHandler :: Yesod y => ErrorResponse -> GHandler sub y ChooseRep
-defaultErrorHandler NotFound = error "Not Found"
-defaultErrorHandler (PermissionDenied msg) = error "Permission Denied"
-defaultErrorHandler (InvalidArgs ia) = error "Invalid Arguments"
-defaultErrorHandler (InternalError e) = error "Internal Server Error"
-defaultErrorHandler (BadMethod m) = error "Bad Method"
+defaultErrorHandler NotFound = do
+    r <- waiRequest
+    let path' = TE.decodeUtf8With TEE.lenientDecode $ W.rawPathInfo r
+    applyLayout' "Not Found" $ \ _render_ayac -> do { id
+                ((Text.Blaze.Internal.preEscapedText . T.pack)
+                   "<h1>Not Found</h1><p>");
+              id (TBH.toHtml path');
+              id ((Text.Blaze.Internal.preEscapedText . T.pack) "</p>") }
+defaultErrorHandler (PermissionDenied msg) =
+    applyLayout' "Permission Denied" $  \ _render_ayah -> do { id
+                ((Text.Blaze.Internal.preEscapedText . T.pack)
+                   "<h1>Permission denied</h1><p>");
+              id (TBH.toHtml msg);
+              id ((Text.Blaze.Internal.preEscapedText . T.pack) "</p>") }
+defaultErrorHandler (InvalidArgs ia) =
+    applyLayout' "Invalid Arguments" $  \ _render_ayam -> do { id
+                ((Text.Blaze.Internal.preEscapedText . T.pack)
+                   "<h1>Invalid Arguments</h1><ul>");
+              Data.Foldable.mapM_
+                (\ msg_ayan
+                   -> do { id ((Text.Blaze.Internal.preEscapedText . T.pack) "<li>");
+                           id (TBH.toHtml msg_ayan);
+                           id ((Text.Blaze.Internal.preEscapedText . T.pack) "</li>") })
+                ia;
+              id ((Text.Blaze.Internal.preEscapedText . T.pack) "</ul>") }
+defaultErrorHandler (InternalError e) = do
+    applyLayout' "Internal Server Error" $  \ _render_ayau -> do { id
+                ((Text.Blaze.Internal.preEscapedText . T.pack)
+                   "<h1>Internal Server Error</h1><pre>");
+              id (TBH.toHtml e);
+              id ((Text.Blaze.Internal.preEscapedText . T.pack) "</pre>") }
+defaultErrorHandler (BadMethod m) =
+    applyLayout' "Bad Method" $ \ _render_ayaz -> do { id
+                ((Text.Blaze.Internal.preEscapedText . T.pack)
+                   "<h1>Method Not Supported</h1><p>Method <code>");
+              id (TBH.toHtml (S8.unpack m));
+              id
+                ((Text.Blaze.Internal.preEscapedText . T.pack)
+                   "</code> not supported</p>") }
 
 -- | Return the same URL if the user is authorized to see it.
 --
@@ -565,10 +623,99 @@ widgetToPageContent w = do
     -- modernizr should be at the end of the <head> http://www.modernizr.com/docs/#installing
     -- the asynchronous loader means your page doesn't have to wait for all the js to load
     let (mcomplete, asyncScripts) = asyncHelper render scripts jscript jsLoc
-        regularScriptLoad = error "TODO"
-
-        headAll = error "TODO"
-    let bodyScript = error "TODO"
+        regularScriptLoad =  \ _render_aybs -> do { Data.Foldable.mapM_
+                (\ s_aybt
+                   -> id (mkScriptTag s_aybt) _render_aybs)
+                scripts;
+              Text.Hamlet.maybeH
+                jscript
+                (\ j_aybu
+                   -> Text.Hamlet.maybeH
+                        jsLoc
+                        (\ s_aybv
+                           -> do { id
+                                     ((Text.Blaze.Internal.preEscapedText . T.pack)
+                                        "<script src=\"");
+                                   id (TBH.toHtml s_aybv);
+                                   id
+                                     ((Text.Blaze.Internal.preEscapedText . T.pack)
+                                        "\"></script>") })
+                        (Just
+                           (do { id
+                                   ((Text.Blaze.Internal.preEscapedText . T.pack) "<script>");
+                                 id (jelper j_aybu) _render_aybs;
+                                 id ((Text.Blaze.Internal.preEscapedText . T.pack) "</script>") })))
+                Nothing }
+
+        headAll = \ _render_aybz  -> do
+            { id head' _render_aybz;
+              Data.Foldable.mapM_
+                (\ s_aybA -> id (mkLinkTag s_aybA) _render_aybz)
+                stylesheets;
+              Data.Foldable.mapM_
+                (\ s_aybB
+                   -> do { Text.Hamlet.maybeH
+                             (right (snd s_aybB))
+                             (\ t_aybC
+                                -> Text.Hamlet.maybeH
+                                     (fst s_aybB)
+                                     (\ media_aybD
+                                        -> do { id
+                                                  ((Text.Blaze.Internal.preEscapedText . T.pack)
+                                                     "<link rel=\"stylesheet\" media=\"");
+                                                id (TBH.toHtml media_aybD);
+                                                id
+                                                  ((Text.Blaze.Internal.preEscapedText . T.pack)
+                                                     "\" href=\"");
+                                                id (TBH.toHtml t_aybC);
+                                                id
+                                                  ((Text.Blaze.Internal.preEscapedText . T.pack)
+                                                     "\">") })
+                                     (Just
+                                        (do { id
+                                                ((Text.Blaze.Internal.preEscapedText . T.pack)
+                                                   "<link rel=\"stylesheet\" href=\"");
+                                              id (TBH.toHtml t_aybC);
+                                              id
+                                                ((Text.Blaze.Internal.preEscapedText . T.pack)
+                                                   "\">") })))
+                             Nothing;
+                           Text.Hamlet.maybeH
+                             (left (snd s_aybB))
+                             (\ content_aybE
+                                -> Text.Hamlet.maybeH
+                                     (fst s_aybB)
+                                     (\ media_aybF
+                                        -> do { id
+                                                  ((Text.Blaze.Internal.preEscapedText . T.pack)
+                                                     "<style media=\"");
+                                                id (TBH.toHtml media_aybF);
+                                                id
+                                                  ((Text.Blaze.Internal.preEscapedText . T.pack)
+                                                     "\">");
+                                                id (TBH.toHtml content_aybE);
+                                                id
+                                                  ((Text.Blaze.Internal.preEscapedText . T.pack)
+                                                     "</style>") })
+                                     (Just
+                                        (do { id
+                                                ((Text.Blaze.Internal.preEscapedText . T.pack)
+                                                   "<style>");
+                                              id (TBH.toHtml content_aybE);
+                                              id
+                                                ((Text.Blaze.Internal.preEscapedText . T.pack)
+                                                   "</style>") })))
+                             Nothing })
+                css;
+              case jsLoader master of
+                BottomOfBody -> return ()
+                BottomOfHeadAsync asyncJsLoader -> id (asyncJsLoader asyncScripts mcomplete) _render_aybz
+                BottomOfHeadBlocking -> id regularScriptLoad _render_aybz
+            }
+
+    let bodyScript = \ _render_aybL -> do {
+              id body _render_aybL;
+              id regularScriptLoad _render_aybL }
 
     return $ PageContent title headAll (case jsLoader master of
       BottomOfBody -> bodyScript
@@ -611,6 +758,50 @@ jsonArray = unsafeLazyByteString . encode . Array . Vector.fromList . map String
 -- | For use with setting 'jsLoader' to 'BottomOfHeadAsync'
 loadJsYepnope :: Yesod master => Either Text (Route master) -> [Text] -> Maybe (HtmlUrl (Route master)) -> (HtmlUrl (Route master))
 loadJsYepnope eyn scripts mcomplete = error "TODO"
+{-
+    \ _render_aybU
+      -> do { Text.Hamlet.maybeH
+                (left eyn)
+                (\ yn_aybV
+                   -> do { id
+                             ((Text.Blaze.Internal.preEscapedText . T.pack) "<script src=\"");
+                           id (TBH.toHtml yn_aybV);
+                           id
+                             ((Text.Blaze.Internal.preEscapedText . T.pack) "\"></script>") })
+                Nothing;
+              Text.Hamlet.maybeH
+                (right eyn)
+                (\ yn_aybW
+                   -> do { id
+                             ((Text.Blaze.Internal.preEscapedText . T.pack) "<script src=\"");
+                           id
+                             (TBH.toHtml
+                                (\ u_aybX -> _render_aybU u_aybX [] yn_aybW));
+                           id
+                             ((Text.Blaze.Internal.preEscapedText . T.pack) "\"></script>") })
+                Nothing;
+              Text.Hamlet.maybeH
+                mcomplete
+                (\ complete_aybY
+                   -> do { id
+                             ((Text.Blaze.Internal.preEscapedText . T.pack)
+                                "<script>yepnope({load:");
+                           id (TBH.toHtml (jsonArray scripts));
+                           id
+                             ((Text.Blaze.Internal.preEscapedText . T.pack)
+                                ",complete:function(){");
+                           id complete_aybY _render_aybU;
+                           id
+                             ((Text.Blaze.Internal.preEscapedText . T.pack) "}});</script>") })
+                (Just
+                   (do { id
+                           ((Text.Blaze.Internal.preEscapedText . T.pack)
+                              "<script>yepnope({load:");
+                         id (TBH.toHtml (jsonArray scripts));
+                         id
+                           ((Text.Blaze.Internal.preEscapedText . T.pack)
+                              "});</script>") })) }
+-}
 
 asyncHelper :: (url -> [x] -> Text)
          -> [Script (url)]
-- 
1.7.10.4