2012-05-29 18:25:43 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2013-12-15 07:29:39 +00:00
|
|
|
module Generate.Html (generate, JSSource(..)) where
|
2012-05-29 18:25:43 +00:00
|
|
|
|
|
|
|
import Text.Blaze (preEscapedToMarkup)
|
|
|
|
import qualified Text.Blaze.Html5 as H
|
|
|
|
import Text.Blaze.Html5 ((!))
|
|
|
|
import qualified Text.Blaze.Html5.Attributes as A
|
2012-09-11 09:53:45 +00:00
|
|
|
import qualified Data.ByteString.Lazy.Char8 as BS
|
|
|
|
|
2013-09-28 19:36:02 +00:00
|
|
|
data JSSource = Link String | Source BS.ByteString
|
2012-09-11 09:53:45 +00:00
|
|
|
|
2013-06-05 07:44:04 +00:00
|
|
|
makeScript :: JSSource -> H.Html
|
|
|
|
makeScript source =
|
|
|
|
case source of
|
|
|
|
Link src -> H.script ! A.type_ "text/javascript" ! A.src (H.toValue src) $ ""
|
2013-09-28 19:36:02 +00:00
|
|
|
Source src ->
|
2013-06-05 07:44:04 +00:00
|
|
|
H.script ! A.type_ "text/javascript" $
|
2013-09-28 19:36:02 +00:00
|
|
|
preEscapedToMarkup $ BS.unpack src
|
2012-06-12 10:42:00 +00:00
|
|
|
|
2013-12-15 07:29:39 +00:00
|
|
|
generate :: FilePath -> String -> [JSSource] -> String -> String -> H.Html
|
|
|
|
generate libLoc title scripts moduleName noscript =
|
2012-05-29 18:25:43 +00:00
|
|
|
H.docTypeHtml $ do
|
|
|
|
H.head $ do
|
|
|
|
H.meta ! A.charset "UTF-8"
|
|
|
|
H.title . H.toHtml $ title
|
2013-06-05 07:44:04 +00:00
|
|
|
makeScript (Link libLoc)
|
|
|
|
mapM_ makeScript scripts
|
2013-04-05 16:56:21 +00:00
|
|
|
H.body $ do
|
2013-08-06 20:41:17 +00:00
|
|
|
H.script ! A.type_ "text/javascript" $
|
|
|
|
preEscapedToMarkup ("Elm.fullscreen(Elm." ++ moduleName ++ ")")
|
2013-03-11 01:52:16 +00:00
|
|
|
H.noscript $ preEscapedToMarkup noscript
|