Get runtime location working properly.

This commit is contained in:
evancz 2012-10-03 02:47:46 -04:00
parent f45433145c
commit 253e768e62
5 changed files with 21 additions and 17 deletions

View file

@ -9,11 +9,13 @@ import Happstack.Server.Compression
import System.Directory (makeRelativeToCurrentDirectory)
import System.Environment
import qualified Language.Elm as Elm
import Paths_Elm
import Paths_elm_server
runtime = "/elm-" ++ show version ++ ".js"
serve :: String -> IO ()
serve libLoc = do
putStrLn "Elm Server 0.4.0.3: running at <http://localhost:8000>"
putStrLn ("Elm Server "++show version++": running at <http://localhost:8000>")
simpleHTTP nullConf $ do
_ <- compressedResponseFilter
msum [ uriRest serveElm
@ -29,10 +31,10 @@ serveElm fp = do
let ('/':filePath) = fp
guard (".elm" `isSuffixOf` filePath)
content <- liftIO (readFile filePath)
ok . toResponse $ Elm.toHtml "elm-runtime.js" (pageTitle filePath) content
ok . toResponse $ Elm.toHtml runtime (pageTitle filePath) content
serveLib libLoc fp = do
guard (fp == "/elm-runtime.js")
guard (fp == runtime)
serveFile (asContentType "application/javascript") libLoc
main :: IO ()
@ -40,11 +42,8 @@ main = getArgs >>= parse
parse :: [String] -> IO ()
parse ("--help":_) = putStrLn usage
parse ("--version":_) = putStrLn "The Elm Server 0.4.0.3"
parse [] = do
absolutePath <- getDataFileName "elm-runtime-0.4.0.3.js"
runtime <- makeRelativeToCurrentDirectory absolutePath
serve runtime
parse ("--version":_) = putStrLn ("The Elm Server " ++ show version)
parse [] = serve =<< Elm.runtimeLocation
parse [arg]
| "--runtime-location=" `isPrefixOf` arg =
serve . tail $ dropWhile (/='=') arg
@ -63,7 +62,7 @@ usage =
\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\

View file

@ -35,4 +35,4 @@ Executable elm-server
happstack-server == 7.0.2,
deepseq,
directory,
Elm == 0.4.*
Elm >= 0.4.0.3

View file

@ -32,7 +32,6 @@ source-repository head
Library
exposed-modules: Language.Elm,
Language.Elm.Quasi
Paths_Elm
Hs-Source-Dirs: src, src/Parse, src/Types, src/Gen
other-modules: Ast,
CompileToJS,
@ -56,7 +55,8 @@ Library
Types.Constrain,
Types.Hints,
Types.Substitutions,
Types.Unify
Types.Unify,
Paths_Elm
Build-depends: base >=4.2 && <5,
containers >= 0.3,
@ -98,7 +98,8 @@ Executable elm
Types.Constrain,
Types.Hints,
Types.Substitutions,
Types.Unify
Types.Unify,
Paths_Elm
Build-depends: base >=4.2 && <5,
containers >= 0.3,

View file

@ -40,11 +40,11 @@ elm = ELM { make = False &= help "automatically compile dependencies."
, minify = False &= help "Minify generated JavaScript"
} &=
help "Compile Elm programs to HTML, CSS, and JavaScript." &=
summary "The Elm Compiler v0.4.0.3, (c) Evan Czaplicki"
summary ("The Elm Compiler " ++ show version ++ ", (c) Evan Czaplicki")
main = do
args <- cmdArgs elm
mini <- getDataFileName "elm-runtime-0.4.0.3.js"
mini <- getDataFileName ("elm-runtime-" ++ show version ++ ".js")
compileArgs mini args
compileArgs mini (ELM _ [] _ _ _ _ _ _) =

View file

@ -12,7 +12,8 @@
Example implementations using Yesod and Happstack are available at <https://github.com/tazjin/Elm/tree/master/Examples>
-}
module Language.Elm (
ElmSource (..)
ElmSource (..),
runtimeLocation
) where
import CompileToJS
@ -21,10 +22,13 @@ import GenerateHtml
import Initialize
import Text.Blaze.Html (Html)
import Language.Elm.Quasi
import Paths_Elm
import qualified Data.Text as TS
import qualified Data.Text.Lazy as TL
runtimeLocation = getDataFileName ("elm-runtime-" ++ show version ++ ".js")
class ElmSource a where
-- |This function compiles Elm code to three separate parts: HTML, CSS,
-- and JavaScript. The HTML is only the contents of the body, so the three