Fixed staticFiles to prepend an underscore to the generated function name if the filename starts with a digit and to change the first character of a filename's function to lowercase if it is uppercase.

This commit is contained in:
Ian Duncan 2011-02-16 21:16:47 -06:00
parent bb0f91e2ba
commit a7f95db2a7

View File

@ -53,6 +53,7 @@ import Data.List (intercalate)
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
import Data.Char
import qualified Data.ByteString.Lazy as L
import Data.Digest.Pure.MD5
import qualified Data.ByteString.Base64
@ -155,7 +156,11 @@ staticFiles fp = do
| '0' <= c && c <= '9' = c
| otherwise = '_'
go f = do
let name = mkName $ intercalate "_" $ map (map replace') f
let adjust [] = ""
adjust str@(x:xs) | isDigit x = '_' : x : xs
| isUpper x = toLower x : xs
| otherwise = str
let name = mkName $ intercalate "_" $ map (adjust . map replace') f
f' <- lift f
let sr = ConE $ mkName "StaticRoute"
hash <- qRunIO $ fmap base64md5 $ L.readFile $ fp ++ '/' : intercalate "/" f