on ebbecaf help sign in
elk/terminal/src/Develop/StaticFiles.hs
123 lines 1.9 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 , elmPath ==> (elm , "application/javascript")
40 , cssPath ==> (css , "text/css")
41 , codeFontPath ==> (codeFont, "font/ttf")
42 , sansFontPath ==> (sansFont, "font/ttf")
43 ]
46(==>) :: a -> b -> (a,b)
47(==>) a b =
48 (a, b)
52-- PATHS
55faviconPath :: FilePath
56faviconPath =
57 "favicon.ico"
60waitingPath :: FilePath
61waitingPath =
62 "_elm" </> "waiting.gif"
65elmPath :: FilePath
66elmPath =
67 "_elm" </> "elm.js"
70cssPath :: FilePath
71cssPath =
72 "_elm" </> "styles.css"
75codeFontPath :: FilePath
76codeFontPath =
77 "_elm" </> "source-code-pro.ttf"
80sansFontPath :: FilePath
81sansFontPath =
82 "_elm" </> "source-sans-pro.ttf"
86-- ELM
89elm :: BS.ByteString
90elm =
91 $(bsToExp =<< runIO Build.buildReactorFrontEnd)
95-- CSS
98css :: BS.ByteString
99css =
100 $(bsToExp =<< runIO (Build.readAsset "styles.css"))
104-- FONTS
107codeFont :: BS.ByteString
108codeFont =
109 $(bsToExp =<< runIO (Build.readAsset "source-code-pro.ttf"))
112sansFont :: BS.ByteString
113sansFont =
114 $(bsToExp =<< runIO (Build.readAsset "source-sans-pro.ttf"))
118-- IMAGES
121favicon :: BS.ByteString
122favicon =
123 $(bsToExp =<< runIO (Build.readAsset "favicon.ico"))