4import Control.Monad (msum,guard)
5import Control.Monad.Trans (MonadIO(liftIO))
6import Data.List (isPrefixOf, isSuffixOf)
7import Data.Version (showVersion)
9import Happstack.Server.Compression
10import System.Environment
12import qualified Language.Elm as Elm
13import Paths_elm_server
15runtime = "/elm-" ++ showVersion version ++ ".js"
17serve :: String -> IO ()
19 putStrLn ("Elm Server " ++ showVersion version ++
20 ": running at <http://localhost:8000>")
21 putStrLn "Just refresh a page to recompile it!"
22 simpleHTTP nullConf $ do
23 _ <- compressedResponseFilter
24 msum [ uriRest serveElm
25 , uriRest (serveLib libLoc)
26 , serveDirectory EnableBrowsing [] "."
29pageTitle :: String -> String
30pageTitle = dropExtension . takeBaseName
33 guard (takeExtension fp == ".elm")
34 content <- liftIO (readFile (tail fp))
35 ok . toResponse $ Elm.toHtml runtime (pageTitle fp) content
37serveLib libLoc fp = do
39 serveFile (asContentType "application/javascript") libLoc
42main = getArgs >>= parse
44parse :: [String] -> IO ()
45parse ("--help":_) = putStrLn usage
46parse ("--version":_) = putStrLn ("The Elm Server " ++ showVersion version)
47parse [] = serve =<< Elm.runtime
49 | "--runtime-location=" `isPrefixOf` arg =
50 serve . tail $ dropWhile (/='=') arg
51 | otherwise = putStrLn usageMini
52parse _ = putStrLn usageMini
56 "Usage: elm-server [OPTIONS]\n\
57 \Try `elm-server --help' for more information."
61 "Usage: elm-server [OPTIONS]\n\
62 \Compiles and serves .elm files from the current directory.\n\
63 \Example: elm-server\n\
65 \Resource Locations:\n\
66 \ --runtime-location set the location of the Elm runtime\n\
68 \Compiler Information:\n\
69 \ --version print the version information and exit\n\
70 \ --help display this help and exit\n\
72 \Elm home page: <http://elm-lang.org>"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list