* modified elm-server

Elm-server now works with the "new" structure of Elm as well. The elm
package exports Language.Elm.generateHtml which is equivalent to the
compileToHtml function of the old Language.Elm package.

Since a dependency on blaze exists either way, a separate elm-blaze
package is not necessary.
This commit is contained in:
Vincent Ambo 2012-05-28 16:56:13 +02:00
parent f2e8703a2b
commit 08287fcea7
22 changed files with 70 additions and 56 deletions

View file

@ -1,42 +0,0 @@
{-# LANGUAGE OverloadedStrings #-}
module GenerateHtml (generateHtml) where
import Text.Blaze (preEscapedToMarkup)
import qualified Text.Blaze.Html5 as H
import Text.Blaze.Html5 ((!))
import qualified Text.Blaze.Html5.Attributes as A
import Initialize
import CompileToJS
import ExtractNoscript
css = preEscapedToMarkup $
("* { padding:0; margin:0; \
\hyphens: auto; -moz-hyphens: auto;\
\ -webkit-hyphens: auto; -ms-hyphens: auto; }\
\body { font-family: Arial; }\
\a:link {text-decoration: none}\
\a:visited {text-decoration: none}\
\a:active {text-decoration: none}\
\a:hover {text-decoration: underline; color: #ff8f12;}" :: String)
makeScript :: String -> H.Html
makeScript s = H.script ! A.type_ "text/javascript" ! A.src (H.toValue s) $ ""
generateHtml libLoc title source =
let expr = initialize source
js = compileToJS expr
noscript = either id extract expr
in
H.docTypeHtml $ do
H.head $ do
H.meta ! A.charset "UTF-8"
H.title . H.toHtml $ title
makeScript libLoc
H.script ! A.type_ "text/javascript" $ preEscapedToMarkup js
H.style ! A.type_ "text/css" $ css
H.body $ do
H.div ! A.id "widthChecker" ! A.style "width:100%; height:1px; position:absolute; top:-1px;" $ ""
H.span ! A.id "content" $ ""
H.script ! A.type_ "text/javascript" $ "Dispatcher.initialize()"
H.noscript $ preEscapedToMarkup noscript

30
elm-server/LICENSE Normal file
View file

@ -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.

View file

@ -11,7 +11,7 @@ import Language.Elm
serve :: String -> IO ()
serve libLoc = do
putStrLn "Elm Server 0.1.1.7: running at <http://localhost:8000>"
putStrLn "Elm Server 0.1.1.8: running at <http://localhost:8000>"
simpleHTTP nullConf $ do
compressedResponseFilter
msum [ uriRest (serveElm libLoc)
@ -25,7 +25,7 @@ serveElm libLoc fp = do
let ('/':path) = fp
guard (".elm" `isSuffixOf` path)
content <- liftIO (readFile path)
ok . toResponse $ compileToHtml libLoc (pageTitle path) content
ok . toResponse $ generateHtml libLoc (pageTitle path) content
main = getArgs >>= parse

View file

@ -1,13 +1,38 @@
Name: Elm-server
Version: 0.1.1.8
Synopsis: The Elm language module.
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
Hs-Source-Dirs: src, src/Parse, src/Types
other-modules: Ast, CompileToJS, GenerateHtml, Guid, Initialize,
Rename, Language.Elm, Binop, Combinators, Lexer,
ParsePatterns, Parser, ParserLib, ParseTypes, Tokens,
Types, Constrain, Hints, Types, Unify, ExtractNoscript
ghc-options: -O3
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, yesod-core, shakespeare-css, shakespeare-js, hamlet,
ghc-options: -O2
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.1.8

View file

@ -63,7 +63,8 @@ Library
exposed-modules: Language.Elm,
Language.Elm.CompileToJS,
Language.Elm.ExtractNoscript,
Language.Elm.Initialize
Language.Elm.Initialize,
Language.Elm.GenerateHtml
Hs-Source-Dirs: src, src/Parse, src/Types
other-modules: Ast,
Guid,