* restructuring, part #1

I am splitting the elm package up into several packages, elm itself
which exports the Language.Elm* modules and builds the compiler
executable, elm-server which contains the standalone, Happstack-based
Elm server and elm-yesod, which provides the generateWidget function
for using Elm together with Yesod.
This commit is contained in:
Vincent Ambo 2012-05-28 16:43:56 +02:00
parent f7e985243a
commit f2e8703a2b
49 changed files with 174 additions and 100 deletions

View file

@ -1,73 +0,0 @@
Name: Elm
Version: 0.1.1.7
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
language to HTML, CSS, and JS. This package provides a
compiler and server for Elm.
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
-- .hs or .lhs file containing the Main module.
Main-is: Compiler.hs
Hs-Source-Dirs: src, src/Parse, src/Types, src/Language
other-modules: Ast, CompileToJS, GenerateHtml, Guid, Initialize,
Rename, Language.Elm, Binop, Combinators, Lexer,
ParsePatterns, Parser, ParserLib, ParseTypes, Tokens,
Types, Constrain, Hints, Types, Unify, ExtractNoscript
-- Packages needed in order to build this package.
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.*, blaze-markup == 0.5.1.*,
deepseq
-- Modules not exported by this package.
-- Other-modules:
-- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.
-- Build-tools:
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,
template-haskell
Library
exposed-modules: Language.Elm, Language.Elm.Yesod
Hs-Source-Dirs: src, src/Parse, src/Types
other-modules: Ast, CompileToJS, GenerateHtml, Guid, Initialize,
Rename, Binop, Combinators, Lexer,
ParsePatterns, Parser, ParserLib, ParseTypes, Tokens,
Types, Constrain, Hints, Types, Unify, ExtractNoscript

View file

View file

@ -0,0 +1,13 @@
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,

View file

@ -1,6 +1,6 @@
{-# LANGUAGE QuasiQuotes, TemplateHaskell #-}
module Language.Elm.Yesod (elm, generateWidget) where
module Language.Elm.Yesod (generateWidget) where
import Language.Haskell.TH.Quote
import Language.Haskell.TH
@ -14,9 +14,6 @@ import Initialize
import CompileToJS
import ExtractNoscript
elm :: QuasiQuoter
elm = QuasiQuoter {quoteExp = \s -> [|s|] }
css = [lucius|
* { padding:0; margin:0;
hyphens: auto; -moz-hyphens: auto;

93
elm/Elm.cabal Normal file
View file

@ -0,0 +1,93 @@
Name: Elm
Version: 0.1.1.8
Synopsis: The Elm language module.
Description: Elm aims to make client-side web-development more pleasant.
It is a statically/strongly typed, functional reactive
language to HTML, CSS, and JS. This package provides a
library for Elm compilation in Haskell and a compiler
executable.
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
-- .hs or .lhs file containing the Main module.
Main-is: Compiler.hs
Hs-Source-Dirs: src, src/Parse, src/Types, src/Language
other-modules: Ast,
Binop,
Combinators,
Constrain,
Guid,
Hints,
Lexer,
ParsePatterns,
Parser,
ParserLib,
ParseTypes,
Rename,
Tokens,
Types,
Types,
Unify
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.*,
blaze-markup == 0.5.1.*,
deepseq
Library
exposed-modules: Language.Elm,
Language.Elm.CompileToJS,
Language.Elm.ExtractNoscript,
Language.Elm.Initialize
Hs-Source-Dirs: src, src/Parse, src/Types
other-modules: Ast,
Guid,
Rename,
Binop,
Combinators,
Lexer,
ParsePatterns,
Parser,
ParserLib,
ParseTypes,
Tokens,
Types,
Constrain,
Hints,
Types,
Unify
Build-depends: base >=4.2 && <5,
containers >= 0.3,
transformers >= 0.2,
mtl >= 2,
parsec >= 3.1.1,
blaze-html == 0.5.0.*,
blaze-markup == 0.5.1.*,
deepseq,
template-haskell

View file

@ -1,10 +1,9 @@
module Main where
import System.Environment
import CompileToJS
import Data.List (isPrefixOf)
import GenerateHtml
import Language.Elm.CompileToJS
import Language.Elm.GenerateHtml
import System.Environment
import Text.Blaze.Html.Renderer.String (renderHtml)
main = getArgs >>= parse

18
elm/src/Language/Elm.hs Normal file
View file

@ -0,0 +1,18 @@
{-# LANGUAGE QuasiQuotes, TemplateHaskell #-}
module Language.Elm (
module Language.Elm.Initialize,
module Language.Elm.CompileToJS,
module Language.Elm.ExtractNoscript,
generateHtml,
elm) where
import Language.Elm.CompileToJS
import Language.Elm.ExtractNoscript
import Language.Elm.Initialize
import Language.Elm.GenerateHtml
import Language.Haskell.TH
import Language.Haskell.TH.Quote
elm :: QuasiQuoter
elm = QuasiQuoter {quoteExp = \s -> [|s|] }

View file

@ -1,5 +1,5 @@
module CompileToJS (compile, compileToJS) where
module Language.Elm.CompileToJS (compile, compileToJS) where
import Ast
import Control.Monad (liftM,(<=<),join)
@ -7,7 +7,7 @@ import Data.Char (isAlpha)
import Data.List (intercalate,sortBy)
import Data.Map (toList)
import Initialize
import Language.Elm.Initialize
compile = (return . addMain . toJS) <=< initialize

View file

@ -1,5 +1,5 @@
module ExtractNoscript (extract) where
module Language.Elm.ExtractNoscript (extract) where
import Ast

View file

@ -0,0 +1,42 @@
{-# LANGUAGE OverloadedStrings #-}
module Language.Elm.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 Language.Elm.Initialize
import Language.Elm.CompileToJS
import Language.Elm.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

View file

@ -1,4 +1,4 @@
module Initialize (initialize) where
module Language.Elm.Initialize (initialize) where
import Ast
import Control.Arrow (first, second)

View file

@ -1,15 +0,0 @@
module Language.Elm where
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 source