@@ -14,7 +14,7 @@
1414 at <https://github.com/tazjin/Elm/tree/master/Examples>
1515-}
1616module Language.Elm (
17− ElmSource (..),
17+ compile, toHtml,
1818 runtimeLocation
1919 ) where
2020
@@ -30,52 +30,21 @@ import Paths_Elm
3030import qualified Data.Text as TS
3131import qualified Data.Text.Lazy as TL
3232
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.
36+compile :: String -> String
37+compile source = either showErr jsModule modul
38+ where modul = buildFromSource source
39+
40+-- |This function compiles Elm code into a full HTML page.
41+toHtml :: String -- ^ Location of elm-min.js as expected by the browser
42+ -> String -- ^ The page title
43+ -> String -- ^ The elm source code
44+ -> Html
45+toHtml = generateHtml
46+
3347-- |The absolute path to Elm's runtime system.
3448runtimeLocation :: IO FilePath
3549runtimeLocation = getDataFileName "elm-runtime.js"
3650
37−class ElmSource a where
38− -- |This function compiles Elm code to three separate parts: HTML, CSS,
39− -- and JavaScript. The HTML is only the contents of the body, so the three
40− -- parts must be combined in a basic HTML skeleton.
41− compile :: a -> String
42−
43− -- |This function compiles Elm code into a full HTML page.
44− toHtml :: String -- ^ Location of elm-min.js as expected by the browser
45− -> String -- ^ The page title
46− -> a -- ^ The elm source code
47− -> Html
48−
49−instance ElmSource String where
50− compile = compileHelper
51− toHtml = generateHtml
52−
53−instance ElmSource Elm where
54− compile = compileHelper . TL.unpack . renderElm
55− toHtml elmL title = generateHtml elmL title . TL.unpack . renderElm
56−
57−-- |Strict text
58−instance ElmSource TS.Text where
59− compile = compileHelper . TS.unpack
60− toHtml elmL title = generateHtml elmL title . TS.unpack
61−
62−-- |Lazy text
63−instance ElmSource TL.Text where
64− compile = compileHelper . TL.unpack
65− toHtml elmL title = generateHtml elmL title . TL.unpack
66−
67−-- | (urlRenderFn, urlRenderFn -> Elm)
68−instance ElmSource (t, t -> Elm) where
69− compile (f, s) = compileHelper $ TL.unpack $ renderElm $ s f
70− toHtml elmL title (f, s) = generateHtml elmL title $ TL.unpack $ renderElm $ s f
71−
72−-- | to be used without URL interpolation
73−instance ElmSource (t -> Elm) where
74− compile s = compileHelper $ TL.unpack $ renderElm $ s undefined
75− toHtml l t s = generateHtml l t $ TL.unpack $ renderElm $ s undefined
76−
77−
78−-- build helper to avoid boilerplate repetition
79−compileHelper :: String -> String
80−compileHelper source = either showErr jsModule modul
81− where modul = buildFromSource source