on 8f7c3cd help sign in
elk/cli/src/Develop/StaticFiles.hs
127 lines 1.9 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE TemplateHaskell #-}
3module Develop.StaticFiles
4 ( lookup
5 , cssPath
6 , elmPath
7 , waitingPath
8 )
9 where
11import Prelude hiding (lookup)
12import qualified Data.ByteString as BS
13import Data.FileEmbed (bsToExp)
14import qualified Data.HashMap.Strict as HM
15import Language.Haskell.TH (runIO)
17import qualified Develop.StaticFiles.Build as Build
21-- FILE LOOKUP
24type MimeType =
25 String
28lookup :: FilePath -> Maybe (BS.ByteString, MimeType)
29lookup path =
30 HM.lookup path dict
33dict :: HM.HashMap FilePath (BS.ByteString, MimeType)
34dict =
35 HM.fromList
36 [ faviconPath ==> (favicon , "image/x-icon")
37 , waitingPath ==> (waiting , "image/gif")
38 , elmPath ==> (elm , "application/javascript")
39 , cssPath ==> (css , "text/css")
40 , codeFontPath ==> (codeFont, "font/ttf")
41 , sansFontPath ==> (sansFont, "font/ttf")
42 ]
45(==>) :: a -> b -> (a,b)
46(==>) a b =
47 (a, b)
51-- PATHS
54faviconPath :: FilePath
55faviconPath =
56 "favicon.ico"
59waitingPath :: FilePath
60waitingPath =
61 "_elm/waiting.gif"
64elmPath :: FilePath
65elmPath =
66 "_elm/elm.js"
69cssPath :: FilePath
70cssPath =
71 "_elm/styles.css"
74codeFontPath :: FilePath
75codeFontPath =
76 "_elm/source-code-pro.ttf"
79sansFontPath :: FilePath
80sansFontPath =
81 "_elm/source-sans-pro.ttf"
85-- ELM
88elm :: BS.ByteString
89elm =
90 $(bsToExp =<< runIO Build.compile)
94-- CSS
97css :: BS.ByteString
98css =
99 $(bsToExp =<< runIO (Build.readAsset "styles.css"))
103-- FONTS
106codeFont :: BS.ByteString
107codeFont =
108 $(bsToExp =<< runIO (Build.readAsset "source-code-pro.ttf"))
111sansFont :: BS.ByteString
112sansFont =
113 $(bsToExp =<< runIO (Build.readAsset "source-sans-pro.ttf"))
117-- IMAGES
120favicon :: BS.ByteString
121favicon =
122 $(bsToExp =<< runIO (Build.readAsset "favicon.ico"))
125waiting :: BS.ByteString
126waiting =
127 $(bsToExp =<< runIO (Build.readAsset "waiting.gif"))