module Language.Elm (
ElmSource (..),
runtimeLocation
) where
import Data.Version (showVersion)
import CompileToJS
import ExtractNoscript
import GenerateHtml
import Initialize
import Text.Blaze.Html (Html)
import Language.Elm.Quasi
import Paths_Elm
import qualified Data.Text as TS
import qualified Data.Text.Lazy as TL
runtimeLocation :: IO FilePath
runtimeLocation =
getDataFileName ("elm-runtime-" ++ showVersion version ++ ".js")
class ElmSource a where
toParts :: a -> (Html, Html, String)
toHtml :: String
-> String
-> a
-> Html
instance ElmSource String where
toParts = toPartsHelper
toHtml = generateHtml
instance ElmSource Elm where
toParts = toPartsHelper . TL.unpack . renderElm
toHtml elmL title = generateHtml elmL title . TL.unpack . renderElm
instance ElmSource TS.Text where
toParts = toPartsHelper . TS.unpack
toHtml elmL title = generateHtml elmL title . TS.unpack
instance ElmSource TL.Text where
toParts = toPartsHelper . TL.unpack
toHtml elmL title = generateHtml elmL title . TL.unpack
instance ElmSource (t, t -> Elm) where
toParts (f, s) = toPartsHelper $ TL.unpack $ renderElm $ s f
toHtml elmL title (f, s) = generateHtml elmL title $ TL.unpack $ renderElm $ s f
instance ElmSource (t -> Elm) where
toParts s = toPartsHelper $ TL.unpack $ renderElm $ s undefined
toHtml l t s = generateHtml l t $ TL.unpack $ renderElm $ s undefined
toPartsHelper :: String -> (Html, Html, String)
toPartsHelper source = (html, css, js)
where modul = initialize source
js = either showErr jsModule modul
html = widgetBody $ either id (extractNoscript . snd) modul