Remove minification from compiler.

Unix philosophy and all that.
This commit is contained in:
Evan Czaplicki 2013-09-28 15:36:02 -04:00
parent de232b677e
commit 66c288e4ba
3 changed files with 8 additions and 23 deletions

View file

@ -87,7 +87,6 @@ Library
containers >= 0.3,
directory,
filepath,
hjsmin,
indents,
language-ecmascript,
mtl >= 2,
@ -157,7 +156,6 @@ Executable elm
containers >= 0.3,
directory,
filepath,
hjsmin,
indents,
language-ecmascript,
mtl >= 2,

View file

@ -13,9 +13,7 @@ import System.FilePath
import System.IO
import GHC.Conc
import qualified Text.Blaze.Html.Renderer.Pretty as Pretty
import qualified Text.Blaze.Html.Renderer.String as Normal
import qualified Text.Jasmine as JS
import Text.Blaze.Html.Renderer.Pretty (renderHtml)
import qualified Data.ByteString.Lazy.Char8 as BS
import qualified Data.ByteString.Lazy as L
@ -25,7 +23,7 @@ import SourceSyntax.Module
import Parse.Module (getModuleName)
import Initialize (buildFromSource, getSortedDependencies)
import Generate.JavaScript (jsModule)
import Generate.Html (createHtml, JSStyle(..), JSSource(..))
import Generate.Html (createHtml, JSSource(..))
import Paths_Elm
import SourceSyntax.PrettyPrint (pretty, variable)
@ -42,7 +40,6 @@ data Flags =
, print_program :: Bool
, scripts :: [FilePath]
, no_prelude :: Bool
, minify :: Bool
, cache_dir :: FilePath
, build_dir :: FilePath
}
@ -64,8 +61,6 @@ flags = Flags
&= help "Load JavaScript files in generated HTML. Files will be included in the given order."
, no_prelude = False
&= help "Do not import Prelude by default, used only when compiling standard libraries."
, minify = False
&= help "Minify generated JavaScript and HTML"
, cache_dir = "cache" &= typFile
&= help "Directory for files cached to make builds faster. Defaults to cache/ directory."
, build_dir = "build" &= typFile
@ -184,11 +179,11 @@ build flags rootFile = do
(extension, code) <- case only_js flags of
True -> do
putStr "Generating JavaScript ... "
return ("js", genJs js)
return ("js", js)
False -> do
putStr "Generating HTML ... "
rtsPath <- getRuntime flags
return ("html", BS.pack . genHtml $
return ("html", BS.pack . renderHtml $
createHtml rtsPath (takeBaseName rootFile) (sources js) moduleName "")
let targetFile = buildPath flags rootFile extension
@ -202,10 +197,7 @@ build flags rootFile = do
do src <- BS.readFile (elmo flags filePath)
return (BS.append src js)
genHtml = if minify flags then Normal.renderHtml else Pretty.renderHtml
genJs = if minify flags then JS.minify else id
sources js = map Link (scripts flags) ++
[ Source (if minify flags then Minified else Readable) js ]
sources js = map Link (scripts flags) ++ [ Source js ]
buildFiles :: Flags -> Int -> Interfaces -> String -> [FilePath] -> IO (String, Interfaces)

View file

@ -2,7 +2,6 @@
module Generate.Html
(generateHtml,
createHtml,
JSStyle (..),
JSSource (..)
) where
@ -11,25 +10,21 @@ import qualified Text.Blaze.Html5 as H
import Text.Blaze.Html5 ((!))
import qualified Text.Blaze.Html5.Attributes as A
import Text.Jasmine (minify)
import qualified Data.ByteString.Lazy.Char8 as BS
import Initialize (buildFromSource)
import Generate.JavaScript
import Generate.Noscript
data JSStyle = Minified | Readable
data JSSource = Link String | Source JSStyle BS.ByteString
data JSSource = Link String | Source BS.ByteString
makeScript :: JSSource -> H.Html
makeScript source =
case source of
Link src -> H.script ! A.type_ "text/javascript" ! A.src (H.toValue src) $ ""
Source style src ->
Source src ->
H.script ! A.type_ "text/javascript" $
preEscapedToMarkup $ BS.unpack $ case style of
Minified -> minify src
Readable -> src
preEscapedToMarkup $ BS.unpack src
-- |This function compiles Elm code into simple HTML.
--