on 0050157 help sign in
elk/src/Server.hs
55 lines 1.6 kB history raw
2module Main where
4import Control.Monad (msum,guard)
5import Control.Monad.Trans (MonadIO(liftIO))
6import Data.List (isPrefixOf, isSuffixOf)
7import Happstack.Server
8import Happstack.Server.Compression
9import System.Environment
10import ToHtml
12serve :: String -> IO ()
13serve libLoc = do
14 putStrLn "Elm Server 0.1.0: running at <http://localhost:8000>"
15 simpleHTTP nullConf $ do
16 compressedResponseFilter
17 msum [ uriRest (serveElm libLoc)
18 , serveDirectory EnableBrowsing [] "."
19 ]
21serveElm libLoc fp = do
22 let ('/':path) = fp
23 guard (".elm" `isSuffixOf` path)
24 content <- liftIO (readFile path)
25 ok . toResponse $ compileToHtml libLoc path content
28main = getArgs >>= parse
30parse ("--help":_) = putStrLn usage
31parse ("--version":_) = putStrLn "The Elm Server 0.1.0"
32parse [] = serve "/elm-mini.js"
33parse [arg]
34 | "--runtime-location=" `isPrefixOf` arg =
35 serve . tail $ dropWhile (/='=') arg
36 | otherwise = putStrLn usageMini
37parse _ = putStrLn usageMini
39usageMini =
40 "Usage: elm-server [OPTIONS]\n\
41 \Try `elm-server --help' for more information."
43usage =
44 "Usage: elm-server [OPTIONS]\n\
45 \Compiles and serves .elm files from the current directory.\n\
46 \Example: elm-server\n\
47 \\n\
48 \Resource Locations:\n\
49 \ --runtime-location set the location of the Elm runtime (elm-mini.js)\n\
50 \\n\
51 \Compiler Information:\n\
52 \ --version print the version information and exit\n\
53 \ --help display this help and exit\n\
54 \\n\
55 \Elm home page: <http://elm-lang.org>"