2013-03-21 13:31:55 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
2013-03-17 05:24:18 +00:00
|
|
|
|
2013-03-21 09:29:23 +00:00
|
|
|
module LoadLibraries (docs) where
|
2013-03-17 05:24:18 +00:00
|
|
|
|
|
|
|
import Language.Haskell.TH.Syntax
|
|
|
|
import Paths_Elm
|
2013-03-21 09:29:23 +00:00
|
|
|
import System.Directory
|
2013-03-21 13:31:55 +00:00
|
|
|
import System.FilePath
|
2013-03-17 05:24:18 +00:00
|
|
|
|
|
|
|
docs :: Q Exp
|
2013-03-21 13:31:55 +00:00
|
|
|
docs = liftString =<< qRunIO (readDocs dataDir)
|
2013-03-17 05:24:18 +00:00
|
|
|
|
2013-03-21 13:31:55 +00:00
|
|
|
-- When compiling elm (library and executable), docs.json isn't (yet) in the standard location
|
|
|
|
-- Therefore, Elm.cabal overrides the location.
|
|
|
|
-- Since this is only used by the TemplateHaskell, which reads the file at compile time,
|
|
|
|
-- this should be ok.
|
|
|
|
|
|
|
|
dataDir :: IO FilePath
|
|
|
|
#if defined ELM_COMPILEDATADIR
|
|
|
|
dataDir = canonicalizePath (ELM_COMPILEDATADIR </> "docs.json")
|
|
|
|
#else
|
|
|
|
dataDir = getDataFileName "docs.json"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
readDocs :: IO FilePath -> IO String
|
|
|
|
readDocs path = do
|
|
|
|
name <- path
|
2013-03-21 09:29:23 +00:00
|
|
|
exists <- doesFileExist name
|
|
|
|
if exists then readFile name
|
|
|
|
else putStrLn warning >> return "{\"modules\":[]}"
|
|
|
|
|
|
|
|
warning = "Warning! Types for standard library not loaded properly!\n\
|
2013-03-21 13:31:55 +00:00
|
|
|
Run the following commands after compilation:\n\
|
|
|
|
\n\
|
|
|
|
touch compiler/Model/LoadLibraries.hs\n\
|
|
|
|
cabal install\n\n"
|