on master help sign in
Add markdown support. Add minification support.
0391c1cevancz
elm/Elm.cabal+6−2
@@ -68,7 +68,9 @@ Library
68 text,
68 text,
69 template-haskell,
69 template-haskell,
70 shakespeare,
70 shakespeare,
71− pandoc
71+ pandoc,
72+ bytestring,
73+ hjsmin
72
74
73Executable elm
75Executable elm
74 Main-is: Compiler.hs
76 Main-is: Compiler.hs
@@ -106,4 +108,6 @@ Executable elm
106 blaze-markup == 0.5.1.*,
108 blaze-markup == 0.5.1.*,
107 deepseq,
109 deepseq,
108 cmdargs,
110 cmdargs,
109− pandoc
111+ pandoc,
112+ bytestring,
113+ hjsmin
elm/changelog.txt+21
@@ -1,4 +1,25 @@
1
1
2+Release 0.4.0
3+=============
4+
5+This version is all about graphics: nicer API with more features and major
6+efficiency improvements. I am really excited about this release!
7+
8+* Add native Markdown support. You can now embed markdown directly in .elm files
9+ and it is used as an `Element`. Syntax is `[markdown| ... |]` where `...` is
10+ formatted as described [here](http://daringfireball.net/projects/markdown/).
11+ Content can span multiple lines too.
12+
13+* Drastically improve the `collage` interface. You can now move, rotate, and scale
14+ the following forms:
15+ - Lines
16+ - Shapes (shapes can be textured now too)
17+ - Images
18+ - Elements (any Element you want can be turned into a Form with `toForm`)
19+ This will make it way easier to make games in Elm.
20+
21+* Add `--minify` flag, to minify JS code.
22+
2Release 0.3.6
23Release 0.3.6
3=============
24=============
4
25
elm/src/Compiler.hs+16−9
@@ -7,6 +7,9 @@ import Data.Maybe (fromMaybe)
7import System.Console.CmdArgs
7import System.Console.CmdArgs
8import Text.Blaze.Html.Renderer.String (renderHtml)
8import Text.Blaze.Html.Renderer.String (renderHtml)
9
9
10+import qualified Text.Jasmine as JS
11+import qualified Data.ByteString.Lazy.Char8 as BS
12+
10import Ast
13import Ast
11import Initialize
14import Initialize
12import CompileToJS
15import CompileToJS
@@ -22,6 +25,7 @@ data ELM =
22 , only_js :: Bool
25 , only_js :: Bool
23 , import_js :: [FilePath]
26 , import_js :: [FilePath]
24 , generate_noscript :: Bool
27 , generate_noscript :: Bool
28+ , minify :: Bool
25 }
29 }
26 deriving (Data,Typeable,Show,Eq)
30 deriving (Data,Typeable,Show,Eq)
27
31
@@ -33,26 +37,29 @@ elm = ELM { make = False &= help "automatically compile dependencies."
33 , only_js = False &= help "Compile only to JavaScript."
37 , only_js = False &= help "Compile only to JavaScript."
34 , import_js = [] &= typFile &= help "Include a JavaScript file before the body of the Elm program. Can be used many times. Files will be included in the given order."
38 , import_js = [] &= typFile &= help "Include a JavaScript file before the body of the Elm program. Can be used many times. Files will be included in the given order."
35 , generate_noscript = True &= help "Add generated <noscript> tag to HTML output."
39 , generate_noscript = True &= help "Add generated <noscript> tag to HTML output."
40+ , minify = False &= help "Minify generated JavaScript"
36 } &=
41 } &=
37 help "Compile Elm programs to HTML, CSS, and JavaScript." &=
42 help "Compile Elm programs to HTML, CSS, and JavaScript." &=
38− summary "The Elm Compiler v0.3.6.2, (c) Evan Czaplicki"
43+ summary "The Elm Compiler v0.4.0, (c) Evan Czaplicki"
39
44
40main = do
45main = do
41 args <- cmdArgs elm
46 args <- cmdArgs elm
42− mini <- getDataFileName "elm-runtime-0.3.6.2.js"
47+ mini <- getDataFileName "elm-runtime-0.4.0.js"
43 compileArgs mini args
48 compileArgs mini args
44
49
45−compileArgs mini (ELM _ [] _ _ _ _ _) =
50+compileArgs mini (ELM _ [] _ _ _ _ _ _) =
46 putStrLn "Usage: elm [OPTIONS] [FILES]\nFor more help: elm --help"
51 putStrLn "Usage: elm [OPTIONS] [FILES]\nFor more help: elm --help"
47−compileArgs mini (ELM make files rtLoc split only js nscrpt) =
52+compileArgs mini (ELM make files rtLoc split only js nscrpt isMini) =
48− mapM_ (fileTo get what js nscrpt $ fromMaybe mini rtLoc) files
53+ mapM_ (fileTo isMini get what js nscrpt $ fromMaybe mini rtLoc) files
49 where get = if make then getModules [] else getModule
54 where get = if make then getModules [] else getModule
50 what = if only then JS else
55 what = if only then JS else
51 if split then Split else HTML
56 if split then Split else HTML
52
57
53data What = JS | HTML | Split
58data What = JS | HTML | Split
54
59
55−fileTo get what jsFiles noscript rtLoc file = do
60+fileTo isMini get what jsFiles noscript rtLoc file = do
61+ let jsStyle = if isMini then Minified else Readable
62+ let formatJS = if isMini then BS.unpack . JS.minify . BS.pack else id
56 ems <- get file
63 ems <- get file
57 jss <- concat `fmap` mapM readFile jsFiles
64 jss <- concat `fmap` mapM readFile jsFiles
58 case ems of
65 case ems of
@@ -62,11 +69,11 @@ fileTo get what jsFiles noscript rtLoc file = do
62 js = name ++ ".js"
69 js = name ++ ".js"
63 html = name ++ ".html"
70 html = name ++ ".html"
64 in case what of
71 in case what of
65− JS -> writeFile js $ jss ++ concatMap jsModule ms
72+ JS -> writeFile js . formatJS $ jss ++ concatMap jsModule ms
66− HTML -> writeFile html . renderHtml $ modulesToHtml "" rtLoc jss noscript ms
73+ HTML -> writeFile html . renderHtml $ modulesToHtml jsStyle "" rtLoc jss noscript ms
67 Split -> do
74 Split -> do
68 writeFile html . renderHtml $ linkedHtml rtLoc js ms
75 writeFile html . renderHtml $ linkedHtml rtLoc js ms
69− writeFile js $ jss ++ concatMap jsModule ms
76+ writeFile js . formatJS $ jss ++ concatMap jsModule ms
70
77
71getModules :: [String] -> FilePath -> IO (Either String [([String],Module)])
78getModules :: [String] -> FilePath -> IO (Either String [([String],Module)])
72getModules uses file = do
79getModules uses file = do
elm/src/Gen/CompileToJS.hs+12−7
@@ -5,7 +5,7 @@ import Ast
5import Control.Arrow (first)
5import Control.Arrow (first)
6import Control.Monad (liftM,(<=<),join,ap)
6import Control.Monad (liftM,(<=<),join,ap)
7import Data.Char (isAlpha,isDigit)
7import Data.Char (isAlpha,isDigit)
8−import Data.List (intercalate,sortBy,inits)
8+import Data.List (intercalate,sortBy,inits,foldl')
9import Data.Map (toList)
9import Data.Map (toList)
10import Data.Maybe (mapMaybe)
10import Data.Maybe (mapMaybe)
11import qualified Text.Pandoc as Pan
11import qualified Text.Pandoc as Pan
@@ -84,8 +84,8 @@ jsImport' (modul, Importing []) = jsImport' (modul, Hiding [])
84jsImport' (modul, Importing vs) =
84jsImport' (modul, Importing vs) =
85 concatMap (\v -> assign v $ modul ++ "." ++ v) vs
85 concatMap (\v -> assign v $ modul ++ "." ++ v) vs
86jsImport' (modul, Hiding vs) =
86jsImport' (modul, Hiding vs) =
87− concat [ "\nfor(var i in " ++ modul ++ "){"
88− , assign "hiddenVars" . jsList $ map (\v -> "'" ++ v ++ "'") vs
87+ concat [ assign "hiddenVars" . jsList $ map (\v -> "'" ++ v ++ "'") vs
88+ , "\nfor(var i in " ++ modul ++ "){"
89 , "\nif (hiddenVars.indexOf(i) >= 0) continue;"
89 , "\nif (hiddenVars.indexOf(i) >= 0) continue;"
90 , globalAssign "this[i]" $ modul ++ "[i]"
90 , globalAssign "this[i]" $ modul ++ "[i]"
91 , "}" ]
91 , "}" ]
@@ -142,10 +142,15 @@ toJS' expr =
142 Let defs e -> jsLet defs e
142 Let defs e -> jsLet defs e
143 Case e cases -> caseToJS e cases
143 Case e cases -> caseToJS e cases
144 Data name es -> (\ss -> jsList $ show name : ss) `liftM` mapM toJS' es
144 Data name es -> (\ss -> jsList $ show name : ss) `liftM` mapM toJS' es
145− Markdown doc ->
145+ Markdown doc -> return $ "text('" ++ pad ++ md ++ pad ++ "')"
146− return $ concat [ "text('<div style=\"height:0;width:0;\">&nbsp;</div>"
147− , filter (/='\n') $ Pan.writeHtmlString Pan.defaultWriterOptions doc
146+ where md = formatMarkdown $ Pan.writeHtmlString Pan.defaultWriterOptions doc
148− , "<div style=\"height:0;width:0;\">&nbsp;</div>')" ]
147+ pad = "<div style=\"height:0;width:0;\">&nbsp;</div>"
148+
149+formatMarkdown = concatMap f
150+ where f '\'' = "\\'"
151+ f '\n' = ""
152+ f '"' = "\""
153+ f c = [c]
149
154
150jsLet defs e' = do
155jsLet defs e' = do
151 body <- (++) `liftM` jsDefs defs `ap` (ret `liftM` toJS' e')
156 body <- (++) `liftM` jsDefs defs `ap` (ret `liftM` toJS' e')
elm/src/Gen/GenerateHtml.hs+22−13
@@ -1,7 +1,8 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2module GenerateHtml (generateHtml,
2module GenerateHtml (generateHtml,
3 body, css, widgetBody,
3 body, css, widgetBody,
4− modulesToHtml, linkedHtml
4+ modulesToHtml, linkedHtml,
5+ JSStyle (..)
5 ) where
6 ) where
6
7
7import Data.List (intercalate)
8import Data.List (intercalate)
@@ -11,6 +12,9 @@ import qualified Text.Blaze.Html5 as H
11import Text.Blaze.Html5 ((!))
12import Text.Blaze.Html5 ((!))
12import qualified Text.Blaze.Html5.Attributes as A
13import qualified Text.Blaze.Html5.Attributes as A
13
14
15+import Text.Jasmine (minify)
16+import qualified Data.ByteString.Lazy.Char8 as BS
17+
14import Ast
18import Ast
15import Initialize
19import Initialize
16import CompileToJS
20import CompileToJS
@@ -28,11 +32,15 @@ css = H.style ! A.type_ "text/css" $ preEscapedToMarkup
28 \ -webkit-hyphens: auto; -ms-hyphens: auto; }\
32 \ -webkit-hyphens: auto; -ms-hyphens: auto; }\
29--}
33--}
30
34
35+data JSStyle = Minified | Readable
36+
31−makeScript :: Either String String -> H.Html
37+makeScript :: JSStyle -> Either String String -> H.Html
32−makeScript (Left s) =
38+makeScript _ (Left s) =
33 H.script ! A.type_ "text/javascript" ! A.src (H.toValue s) $ ""
39 H.script ! A.type_ "text/javascript" ! A.src (H.toValue s) $ ""
34−makeScript (Right s) =
35− H.script ! A.type_ "text/javascript" $ preEscapedToMarkup s
40+makeScript jsStyle (Right s) = H.script ! A.type_ "text/javascript" $ preEscapedToMarkup content
41+ where content = case jsStyle of
42+ Minified -> BS.unpack . minify . BS.pack $ s
43+ Readable -> s
36
44
37-- |This function compiles Elm code into simple HTML.
45-- |This function compiles Elm code into simple HTML.
38--
46--
@@ -45,11 +53,11 @@ generateHtml :: String -- ^ Location of elm-min.js as expected by the browser
45 -> Html
53 -> Html
46generateHtml libLoc title source =
54generateHtml libLoc title source =
47 case initialize source of
55 case initialize source of
48− Left err -> createHtml libLoc title (Right $ showErr err) (H.noscript "")
56+ Left err -> createHtml Readable libLoc title (Right $ showErr err) (H.noscript "")
49− Right (escs, modul) -> modulesToHtml title libLoc [] True [(escs,modul)]
57+ Right (escs, modul) -> modulesToHtml Readable title libLoc [] True [(escs,modul)]
50
58
51
59
52−modulesToHtml title libLoc jss nscrpt pairs = createHtml libLoc title' js noscript
60+modulesToHtml jsStyle title libLoc jss nscrpt pairs = createHtml jsStyle libLoc title' js noscript
53 where modules = map snd pairs
61 where modules = map snd pairs
54 js = Right $ jss ++ concatMap jsModule pairs
62 js = Right $ jss ++ concatMap jsModule pairs
55 noscript = if nscrpt then extract $ last modules else ""
63 noscript = if nscrpt then extract $ last modules else ""
@@ -59,20 +67,21 @@ modulesToHtml title libLoc jss nscrpt pairs = createHtml libLoc title' js noscri
59
67
60
68
61linkedHtml rtLoc jsLoc modules =
69linkedHtml rtLoc jsLoc modules =
62− createHtml rtLoc title (Left jsLoc) (H.noscript "")
70+ createHtml Readable rtLoc title (Left jsLoc) (H.noscript "")
63 where title = (\(Module names _ _ _) -> intercalate "." names) $
71 where title = (\(Module names _ _ _) -> intercalate "." names) $
64 snd (last modules)
72 snd (last modules)
65
73
66
74
67−createHtml libLoc title js noscript =
75+createHtml jsStyle libLoc title js noscript =
68 H.docTypeHtml $ do
76 H.docTypeHtml $ do
69 H.head $ do
77 H.head $ do
70 H.meta ! A.charset "UTF-8"
78 H.meta ! A.charset "UTF-8"
71 H.title . H.toHtml $ title
79 H.title . H.toHtml $ title
72− makeScript (Left libLoc)
73− makeScript js
74 css
80 css
81+ H.body $ do
82+ makeScript Readable (Left libLoc)
83+ makeScript jsStyle js
75− H.body $ body noscript
84+ body noscript
76
85
77body noscript = do
86body noscript = do
78 H.div ! A.id "widthChecker" ! A.style "width:100%; height:1px; position:absolute; top:-1px;" $ ""
87 H.div ! A.id "widthChecker" ! A.style "width:100%; height:1px; position:absolute; top:-1px;" $ ""
elm/src/Types/Hints.hs+1−1
@@ -15,7 +15,7 @@ textToText = [ "header", "italic", "bold", "underline"
15 , "overline", "strikeThrough", "monospace" ]
15 , "overline", "strikeThrough", "monospace" ]
16
16
17textAttrs = [ "toText" -: string ==> text
17textAttrs = [ "toText" -: string ==> text
18− , "link" -: string ==> text ==> text
18+ --, "link" -: string ==> text ==> text
19 , numScheme (\t -> t ==> text ==> text) "Text.height"
19 , numScheme (\t -> t ==> text ==> text) "Text.height"
20 ] ++ hasType (text ==> text) textToText
20 ] ++ hasType (text ==> text) textToText
21
21