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 ++ ": running at <http://localhost:8000>")
20 putStrLn "Just refresh a page to recompile it!"
21 simpleHTTP nullConf $ do
22 _ <- compressedResponseFilter
23 msum [ uriRest serveElm
24 , uriRest (serveLib libLoc)
25 , serveDirectory EnableBrowsing [] "."
28pageTitle :: String -> String
29pageTitle = dropExtension . takeBaseName
32 guard (takeExtension fp == ".elm")
33 content <- liftIO (readFile (tail fp))
34 ok . toResponse $ Elm.toHtml runtime (pageTitle fp) content
36serveLib libLoc fp = do
38 serveFile (asContentType "application/javascript") libLoc
41main = getArgs >>= parse
43parse :: [String] -> IO ()
44parse ("--help":_) = putStrLn usage
45parse ("--version":_) = putStrLn ("The Elm Server " ++ showVersion version)
46parse [] = serve =<< Elm.runtimeLocation
48 | "--runtime-location=" `isPrefixOf` arg =
49 serve . tail $ dropWhile (/='=') arg
50 | otherwise = putStrLn usageMini
51parse _ = putStrLn usageMini
55 "Usage: elm-server [OPTIONS]\n\
56 \Try `elm-server --help' for more information."
60 "Usage: elm-server [OPTIONS]\n\
61 \Compiles and serves .elm files from the current directory.\n\
62 \Example: elm-server\n\
64 \Resource Locations:\n\
65 \ --runtime-location set the location of the Elm runtime\n\
67 \Compiler Information:\n\
68 \ --version print the version information and exit\n\
69 \ --help display this help and exit\n\
71 \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