elm/compiler/Language/Elm.hs

51 lines
1.8 KiB
Haskell
Raw Normal View History

{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
{- | This module exports the functions necessary for compiling Elm code into the
2012-05-28 16:02:02 +00:00
respective HTML, JS and CSS code.
The type class @'ElmSource'@ requires an instance for all types that the Elm
compiler understands. The provided instances for String, Text and QuasiQuoted
Elm source code should be sufficient.
The documentation for the Elm language is available at
<http://elm-lang.org/Documentation.elm>, and many interactive examples are
available at <http://elm-lang.org/Examples.elm>
2012-05-30 20:24:33 +00:00
Example implementations using Yesod and Happstack are available
at <https://github.com/tazjin/Elm/tree/master/Examples>
2012-05-28 16:02:02 +00:00
-}
module Language.Elm (
compile, toHtml,
2012-10-03 06:47:46 +00:00
runtimeLocation
) where
2012-10-03 07:17:09 +00:00
import Data.Version (showVersion)
import CompileToJS
import ExtractNoscript
import GenerateHtml
import Initialize
import Text.Blaze.Html (Html)
import Language.Elm.Quasi
2012-10-03 06:47:46 +00:00
import Paths_Elm
2012-05-30 19:52:05 +00:00
import qualified Data.Text as TS
import qualified Data.Text.Lazy as TL
-- |This function compiles Elm code to three separate parts: HTML, CSS,
-- and JavaScript. The HTML is only the contents of the body, so the three
-- parts must be combined in a basic HTML skeleton.
compile :: String -> String
compile source = either showErr jsModule modul
where modul = buildFromSource source
-- |This function compiles Elm code into a full HTML page.
toHtml :: String -- ^ Location of elm-min.js as expected by the browser
-> String -- ^ The page title
-> String -- ^ The elm source code
-> Html
toHtml = generateHtml
-- |The absolute path to Elm's runtime system.
runtimeLocation :: IO FilePath
runtimeLocation = getDataFileName "elm-runtime.js"
2012-10-03 06:47:46 +00:00