Skip to content

Commit 88903cf

Browse files
authored
PureScript rewrite (#90)
* PureScript rewrite, first steps * Move setup code to HTML file * Tidy up use of console global * Port defaultBundleAndExecute * Port bundleAndExecuteThermite * More * hideMenus and changeViewMode * setupSession * Logging changes * Logging again * publishNewGist * Remove exportedFunctions * cacheCurrentCode * tryRestoreCachedCode * Implement getQueryString and setQueryString * Encapsulate the editor * setupEditorWith * Encapsulate iframe * execute * Refactor code for the compile API * compile function * Refactoring: reduce usage of EffFnX * Break up modules * Refactor some code into CPS * Travis * Document dependencies * Document all dependencies, fix #40 * Use do notation * Use triple quotes * Refactoring the API calls * Misc refactoring
1 parent 7b317b7 commit 88903cf

21 files changed

+8977
-461
lines changed

.gitignore

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
.cabal-sandbox/
2-
cabal.sandbox.config
3-
dist/
1+
/bower_components/
2+
/node_modules/
3+
/.pulp-cache/
4+
/output/
5+
/generated-docs/
6+
/.psc-package/
7+
/.psc*
8+
/.purs*
9+
/.psa*

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: node_js
2+
dist: trusty
3+
sudo: required
4+
node_js: 6
5+
install:
6+
- npm install -g bower
7+
- npm install
8+
- bower install --production
9+
script:
10+
- npm run -s build

DEPENDENCIES

Lines changed: 2365 additions & 0 deletions
Large diffs are not rendered by default.

bower.json

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"name": "try-purescript",
3+
"ignore": [
4+
"**/.*",
5+
"node_modules",
6+
"bower_components",
7+
"output"
8+
],
9+
"dependencies": {
10+
"purescript-console": "^3.0.0",
11+
"purescript-foreign-generic": "^5.0.0",
12+
"purescript-jquery": "^4.2.1",
13+
"purescript-js-timers": "^3.0.0",
14+
"purescript-parallel": "^3.2.0",
15+
"purescript-prelude": "^3.1.0",
16+
"purescript-random": "^3.0.0"
17+
},
18+
"devDependencies": {
19+
"ace": "^1.2.8",
20+
"jquery": "^3.2.1",
21+
"underscore": "^1.8.3",
22+
"react": "^15.6.1",
23+
"mathbox": "^0.0.5",
24+
"purescript-thermite": "^4.1.1",
25+
"purescript-behaviors": "^5.2.0",
26+
"purescript-slides": "^0.5.0",
27+
"purescript-flare": "^3.2.0",
28+
"purescript-arrays": "^4.1.2",
29+
"purescript-bifunctors": "^3.0.0",
30+
"purescript-console": "^3.0.0",
31+
"purescript-const": "^3.0.0",
32+
"purescript-contravariant": "^3.1.0",
33+
"purescript-control": "^3.3.0",
34+
"purescript-distributive": "^3.0.0",
35+
"purescript-eff": "^3.1.0",
36+
"purescript-either": "^3.1.0",
37+
"purescript-enums": "^3.2.1",
38+
"purescript-exceptions": "^3.1.0",
39+
"purescript-exists": "^3.0.0",
40+
"purescript-foldable-traversable": "^3.6.0",
41+
"purescript-foreign": "^4.0.1",
42+
"purescript-free": "^4.1.0",
43+
"purescript-functions": "^3.0.0",
44+
"purescript-functors": "^2.2.0",
45+
"purescript-generics": "^4.0.0",
46+
"purescript-generics-rep": "^5.2.0",
47+
"purescript-globals": "^3.0.0",
48+
"purescript-graphs": "^3.0.0",
49+
"purescript-identity": "^3.1.0",
50+
"purescript-inject": "^4.0.0",
51+
"purescript-integers": "^3.1.0",
52+
"purescript-lazy": "^3.0.0",
53+
"purescript-maps": "^3.5.2",
54+
"purescript-math": "^2.1.0",
55+
"purescript-maybe": "^3.0.0",
56+
"purescript-monoid": "^3.1.0",
57+
"purescript-prelude": "^3.1.0",
58+
"purescript-profunctor": "^3.2.0",
59+
"purescript-proxy": "^2.1.0",
60+
"purescript-quickcheck": "^4.4.0",
61+
"purescript-random": "^3.0.0",
62+
"purescript-refs": "^3.0.0",
63+
"purescript-semirings": "^4.0.0",
64+
"purescript-sets": "^3.0.0",
65+
"purescript-st": "^3.0.0",
66+
"purescript-strings": "^3.3.1",
67+
"purescript-tailrec": "^3.3.0",
68+
"purescript-transformers": "^3.4.0",
69+
"purescript-tuples": "^4.1.0",
70+
"purescript-typelevel-prelude": "^2.4.0",
71+
"purescript-unfoldable": "^3.0.0",
72+
"purescript-validation": "^3.1.0"
73+
}
74+
}

dependencies.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
echo Try PureScript uses the following dependencies.
2+
echo Their licenses are reproduced here:
3+
4+
for dir in bower_components/*
5+
do
6+
echo
7+
basename $dir
8+
echo
9+
cat $dir/LICENSE* || (echo 'No license file found. bower.json says:' && cat $dir/bower.json | jq '.license')
10+
done

index.html

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,104 @@
114114

115115
<div id="column2">
116116
</div>
117-
118-
<script type="text/javascript" src="js/index.js"></script>
119117
</div>
120118
</div>
121119
</div>
120+
121+
<script type="text/javascript">
122+
$.ajaxSetup({
123+
dataType: 'text'
124+
});
125+
126+
var editor, cleanupActions = [];
127+
128+
editor = ace.edit('code');
129+
130+
editor.renderer.setShowGutter(true);
131+
editor.setFontSize(13);
132+
editor.setShowPrintMargin(false);
133+
134+
var session = editor.getSession();
135+
136+
session.setMode('ace/mode/haskell');
137+
session.setOptions({
138+
tabSize: 2,
139+
useSoftTabs: true
140+
});
141+
142+
function setEditorContent(value) {
143+
session.setValue(value);
144+
}
145+
146+
function onEditorChanged(callback, millis) {
147+
session.on('change', _.debounce(function() {
148+
callback(session.getValue());
149+
}, millis));
150+
}
151+
152+
function cleanUpMarkers() {
153+
for (var i = 0; i < cleanupActions.length; i++) {
154+
cleanupActions[i]();
155+
}
156+
157+
cleanupActions = [];
158+
}
159+
160+
function addErrorMarker(startLine, startColumn, endLine, endColumn) {
161+
if (startLine === endLine && endColumn <= startColumn) {
162+
// Make sure the range is at least one character wide.
163+
if (startColumn > 0) {
164+
startColumn = endColumn - 1;
165+
} else {
166+
endColumn = startColumn + 1;
167+
}
168+
}
169+
170+
// Add an error marker
171+
var range = new(ace.require("ace/range").Range)
172+
(startLine - 1, startColumn - 1, endLine - 1, endColumn - 1);
173+
174+
var marker = editor.session.addMarker(range, "error", "text", true);
175+
176+
editor.session.addGutterDecoration(startLine - 1, "gutter-error");
177+
178+
cleanupActions.push((function(marker, line) {
179+
return function() {
180+
editor.session.removeMarker(marker);
181+
editor.session.removeGutterDecoration(line, "gutter-error");
182+
};
183+
})(marker, startLine - 1));
184+
}
185+
186+
function setupIFrame($ctr, html, js, onReady) {
187+
var $iframe = $('<iframe id="output-iframe">');
188+
189+
$ctr
190+
.empty()
191+
.append($iframe);
192+
193+
var iframe = $iframe.get(0).contentWindow.document;
194+
iframe.open();
195+
iframe.write(html);
196+
iframe.close();
197+
198+
var script = iframe.createElement('script');
199+
script.appendChild(iframe.createTextNode(js));
200+
201+
$iframe.ready(function() {
202+
var checkExists = setInterval(function() {
203+
var body = iframe.getElementsByTagName('body')[0];
204+
if (body) {
205+
onReady($(body));
206+
body.appendChild(script);
207+
clearInterval(checkExists);
208+
}
209+
}, 100);
210+
});
211+
212+
return $iframe;
213+
}
214+
</script>
215+
<script type="text/javascript" src="js/index.js"></script>
122216
</body>
123217
</html>

0 commit comments

Comments
 (0)