on master help sign in
Make sure that the user defined module name is used in generated HTML
commit97ab6199bd7a70f8f304b885f1cd447d1406c9c0 authorEvan Czaplicki <info@elm-lang.org> dateTue 6 Aug 2013, 13:41 (13 years ago) parent97a4628
2 files changed+11−27
compiler/Compiler.hs+6−6 compiler/Generate/Html.hs+5−21
compiler/Compiler.hs+6−6
@@ -171,7 +171,7 @@ build flags rootFile = do
171171 let noPrelude = no_prelude flags
172172 files <- if make flags then getSortedDependencies noPrelude rootFile else return [rootFile]
173173 let ifaces = if noPrelude then Map.empty else Prelude.interfaces
174− interfaces <- buildFiles flags (length files) ifaces files
174+ (moduleName, interfaces) <- buildFiles flags (length files) ifaces "" files
175175 js <- foldM appendToOutput "" files
176176 case only_js flags of
177177 True -> do
@@ -181,7 +181,7 @@ build flags rootFile = do
181181 False -> do
182182 putStr "Generating HTML ... "
183183 runtime <- getRuntime flags
184− let html = genHtml $ createHtml runtime (takeBaseName rootFile) (sources js) ""
184+ let html = genHtml $ createHtml runtime (takeBaseName rootFile) (sources js) moduleName ""
185185 writeFile (file flags rootFile "html") html
186186 putStrLn "Done"
187187
@@ -197,10 +197,10 @@ build flags rootFile = do
197197 [ Source (if minify flags then Minified else Readable) js ]
198198
199199
200−buildFiles :: Flags -> Int -> Interfaces -> [FilePath] -> IO Interfaces
201−buildFiles _ _ interfaces [] = return interfaces
202−buildFiles flags numModules interfaces (filePath:rest) = do
200+buildFiles :: Flags -> Int -> Interfaces -> String -> [FilePath] -> IO (String, Interfaces)
201+buildFiles _ _ interfaces moduleName [] = return (moduleName, interfaces)
202+buildFiles flags numModules interfaces _ (filePath:rest) = do
203203 interface <- buildFile flags (numModules - length rest) numModules interfaces filePath
204204 let moduleName = List.intercalate "." . splitDirectories $ dropExtensions filePath
205205 interfaces' = Map.insert moduleName interface interfaces
206− buildFiles flags numModules interfaces' rest
206+ buildFiles flags numModules interfaces' moduleName rest
compiler/Generate/Html.hs+5−21
@@ -40,27 +40,10 @@ generateHtml :: String -- ^ Location of elm-runtime.js as expected by the browse
4040 -> String -- ^ The page title
4141 -> String -- ^ The elm source code.
4242 -> H.Html
43−generateHtml libLoc title source = H.span "broken for now"
44−{--
45− case buildFromSource True source of
46− Right modul -> createHtml libLoc title [] "" title [modul]
47− Left err -> createHtml Readable libLoc title (Right $ showErr err)
48− (H.noscript "") "Main"
49−--}
50−{--
51−modulesToHtml :: FilePath -> String -> []
52−modulesToHtml libLoc title scripts nscrpt modules =
53− createHtml jsStyle libLoc title' js noscript altTitle
54− where
55− js = Right $ jss ++ concatMap jsModule modules
56− noscript = if nscrpt then extractNoscript $ last modules else ""
57− title' = if null title then altTitle else title
58− altTitle = intercalate "." names
59− where Module names _ _ _ = last modules
60−--}
43+generateHtml libLoc title source = error "function 'generateHtml' is unimplemented for now"
6144
62−createHtml :: FilePath -> String -> [JSSource] -> String -> H.Html
63−createHtml libLoc title scripts noscript =
45+createHtml :: FilePath -> String -> [JSSource] -> String -> String -> H.Html
46+createHtml libLoc title scripts moduleName noscript =
6447 H.docTypeHtml $ do
6548 H.head $ do
6649 H.meta ! A.charset "UTF-8"
@@ -68,5 +51,6 @@ createHtml libLoc title scripts noscript =
6851 makeScript (Link libLoc)
6952 mapM_ makeScript scripts
7053 H.body $ do
71− H.script ! A.type_ "text/javascript" $ preEscapedToMarkup ("Elm.fullscreen(Elm.Main)" :: String)
54+ H.script ! A.type_ "text/javascript" $
55+ preEscapedToMarkup ("Elm.fullscreen(Elm." ++ moduleName ++ ")")
7256 H.noscript $ preEscapedToMarkup noscript