generateHaskellSource ∷ [CmdOpt] → FilePath → IO ()
generateHaskellSource opts srcFile
- = do modName ← getModuleName opts
- symName ← getSymbolName opts modName
- mimeType ← getMIMEType opts srcFile
- lastMod ← getLastModified srcFile
- input ← openInput srcFile
- output ← openOutput opts
- eTag ← getETag opts input
+ = do modName ← getModuleName opts
+ symName ← getSymbolName opts modName
+ mType ← getMIMEType opts srcFile
+ lastMod ← getLastModified srcFile
+ input ← openInput srcFile
+ output ← openOutput opts
+ tag ← getETag opts input
let compParams = defaultCompressParams { compressLevel = bestCompression }
gzippedData = compressWith compParams input
rawB64 = B64.encode <$> Lazy.toChunks input
gzippedB64 = B64.encode <$> Lazy.toChunks gzippedData
- header ← mkHeader srcFile originalLen gzippedLen useGZip mimeType eTag lastMod
+ header ← mkHeader srcFile originalLen gzippedLen useGZip mType tag lastMod
let hsModule = mkModule modName symName imports decls
imports = mkImports useGZip
decls = concat [ resourceDecl symName useGZip
- , entityTagDecl eTag
+ , entityTagDecl tag
, lastModifiedDecl lastMod
- , contentTypeDecl mimeType
+ , contentTypeDecl mType
, if useGZip then
dataDecl (name "gzippedData") gzippedB64
else
putChunksStmt = qualStmt ∘ putChunksExp
entityTagDecl ∷ ETag → [Decl]
-entityTagDecl eTag
+entityTagDecl tag
= [ TypeSig (⊥) [varName] (TyCon (UnQual (name "ETag")))
, nameBind (⊥) varName valExp
]
varName = name "entityTag"
valExp ∷ Exp
- valExp = function "parseETag" `app` strE (eTagToString eTag)
+ valExp = function "parseETag" `app` strE (eTagToString tag)
lastModifiedDecl ∷ UTCTime → [Decl]
lastModifiedDecl lastMod
strE (Strict.unpack chunk)
mkHeader ∷ FilePath → Int64 → Int64 → Bool → MIMEType → ETag → UTCTime → IO String
-mkHeader srcFile originalLen gzippedLen useGZip mimeType eTag lastMod
+mkHeader srcFile originalLen gzippedLen useGZip mType tag lastMod
= do localLastMod ← utcToLocalZonedTime lastMod
return $ concat
[ "{- DO NOT EDIT THIS FILE.\n"
" Compression: gzip\n"
else
" Compression: disabled\n"
- , " MIME Type: ", mimeTypeToString mimeType, "\n"
- , " ETag: ", eTagToString eTag, "\n"
+ , " MIME Type: ", mimeTypeToString mType, "\n"
+ , " ETag: ", eTagToString tag, "\n"
, " Last Modified: ", show localLastMod, "\n"
, " -}"
]