Skip to content

Added tryHalogen backend #88

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
<input type="radio" name="backend_inputs" value="behaviors" id="backend_behaviors">
<label for="backend_behaviors" title="Use the try-behaviors backend">Behaviors</label>
</li>
<li>
<input type="radio" name="backend_inputs" value="halogen" id="backend_halogen">
<label for="backend_halogen" title="Use the try-halogen backend">Halogen</label>
</li>
</ul>

<ul id="gists">
Expand Down
70 changes: 32 additions & 38 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ $(function() {
extra_body: '<canvas id="canvas" width="800" height="600"></canvas>',
bundleAndExecute: defaultBundleAndExecute
};
} else if (backend === "halogen") {
return {
backend: "halogen",
endpoint: "https://compile.purescript.org/halogen",
mainGist: "15536d7b4c66ac512b2c8dca98e0e3d3",
extra_styling: '',
extra_body: '',
bundleAndExecute: defaultBundleAndExecute
};
} else { // core
return {
backend: "core",
Expand Down Expand Up @@ -249,27 +258,6 @@ $(function() {
.empty()
.append($iframe);

var iframe = $iframe.get(0).contentWindow.document;
iframe.open();
iframe.write(
['<!DOCTYPE html>'
, '<html>'
, ' <head>'
, ' <meta content="text/html;charset=utf-8" http-equiv="Content-Type">'
, ' <meta content="utf-8" http-equiv="encoding">'
, ' <meta name="viewport" content="width=device-width, initial-scale=1.0">'
, ' <title>Try PureScript!</title>'
, ' <link rel="stylesheet" href="css/style.css">'
, backend.extra_styling
, ' </head>'
, ' <body>'
, backend.extra_body
, ' </body>'
, '</html>'
].join('\n')
);
iframe.close();

// Replace any require() statements with the PS['...'] form using a regex substitution.
var replaced = js.replace(/require\("[^"]*"\)/g, function(s) {

Expand All @@ -287,23 +275,29 @@ $(function() {

var scripts = [bundle, wrapped].join("\n");

var script = iframe.createElement('script');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test this on other backends? I seem to remember it was important.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked every single backend available in try.purescript.org just now... (twice) and everything is working... including Halogen

Copy link
Contributor Author

@sudhirvkumar sudhirvkumar Aug 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having said that I tested only in Chrome!

EDIT: I tested in Firefox 54 & Opera 47 (all in ubuntu) and it works

script.appendChild(iframe.createTextNode(scripts));

$('iframe').ready(function() {
var checkExists = setInterval(function() {
var body = iframe.getElementsByTagName('body')[0];
if (body) {
body.onclick = function() {
hideMenus();
};
body.appendChild(script);
clearInterval(checkExists);
}
}, 100);

});

var iframe = $iframe.get(0).contentWindow.document;
iframe.open();
iframe.write(
['<!DOCTYPE html>'
, '<html>'
, ' <head>'
, ' <meta content="text/html;charset=utf-8" http-equiv="Content-Type">'
, ' <meta content="utf-8" http-equiv="encoding">'
, ' <meta name="viewport" content="width=device-width, initial-scale=1.0">'
, ' <title>Try PureScript!</title>'
, ' <link rel="stylesheet" href="css/style.css">'
, backend.extra_styling
, ' </head>'
, ' <body>'
, backend.extra_body
, ' <script>'
, scripts
, ' </script>'
, ' </body>'
, '</html>'
].join('\n')
);
iframe.close();
};

var compile = function() {
Expand Down