elm-server (empty) → 0.1.2
raw patch · 4 files changed
+133/−0 lines, 4 filesdep +Elmdep +HTTPdep +basesetup-changed
Dependencies added: Elm, HTTP, base, blaze-html, containers, deepseq, happstack-server, mtl, parsec, transformers
Files
- LICENSE +30/−0
- Server.hs +63/−0
- Setup.hs +2/−0
- elm-server.cabal +38/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2012, Evan Czaplicki + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Evan Czaplicki nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Server.hs view
@@ -0,0 +1,63 @@+ +module Main where + +import Control.Monad (msum,guard) +import Control.Monad.Trans (MonadIO(liftIO)) +import Data.List (isPrefixOf, isSuffixOf) +import Happstack.Server +import Happstack.Server.Compression +import System.Environment +import qualified Language.Elm as Elm + +serve :: String -> IO () +serve libLoc = do + putStrLn "Elm Server 0.1.2: running at <http://localhost:8000>" + simpleHTTP nullConf $ do + _ <- compressedResponseFilter + msum [ uriRest (serveElm libLoc) + , serveDirectory EnableBrowsing [] "." + ] + +pageTitle :: String -> String +pageTitle fp = + reverse . takeWhile (/='/') . drop 1 . dropWhile (/='.') $ reverse fp + +serveElm libLoc fp = do + let ('/':filePath) = fp + guard (".elm" `isSuffixOf` filePath) + content <- liftIO (readFile filePath) + ok . toResponse $ Elm.toHtml libLoc (pageTitle filePath) content + + +main :: IO () +main = getArgs >>= parse + +parse :: [String] -> IO () +parse ("--help":_) = putStrLn usage +parse ("--version":_) = putStrLn "The Elm Server 0.1.2" +parse [] = serve "/elm-mini.js" +parse [arg] + | "--runtime-location=" `isPrefixOf` arg = + serve . tail $ dropWhile (/='=') arg + | otherwise = putStrLn usageMini +parse _ = putStrLn usageMini + +usageMini :: String +usageMini = + "Usage: elm-server [OPTIONS]\n\ + \Try `elm-server --help' for more information." + +usage :: String +usage = + "Usage: elm-server [OPTIONS]\n\ + \Compiles and serves .elm files from the current directory.\n\ + \Example: elm-server\n\ + \\n\ + \Resource Locations:\n\ + \ --runtime-location set the location of the Elm runtime (elm-mini.js)\n\ + \\n\ + \Compiler Information:\n\ + \ --version print the version information and exit\n\ + \ --help display this help and exit\n\ + \\n\ + \Elm home page: <http://elm-lang.org>"
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple +main = defaultMain
+ elm-server.cabal view
@@ -0,0 +1,38 @@+Name: elm-server +Version: 0.1.2 +Synopsis: The Elm language server. +Description: This package provides a standalone, Happstack-based Elm server. + +Homepage: http://elm-lang.org + +License: BSD3 +License-file: LICENSE + +Author: Evan Czaplicki +Maintainer: info@elm-lang.org +Copyright: Copyright: (c) 2011-2012 Evan Czaplicki + +Category: Compiler, Language + +Build-type: Simple + +--Extra-source-files: README.md +Cabal-version: >=1.6 + +source-repository head + type: git + location: git://github.com/evancz/Elm.git + +Executable elm-server + Main-is: Server.hs +-- ghc-options: -O2 -Wall + Build-depends: base >=4.2 && <5, + containers >= 0.3, + transformers >= 0.2, + mtl >= 2, + parsec >= 3.1.1, + blaze-html == 0.5.0.*, + HTTP >= 4000, + happstack-server == 7.0.2, + deepseq, + Elm == 0.1.2.*