on 29153a8 help sign in
elk/compiler/Model/LoadLibraries.hs
36 lines 1.1 kB history raw
1{-# LANGUAGE CPP #-}
3module LoadLibraries (docs) where
5import Language.Haskell.TH.Syntax
6import Paths_Elm
7import System.Directory
8import System.FilePath
10docs :: Q Exp
11docs = liftString =<< qRunIO (readDocs dataDir)
13-- When compiling elm (library and executable), docs.json isn't (yet) in the standard location
14-- Therefore, Elm.cabal overrides the location.
15-- Since this is only used by the TemplateHaskell, which reads the file at compile time,
16-- this should be ok.
18dataDir :: IO FilePath
19#if defined ELM_COMPILEDATADIR
20dataDir = canonicalizePath (ELM_COMPILEDATADIR </> "docs.json")
21#else
22dataDir = getDataFileName "docs.json"
23#endif
25readDocs :: IO FilePath -> IO String
26readDocs path = do
27 name <- path
28 exists <- doesFileExist name
29 if exists then readFile name
30 else putStrLn warning >> return "{\"modules\":[]}"
32warning = "Warning! Types for standard library not loaded properly!\n\
33 Run the following commands after compilation:\n\
34 \n\
35 touch compiler/Model/LoadLibraries.hs\n\
36 cabal install\n\n"