on efe80bc help sign in
elk/terminal/src/Develop/StaticFiles.hs
129 lines 2.0 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE TemplateHaskell #-}
4module Develop.StaticFiles
5 ( lookup
6 , cssPath
7 , elmPath
8 , waitingPath
9 )
10 where
12import Prelude hiding (lookup)
13import qualified Data.ByteString as BS
14import Data.FileEmbed (bsToExp)
15import qualified Data.HashMap.Strict as HM
16import Language.Haskell.TH (runIO)
17import System.FilePath ((</>))
19import qualified Develop.StaticFiles.Build as Build
23-- FILE LOOKUP
26type MimeType =
27 BS.ByteString
30lookup :: FilePath -> Maybe (BS.ByteString, MimeType)
31lookup path =
32 HM.lookup path dict
35dict :: HM.HashMap FilePath (BS.ByteString, MimeType)
36dict =
37 HM.fromList
38 [ faviconPath ==> (favicon , "image/x-icon")
39 , waitingPath ==> (waiting , "image/gif")
40 , elmPath ==> (elm , "application/javascript")
41 , cssPath ==> (css , "text/css")
42 , codeFontPath ==> (codeFont, "font/ttf")
43 , sansFontPath ==> (sansFont, "font/ttf")
44 ]
47(==>) :: a -> b -> (a,b)
48(==>) a b =
49 (a, b)
53-- PATHS
56faviconPath :: FilePath
57faviconPath =
58 "favicon.ico"
61waitingPath :: FilePath
62waitingPath =
63 "_elm" </> "waiting.gif"
66elmPath :: FilePath
67elmPath =
68 "_elm" </> "elm.js"
71cssPath :: FilePath
72cssPath =
73 "_elm" </> "styles.css"
76codeFontPath :: FilePath
77codeFontPath =
78 "_elm" </> "source-code-pro.ttf"
81sansFontPath :: FilePath
82sansFontPath =
83 "_elm" </> "source-sans-pro.ttf"
87-- ELM
90elm :: BS.ByteString
91elm =
92 $(bsToExp =<< runIO Build.compile)
96-- CSS
99css :: BS.ByteString
100css =
101 $(bsToExp =<< runIO (Build.readAsset "styles.css"))
105-- FONTS
108codeFont :: BS.ByteString
109codeFont =
110 $(bsToExp =<< runIO (Build.readAsset "source-code-pro.ttf"))
113sansFont :: BS.ByteString
114sansFont =
115 $(bsToExp =<< runIO (Build.readAsset "source-sans-pro.ttf"))
119-- IMAGES
122favicon :: BS.ByteString
123favicon =
124 $(bsToExp =<< runIO (Build.readAsset "favicon.ico"))
127waiting :: BS.ByteString
128waiting =
129 $(bsToExp =<< runIO (Build.readAsset "waiting.gif"))