elm-server 0.4.0 → 0.4.0.3
raw patch · 2 files changed
+18/−9 lines, 2 filesdep +directorydep ~Elm
Dependencies added: directory
Dependency ranges changed: Elm
Files
- Server.hs +15/−7
- elm-server.cabal +3/−2
Server.hs view
@@ -6,15 +6,20 @@ import Data.List (isPrefixOf, isSuffixOf) import Happstack.Server import Happstack.Server.Compression+import System.Directory (makeRelativeToCurrentDirectory) import System.Environment import qualified Language.Elm as Elm+import Paths_elm_server +runtime = "/elm-" ++ show version ++ ".js"+ serve :: String -> IO () serve libLoc = do- putStrLn "Elm Server 0.4.0: running at <http://localhost:8000>"+ putStrLn ("Elm Server "++show version++": running at <http://localhost:8000>") simpleHTTP nullConf $ do _ <- compressedResponseFilter- msum [ uriRest (serveElm libLoc)+ msum [ uriRest serveElm+ , uriRest (serveLib libLoc) , serveDirectory EnableBrowsing [] "." ] @@ -22,20 +27,23 @@ pageTitle fp = reverse . takeWhile (/='/') . drop 1 . dropWhile (/='.') $ reverse fp -serveElm libLoc fp = do+serveElm fp = do let ('/':filePath) = fp guard (".elm" `isSuffixOf` filePath) content <- liftIO (readFile filePath)- ok . toResponse $ Elm.toHtml libLoc (pageTitle filePath) content+ ok . toResponse $ Elm.toHtml runtime (pageTitle filePath) content +serveLib libLoc fp = do+ guard (fp == runtime)+ serveFile (asContentType "application/javascript") libLoc main :: IO () main = getArgs >>= parse parse :: [String] -> IO () parse ("--help":_) = putStrLn usage-parse ("--version":_) = putStrLn "The Elm Server 0.3.5"-parse [] = serve "/elm-mini.js"+parse ("--version":_) = putStrLn ("The Elm Server " ++ show version)+parse [] = serve =<< Elm.runtimeLocation parse [arg] | "--runtime-location=" `isPrefixOf` arg = serve . tail $ dropWhile (/='=') arg@@ -54,7 +62,7 @@ \Example: elm-server\n\ \\n\ \Resource Locations:\n\- \ --runtime-location set the location of the Elm runtime (elm-mini.js)\n\+ \ --runtime-location set the location of the Elm runtime\n\ \\n\ \Compiler Information:\n\ \ --version print the version information and exit\n\
elm-server.cabal view
@@ -1,5 +1,5 @@ Name: elm-server-Version: 0.4.0+Version: 0.4.0.3 Synopsis: The Elm language server. Description: This package provides a standalone, Happstack-based Elm server. @@ -34,4 +34,5 @@ HTTP >= 4000, happstack-server == 7.0.2, deepseq,- Elm == 0.4.*+ directory,+ Elm >= 0.4.0.3