@@ -2,14 +2,16 @@
22{- | This module exports the functions necessary for compiling Elm code into the
33 respective HTML, JS and CSS code.
44
5− The type class @'ElmSource'@ requires an instance for all types that the Elm compiler
6− understands. The provided instances for String, Text and QuasiQuoted Elm source code
7− should be sufficient.
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.
88
9− The documentation for the Elm language is available at <http://elm-lang.org/Documentation.elm>,
10− and many interactive examples are available at <http://elm-lang.org/Examples.elm>
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>
1112
12− Example implementations using Yesod and Happstack are available at <https://github.com/tazjin/Elm/tree/master/Examples>
13+ Example implementations using Yesod and Happstack are available
14+ at <https://github.com/tazjin/Elm/tree/master/Examples>
1315-}
1416module Language.Elm (
1517 ElmSource (..),
@@ -37,7 +39,7 @@ class ElmSource a where
3739 -- |This function compiles Elm code to three separate parts: HTML, CSS,
3840 -- and JavaScript. The HTML is only the contents of the body, so the three
3941 -- parts must be combined in a basic HTML skeleton.
40− toParts :: a -> (Html, Html, String)
42+ compile :: a -> String
4143
4244 -- |This function compiles Elm code into a full HTML page.
4345 toHtml :: String -- ^ Location of elm-min.js as expected by the browser
@@ -46,37 +48,35 @@ class ElmSource a where
4648 -> Html
4749
4850instance ElmSource String where
49− toParts = toPartsHelper
51+ compile = compileHelper
5052 toHtml = generateHtml
5153
5254instance ElmSource Elm where
53− toParts = toPartsHelper . TL.unpack . renderElm
55+ compile = compileHelper . TL.unpack . renderElm
5456 toHtml elmL title = generateHtml elmL title . TL.unpack . renderElm
5557
5658-- |Strict text
5759instance ElmSource TS.Text where
58− toParts = toPartsHelper . TS.unpack
60+ compile = compileHelper . TS.unpack
5961 toHtml elmL title = generateHtml elmL title . TS.unpack
6062
6163-- |Lazy text
6264instance ElmSource TL.Text where
63− toParts = toPartsHelper . TL.unpack
65+ compile = compileHelper . TL.unpack
6466 toHtml elmL title = generateHtml elmL title . TL.unpack
6567
6668-- | (urlRenderFn, urlRenderFn -> Elm)
6769instance ElmSource (t, t -> Elm) where
68− toParts (f, s) = toPartsHelper $ TL.unpack $ renderElm $ s f
70+ compile (f, s) = compileHelper $ TL.unpack $ renderElm $ s f
6971 toHtml elmL title (f, s) = generateHtml elmL title $ TL.unpack $ renderElm $ s f
7072
7173-- | to be used without URL interpolation
7274instance ElmSource (t -> Elm) where
73− toParts s = toPartsHelper $ TL.unpack $ renderElm $ s undefined
75+ compile s = compileHelper $ TL.unpack $ renderElm $ s undefined
7476 toHtml l t s = generateHtml l t $ TL.unpack $ renderElm $ s undefined
7577
7678
7779-- build helper to avoid boilerplate repetition
78−toPartsHelper :: String -> (Html, Html, String)
79−toPartsHelper source = (html, css, js)
80+compileHelper :: String -> String
81+compileHelper source = either showErr jsModule modul
8082 where modul = buildFromSource source
81− js = either showErr jsModule modul
82− html = widgetBody $ either id extractNoscript modul