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