174 lines
		
	
	
	
		
			6.5 KiB
			
		
	
	
	
		
			Diff
		
	
	
	
	
	
			
		
		
	
	
			174 lines
		
	
	
	
		
			6.5 KiB
			
		
	
	
	
		
			Diff
		
	
	
	
	
	
From 476414b04064bb66fc25ba9ca426c309fe5c156e Mon Sep 17 00:00:00 2001
 | 
						|
From: Joey Hess <joey@kitenet.net>
 | 
						|
Date: Mon, 15 Apr 2013 12:48:13 -0400
 | 
						|
Subject: [PATCH] remove TH
 | 
						|
 | 
						|
---
 | 
						|
 Yesod/Static.hs           | 121 ----------------------------------------------
 | 
						|
 dist/package.conf.inplace |   3 +-
 | 
						|
 2 files changed, 2 insertions(+), 122 deletions(-)
 | 
						|
 | 
						|
diff --git a/Yesod/Static.hs b/Yesod/Static.hs
 | 
						|
index e8ca09f..193b1f0 100644
 | 
						|
--- a/Yesod/Static.hs
 | 
						|
+++ b/Yesod/Static.hs
 | 
						|
@@ -1,5 +1,3 @@
 | 
						|
-{-# LANGUAGE QuasiQuotes #-}
 | 
						|
-{-# LANGUAGE TemplateHaskell #-}
 | 
						|
 {-# LANGUAGE TypeFamilies #-}
 | 
						|
 {-# LANGUAGE CPP #-}
 | 
						|
 {-# LANGUAGE FlexibleInstances #-}
 | 
						|
@@ -34,11 +32,6 @@ module Yesod.Static
 | 
						|
       -- * Smart constructor
 | 
						|
     , static
 | 
						|
     , staticDevel
 | 
						|
-    , embed
 | 
						|
-      -- * Template Haskell helpers
 | 
						|
-    , staticFiles
 | 
						|
-    , staticFilesList
 | 
						|
-    , publicFiles
 | 
						|
       -- * Hashing
 | 
						|
     , base64md5
 | 
						|
 #ifdef TEST_EXPORT
 | 
						|
@@ -50,7 +43,6 @@ import Prelude hiding (FilePath)
 | 
						|
 import qualified Prelude
 | 
						|
 import System.Directory
 | 
						|
 import Control.Monad
 | 
						|
-import Data.FileEmbed (embedDir)
 | 
						|
 
 | 
						|
 import Yesod.Core hiding (lift)
 | 
						|
 
 | 
						|
@@ -111,18 +103,6 @@ staticDevel dir = do
 | 
						|
     hashLookup <- cachedETagLookupDevel dir
 | 
						|
     return $ Static $ webAppSettingsWithLookup (F.decodeString dir) hashLookup
 | 
						|
 
 | 
						|
--- | Produce a 'Static' based on embedding all of the static
 | 
						|
--- files' contents in the executable at compile time.
 | 
						|
--- Nota Bene: if you replace the scaffolded 'static' call in Settings/StaticFiles.hs
 | 
						|
--- you will need to change the scaffolded addStaticContent.  Otherwise, some of your
 | 
						|
--- assets will be 404'ed.  This is because by default yesod will generate compile those
 | 
						|
--- assets to @static/tmp@ which for 'static' is fine since they are served out of the 
 | 
						|
--- directory itself.  With embedded static, that will not work.  
 | 
						|
--- You can easily change @addStaticContent@ to @\_ _ _ -> return Nothing@ as a workaround.
 | 
						|
--- This will cause yesod to embed those assets into the generated HTML file itself.  
 | 
						|
-embed :: Prelude.FilePath -> Q Exp
 | 
						|
-embed fp = [|Static (embeddedSettings $(embedDir fp))|]
 | 
						|
-
 | 
						|
 instance RenderRoute Static where
 | 
						|
     -- | A route on the static subsite (see also 'staticFiles').
 | 
						|
     --
 | 
						|
@@ -167,59 +147,6 @@ getFileListPieces = flip go id
 | 
						|
         dirs' <- mapM (\f -> go (fullPath f) (front . (:) f)) dirs
 | 
						|
         return $ concat $ files' : dirs'
 | 
						|
 
 | 
						|
--- | Template Haskell function that automatically creates routes
 | 
						|
--- for all of your static files.
 | 
						|
---
 | 
						|
--- For example, if you used
 | 
						|
---
 | 
						|
--- > staticFiles "static/"
 | 
						|
---
 | 
						|
--- and you had files @\"static\/style.css\"@ and
 | 
						|
--- @\"static\/js\/script.js\"@, then the following top-level
 | 
						|
--- definitions would be created:
 | 
						|
---
 | 
						|
--- > style_css    = StaticRoute ["style.css"]    []
 | 
						|
--- > js_script_js = StaticRoute ["js/script.js"] []
 | 
						|
---
 | 
						|
--- Note that dots (@.@), dashes (@-@) and slashes (@\/@) are
 | 
						|
--- replaced by underscores (@\_@) to create valid Haskell
 | 
						|
--- identifiers.
 | 
						|
-staticFiles :: Prelude.FilePath -> Q [Dec]
 | 
						|
-staticFiles dir = mkStaticFiles dir
 | 
						|
-
 | 
						|
--- | Same as 'staticFiles', but takes an explicit list of files
 | 
						|
--- to create identifiers for. The files path given are relative
 | 
						|
--- to the static folder. For example, to create routes for the
 | 
						|
--- files @\"static\/js\/jquery.js\"@ and
 | 
						|
--- @\"static\/css\/normalize.css\"@, you would use:
 | 
						|
---
 | 
						|
--- > staticFilesList \"static\" [\"js\/jquery.js\", \"css\/normalize.css\"]
 | 
						|
---
 | 
						|
--- This can be useful when you have a very large number of static
 | 
						|
--- files, but only need to refer to a few of them from Haskell.
 | 
						|
-staticFilesList :: Prelude.FilePath -> [Prelude.FilePath] -> Q [Dec]
 | 
						|
-staticFilesList dir fs =
 | 
						|
-    mkStaticFilesList dir (map split fs) "StaticRoute" True
 | 
						|
-  where
 | 
						|
-    split :: Prelude.FilePath -> [String]
 | 
						|
-    split [] = []
 | 
						|
-    split x =
 | 
						|
-        let (a, b) = break (== '/') x
 | 
						|
-         in a : split (drop 1 b)
 | 
						|
-
 | 
						|
--- | Same as 'staticFiles', but doesn't append an ETag to the
 | 
						|
--- query string.
 | 
						|
---
 | 
						|
--- Using 'publicFiles' will speed up the compilation, since there
 | 
						|
--- won't be any need for hashing files during compile-time.
 | 
						|
--- However, since the ETag ceases to be part of the URL, the
 | 
						|
--- 'Static' subsite won't be able to set the expire date too far
 | 
						|
--- on the future.  Browsers still will be able to cache the
 | 
						|
--- contents, however they'll need send a request to the server to
 | 
						|
--- see if their copy is up-to-date.
 | 
						|
-publicFiles :: Prelude.FilePath -> Q [Dec]
 | 
						|
-publicFiles dir = mkStaticFiles' dir "StaticRoute" False
 | 
						|
-
 | 
						|
 
 | 
						|
 mkHashMap :: Prelude.FilePath -> IO (M.Map F.FilePath S8.ByteString)
 | 
						|
 mkHashMap dir = do
 | 
						|
@@ -262,54 +189,6 @@ cachedETagLookup dir = do
 | 
						|
     etags <- mkHashMap dir
 | 
						|
     return $ (\f -> return $ M.lookup f etags)
 | 
						|
 
 | 
						|
-mkStaticFiles :: Prelude.FilePath -> Q [Dec]
 | 
						|
-mkStaticFiles fp = mkStaticFiles' fp "StaticRoute" True
 | 
						|
-
 | 
						|
-mkStaticFiles' :: Prelude.FilePath -- ^ static directory
 | 
						|
-               -> String   -- ^ route constructor "StaticRoute"
 | 
						|
-               -> Bool     -- ^ append checksum query parameter
 | 
						|
-               -> Q [Dec]
 | 
						|
-mkStaticFiles' fp routeConName makeHash = do
 | 
						|
-    fs <- qRunIO $ getFileListPieces fp
 | 
						|
-    mkStaticFilesList fp fs routeConName makeHash
 | 
						|
-
 | 
						|
-mkStaticFilesList
 | 
						|
-    :: Prelude.FilePath -- ^ static directory
 | 
						|
-    -> [[String]] -- ^ list of files to create identifiers for
 | 
						|
-    -> String   -- ^ route constructor "StaticRoute"
 | 
						|
-    -> Bool     -- ^ append checksum query parameter
 | 
						|
-    -> Q [Dec]
 | 
						|
-mkStaticFilesList fp fs routeConName makeHash = do
 | 
						|
-    concat `fmap` mapM mkRoute fs
 | 
						|
-  where
 | 
						|
-    replace' c
 | 
						|
-        | 'A' <= c && c <= 'Z' = c
 | 
						|
-        | 'a' <= c && c <= 'z' = c
 | 
						|
-        | '0' <= c && c <= '9' = c
 | 
						|
-        | otherwise = '_'
 | 
						|
-    mkRoute f = do
 | 
						|
-        let name' = intercalate "_" $ map (map replace') f
 | 
						|
-            routeName = mkName $
 | 
						|
-                case () of
 | 
						|
-                    ()
 | 
						|
-                        | null name' -> error "null-named file"
 | 
						|
-                        | isDigit (head name') -> '_' : name'
 | 
						|
-                        | isLower (head name') -> name'
 | 
						|
-                        | otherwise -> '_' : name'
 | 
						|
-        f' <- [|map pack $(lift f)|]
 | 
						|
-        let route = mkName routeConName
 | 
						|
-        pack' <- [|pack|]
 | 
						|
-        qs <- if makeHash
 | 
						|
-                    then do hash <- qRunIO $ base64md5File $ pathFromRawPieces fp f
 | 
						|
-                            [|[(pack "etag", pack $(lift hash))]|]
 | 
						|
-                    else return $ ListE []
 | 
						|
-        return
 | 
						|
-            [ SigD routeName $ ConT route
 | 
						|
-            , FunD routeName
 | 
						|
-                [ Clause [] (NormalB $ (ConE route) `AppE` f' `AppE` qs) []
 | 
						|
-                ]
 | 
						|
-            ]
 | 
						|
-
 | 
						|
 base64md5File :: Prelude.FilePath -> IO String
 | 
						|
 base64md5File = fmap (base64 . encode) . hashFile
 | 
						|
     where encode d = Data.Serialize.encode (d :: MD5)
 |