on 294fdfd help sign in
50 lines 1.8 kB history raw
1{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
2{- | This module exports the functions necessary for compiling Elm code into the
3 respective HTML, JS and CSS code.
5 The type class @'ElmSource'@ requires an instance for all types that the Elm
6 compiler understands. The provided instances for String, Text and QuasiQuoted
7 Elm source code should be sufficient.
9 The documentation for the Elm language is available at
10 <http://elm-lang.org/Documentation.elm>, and many interactive examples are
11 available at <http://elm-lang.org/Examples.elm>
13 Example implementations using Yesod and Happstack are available
14 at <https://github.com/tazjin/Elm/tree/master/Examples>
15-}
16module Language.Elm (
17 compile, toHtml,
18 runtimeLocation
19 ) where
21import Data.Version (showVersion)
22import CompileToJS
23import ExtractNoscript
24import GenerateHtml
25import Initialize
26import Text.Blaze.Html (Html)
27import Language.Elm.Quasi
28import Paths_Elm
30import qualified Data.Text as TS
31import qualified Data.Text.Lazy as TL
33-- |This function compiles Elm code to three separate parts: HTML, CSS,
34-- and JavaScript. The HTML is only the contents of the body, so the three
35-- parts must be combined in a basic HTML skeleton.
36compile :: String -> String
37compile source = either showErr jsModule modul
38 where modul = buildFromSource source
40-- |This function compiles Elm code into a full HTML page.
41toHtml :: String -- ^ Location of elm-min.js as expected by the browser
42 -> String -- ^ The page title
43 -> String -- ^ The elm source code
44 -> Html
45toHtml = generateHtml
47-- |The absolute path to Elm's runtime system.
48runtimeLocation :: IO FilePath
49runtimeLocation = getDataFileName "elm-runtime.js"