Skip to content

Added Lamdera alternative implementation for HTML generation. #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: lamdera-next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion compiler/src/Generate/Html.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,50 @@ import qualified Lamdera.UiSourceMap

-- SANDWICH


-- @LAMDERA root :: FilePath parameter added.
sandwich :: FilePath -> Name.Name -> B.Builder -> B.Builder
sandwich root moduleName javascript =
Lamdera.alternativeImplementationWhen Lamdera.isLamdera_ (sandwich_ root moduleName javascript) $
let name = Name.toBuilder moduleName in
[r|<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>|] <> name <> [r|</title>
<style>body { padding: 0; margin: 0; }</style>
</head>

<body>

<pre id="elm"></pre>

<script>
try {
|] <> javascript <> [r|

var app = Elm.|] <> name <> [r|.init({ node: document.getElementById("elm") });
}
catch (e)
{
// display initialization errors (e.g. bad flags, infinite recursion)
var header = document.createElement("h1");
header.style.fontFamily = "monospace";
header.innerText = "Initialization Error";
var pre = document.getElementById("elm");
document.body.insertBefore(header, pre);
pre.innerText = e;
throw e;
}
</script>

</body>
</html>|]


-- @LAMDERA

sandwich_ :: FilePath -> Name.Name -> B.Builder -> B.Builder
sandwich_ root moduleName javascript =
let
name = Name.toBuilder moduleName

Expand Down