Skip to content

Commit

Permalink
Do some house keeping in the Compiler.hs file. Start using the `Syste…
Browse files Browse the repository at this point in the history
…m.FilePath` module which cleaned up some code and is probably significantly safer :)
  • Loading branch information
process-bot committed Nov 25, 2012
1 parent 0d03de7 commit fb3acd7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 4 additions & 2 deletions elm/Elm.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ Library
pandoc <= 1.9.4.2,
bytestring,
hjsmin,
indents
indents,
filepath

Executable elm
Main-is: Compiler.hs
Expand Down Expand Up @@ -114,4 +115,5 @@ Executable elm
pandoc <= 1.9.4.2,
bytestring,
hjsmin,
indents
indents,
filepath
16 changes: 8 additions & 8 deletions elm/src/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Data.List (intersect, intercalate)
import Data.Maybe (fromMaybe)
import Data.Version (showVersion)
import System.Console.CmdArgs
import System.FilePath
import Text.Blaze.Html.Renderer.String (renderHtml)

import qualified Text.Jasmine as JS
Expand All @@ -17,6 +18,7 @@ import CompileToJS
import GenerateHtml
import Paths_Elm

import System.IO.Unsafe

data ELM =
ELM { make :: Bool
Expand Down Expand Up @@ -68,12 +70,10 @@ fileTo isMini get what jsFiles noscript outputDir rtLoc file = do
case ems of
Left err -> putStrLn $ "Error while compiling " ++ file ++ ":\n" ++ err
Right ms ->
let path = case outputDir of
Nothing -> reverse . tail . dropWhile (/='.') $ reverse file
Just dir -> (\s -> dir ++ "/" ++ s) . reverse . takeWhile (/='/') . tail . dropWhile (/='.') $ reverse file
js = path ++ ".js"
html = path ++ ".html"
in case what of
let path = fromMaybe "" outputDir </> file
js = replaceExtension path ".js"
html = replaceExtension path ".html"
in case unsafePerformIO (print path) `seq` what of
JS -> writeFile js . formatJS $ jss ++ concatMap jsModule ms
HTML -> writeFile html . renderHtml $ modulesToHtml jsStyle "" rtLoc jss noscript ms
Split -> do
Expand Down Expand Up @@ -105,10 +105,10 @@ toFilePath :: String -> FilePath
toFilePath modul = map (\c -> if c == '.' then '/' else c) modul ++ ".elm"

builtInModules =
concat [ [ "List", "Char", "Maybe", "Dict", "Set", "Automaton" ]
concat [ [ "List", "Char", "Maybe", "Dict", "Set", "Automaton", "Date" ]
, [ "Signal", "Mouse", "Keyboard.Raw"
, "Window", "Time", "HTTP", "Input", "Random" ]
, [ "Graphics", "Text", "Color" ]
, map ("JavaScript"++) [ "", "Experimental" ]
, map ("JavaScript"++) [ "", ".Experimental" ]
, [ "Prelude", "JSON" ]
]

0 comments on commit fb3acd7

Please sign in to comment.