packages feed

Elm 0.1.1.4 → 0.1.1.5

raw patch · 6 files changed

+22/−8 lines, 6 files

Files

Elm.cabal view
@@ -1,6 +1,6 @@  Name:                Elm-Version:             0.1.1.4+Version:             0.1.1.5 Synopsis:            The Elm compiler and server. Description:         Elm aims to make client-side web-development more pleasant.                      It is a statically/strongly typed, functional reactive
src/CompileToJS.hs view
@@ -11,7 +11,7 @@   compile = (return . addMain . toJS) <=< initialize-compileToJS = addMain . either (\err -> "text('"++err++"')") toJS . initialize+compileToJS = addMain . either (\err -> "text('"++err++"')") toJS addMain body = "function main(){return " ++ body ++ ";}"  parens = ("("++) . (++")")
src/Compiler.hs view
@@ -10,7 +10,7 @@ main = getArgs >>= parse  parse ("--help":_) = putStrLn usage-parse ("--version":_) = putStrLn "The Elm Compiler 0.1.1.4"+parse ("--version":_) = putStrLn "The Elm Compiler 0.1.1.5" parse [loc,file]   | "--runtime-location=" `isPrefixOf` loc =       produceHtml (tail $ dropWhile (/='=') loc) file
src/GenerateHtml.hs view
@@ -6,6 +6,10 @@ 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;\
@@ -20,14 +24,19 @@ 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 $ source
+        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
src/Language/Elm.hs view
@@ -1,10 +1,15 @@ 
 module Language.Elm where
 
-import CompileToJS
 import GenerateHtml
 import Text.Blaze.Html (Html)
 
+-- | The 'compileToHtml' function takes three string arguments: the
+-- location of the Elm runtime (elm-mini.js), the title to be used in
+-- the resulting HTML page, and the Elm source code. For example,
+-- 
+-- > compileToHtml "/elm-mini.js" "Hello, World!" "main = plainText \"Hello, World!\""
+
 compileToHtml :: String -> String -> String -> Html
 compileToHtml libLoc fileName source =
-    generateHtml libLoc fileName (compileToJS source)+    generateHtml libLoc fileName source
src/Server.hs view
@@ -11,7 +11,7 @@  serve :: String -> IO () serve libLoc = do-  putStrLn "Elm Server 0.1.1.4: running at <http://localhost:8000>"+  putStrLn "Elm Server 0.1.1.5: running at <http://localhost:8000>"   simpleHTTP nullConf $ do          compressedResponseFilter          msum [ uriRest (serveElm libLoc)@@ -31,7 +31,7 @@ main = getArgs >>= parse  parse ("--help":_) = putStrLn usage-parse ("--version":_) = putStrLn "The Elm Server 0.1.1.4"+parse ("--version":_) = putStrLn "The Elm Server 0.1.1.5" parse [] = serve "/elm-mini.js" parse [arg]     | "--runtime-location=" `isPrefixOf` arg =