-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
452 lines (390 loc) · 16.7 KB
/
index.html
File metadata and controls
452 lines (390 loc) · 16.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
<!DOCTYPE html>
<html>
<head>
<title>Daimio Tests</title>
<script type="text/javascript" src="../daimio_composite.js"></script>
<link rel="stylesheet" href="../resources/css/styles.css" type="text/css" media="screen">
<link rel="stylesheet" href="../resources/codemirror/lib/codemirror.css">
<link rel="stylesheet" href="../resources/codemirror/addon/hint/show-hint.css">
<script type="text/javascript" charset="utf-8">
// load daimio file
function xhr_get(target, callback) {
var xhr = new XMLHttpRequest()
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
callback(xhr.responseText)
}
}
xhr.open('GET', target, true)
xhr.send(null)
}
xhr_get('daimio.dm', function(data) {
// these globals are kind of a hack...
lines = data.split(/\n/).reverse()
starttime = new Date().getTime()
win=0
lose=0
html=''
mode='text'
block_name=''
code_value=''
code_string=''
D.data_trampoline(lines, eat_line, D.string_concat, function() {}, done)
})
function eat_line(value, prior_starter) {
var whitespace='', wscount=0
, line = lines.pop()
/*
There's four modes:
- text, which just displays regular text based on whitespace and other factors
- code, which is a single line of code
- block, which is a big block of code
- assert, the value the code should process to
*/
// mode switcher
if(mode != 'block') {
if(/^\s*\{begin /.test(line)) {
code_string = ''
block_name = line.match(/^\s*\{begin (\w+)/)[1]
mode = 'block' // begin a block
}
else if(mode == 'code') {
mode = 'assert' // switch to assert
}
else if(/^\s*\{/.test(line)) {
code_string = line
mode = 'code' // begin a line of code
}
else if(mode == 'assert') {
mode = 'text' // switch back to text
}
}
// continue the block
if(mode == 'block') {
code_string += "\n" + line
// end the block
if(new RegExp("\{end " + block_name + '\}').test(line)) {
mode = 'code'
}
}
// sort out whitespace
whitespace = ''
wscount = line.search(/\S/)
if(wscount >= 1) {
whitespace = new Array( wscount + 1 ).join( ' ' )
// whitespace = line.slice(0, wscount !== -1).replace(/\s/, ' ')
}
// handle text
if(mode == 'text') {
html += '<p class="ws' + wscount + '">' + line + '</p>'
}
// handle code
if(mode == 'code') {
html += '<div class="panel panel-default">' // note: this gets closed later
html += '<div class="panel-body"><code><pre><span class="glyphicon glyphicon-arrow-left"></span>' + code_string.replace(/^\s+|\s+$/g, '') + '</pre></code></div>'
code_string = code_string.replace(/^\s+|\s+$/g, '')
code_value = D.execute_then_stringify(
D.ExecutionSpace.execute(
D.Parser.string_to_block_segment(code_string), null, prior_starter))
return code_value
}
// handle asserts
if(mode == 'assert') {
if(code_value === false) {
code_value = ''
}
if(typeof(code_value) != 'string') {
code_value = JSON.stringify(code_value) ? JSON.stringify(code_value) : ''
}
if(code_value.trim() === line.trim()) {
result = 'success'
win++
} else {
result = 'danger'
lose++
}
// TODO: convert line and code_value to escaped html
html += '<div class="assert panel-footer">'
if(result == 'success') {
html += '<small class="text-' + result + '">' + line + '</small>'
} else {
html += '<p><small class="text-expected">' + line + '</small></p>'
html += '<p><small class="actual text-danger">Actual: ' + code_value + '</small></p>'
}
html += '</div></div>' // note: closing div from above
}
return true
}
function done() {
var endtime = new Date().getTime()
stats = "<p>Completed " + (win + lose) + " tests in " + ((endtime - starttime) / 1000) + " seconds.</p>"
stats += '<div class="alert alert-success">Won ' + win + ' tests.</div>'
if(lose) stats += '<div class="alert alert-danger">Lost ' + lose + ' tests. (43 expected)</div>'
if(!lose) stats += '<p>You win!!!</p>'
document.getElementById('stats').innerHTML = stats
document.getElementById('tests').innerHTML = html
}
</script>
</head>
<body>
<!-- NAVBAR -->
<nav class="navbar navbar-fixed-top navbar-inverse" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Daimio</a>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#id_daimio_primer">Daimio Primer</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">In Depth <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#id_commands">Commands</a></li>
<li><a href="#id_lists">Lists</a></li>
<li><a href="#id_pipes">Pipes</a></li>
<li><a href="#id_variables">Variables</a></li>
<li><a href="#id_blocks">Blocks</a></li>
<li><a href="#id_scope">Scope</a></li>
<li><a href="#id_peek">Peek</a></li>
<li><a href="#id_poke">Poke</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Command Examples <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#id_list_examples">List</a></li>
<li><a href="#id_logic_examples">Logic</a></li>
<li><a href="#id_math_examples">Math</a></li>
<li><a href="#id_process_examples">Process</a></li>
<li><a href="#id_string_examples">String</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Appendices <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#id_app_numbers" class="">Numbers</a></li>
<li><a href="#id_app_edge" class="">Edge Cases</a></li>
<li><a href="#id_app_known" class="">Known Bugs</a></li>
<!-- <li><a href="#id_app_dec" class="">Decisions to be Made</a></li> -->
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Demos <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="demos/button_timer.html" class="">Simple Counter</a></li>
<li><a href="demos/automata/excitebikes.html" class="">Excitable Media</a></li>
<li><a href="demos/automata/sans-collatz.html" class="">Sans Collatz</a></li>
<li><a href="demos/todomvc.html" class="">TodoMVC</a></li>
<li><a href="demos/mandelbrot/canvas_ships_faster.html" class="">Mandelbrot</a></li>
<li><a href="demos/turtle/turtle_solo.html" class="">Lonely Turtle</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="https://github.com/dxnn/daimio">Download on Github</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
<div class="container">
<div class="row">
<div class="col-xs-12 col-md-6">
<div id="sidebar" data-spy="affix" class="hidden-print hidden-xs">
<!-- REPL -->
<div id="repl">
<div class="panel panel-default">
<div class="panel-body pre pre-scrollable" id="console">
<div id="history"></div>
</div>
<div class="panel-footer">
<textarea id="code" name="code" rows="1" placeholder="Try me out! Type a '{' up here to get started."></textarea>
</div>
</div>
</div>
<!-- HELP -->
<ul class="list-group" id="help">
<li class="list-group-item">
<div class="row">
<span class="col-md-7">
Click code snippets to copy into the REPL.
</span>
<span class="col-md-5">
<span class="pull-right">
<code class="docs-style"><pre><span class="glyphicon glyphicon-arrow-left"></span>{1 | add 2}</pre></code>
</span>
</span>
</div>
</li>
<li class="list-group-item">Use <em>Space</em> or <em>Enter</em> or double-click to activate autocompletion.</li>
<li class="list-group-item">Use <em>Esc</em> to cancel autocomplete, and to toggle its activation.</li>
<li class="list-group-item">Use <em>Up</em> and <em>Down</em> arrows to cycle through your history.</li>
<li class="list-group-item">History is saved between sessions.</li>
<li class="list-group-item">Start with a '{' and end with a '}' when writing Daimio commands.</li>
</div>
</div>
<div class="col-xs-12 col-md-6">
<!-- INTRO -->
<div id="intro">
<img src="../resources/images/daimio_logo.png" alt="" />
<h3>A system for building programmable applications.</h3>
<p class="lead">Web applications are rarely customizable—you can’t tailor interfaces, extend functionality, or publish your modifications. Daimio makes bottom-up change possible by expressing every action your application can perform in a dialect of a language, and making execution contexts that speak different subsets of that dialect accessible.</p>
<p>That means you can send raw code to the server. It means you can build extensions and share them. It means you can send code to other users for direct execution on their machines. <strong>And that means the server is merely one of potentially many trusted resources.</strong> Welcome to the world of programmable applications. Welcome to the world of universal computing. Welcome to Daimio.</p>
<div class="btn-group text-center">
<a href="https://groups.google.com/forum/#!forum/daimio" class="btn btn-success">Daimio Google Group</a>
<a href="https://github.com/dxnn/daimio" class="btn btn-info">Download on Github</a>
</div>
</div>
<!-- DOCUMENTATION -->
<div id="docs">
<p></p>
<div id="tests"></div>
<div id="stats"></div>
</div>
</div>
</div>
</div>
</div>
<script>
// NOTE: this has to be set before emmet is loaded
emmetKeymap = {
'Ctrl-E': 'expand_abbreviation',
'Shift-Ctrl-D': 'match_pair_outward',
}
</script>
<script src="../resources/codemirror/lib/codemirror.js"></script>
<script src="../resources/codemirror/mode/daimio/daimio.js"></script>
<script src="../resources/codemirror/addon/hint/show-hint.js"></script>
<script src="../resources/codemirror/addon/hint/daimio-hint.js"></script>
<script src="../resources/codemirror/addon/display/placeholder.js"></script>
<script src="../resources/codemirror/addon/emmet/emmet.js"></script>
<script>
var ge = document.getElementById.bind(document)
, results = ge('results')
, repl = CodeMirror.fromTextArea(ge('code'), {})
, ac_on = true
, background = 'transparent'
, console_el = ge('console')
, history_el = ge('history')
, history_list = JSON.parse(localStorage.getItem('repl-history')) || []
, history_buffer = ''
, history_cursor = 0
CodeMirror.commands.autocomplete = function(instance) {
CodeMirror.showHint(instance, CodeMirror.hint.daimio, {
extraKeys: {'Space': function(instance, hint) {hint.pick()}}
, completeSingle: false
, closeCharacters: /[\n|"]/
})
}
repl.setOption('lineNumbers', false)
repl.setOption('matchBrackets', true)
repl.setOption('extraKeys', {
"Esc": function(instance) {
ac_on = !ac_on
repl.display.wrapper.style.backgroundColor = ac_on ? background : 'pink' // display for a/c on/off
},
"Enter": function(instance) {
repl_display(instance.getLine(0))
instance.setLine(0, '')
history_cursor = 0
},
"Up": function(instance) {
if(!history_cursor)
history_buffer = instance.getValue()
if(!history_list.length)
return
// TODO: use history_buffer as a LHS filter to search through history
history_cursor += history_cursor < history_list.length - 1 ? 1 : 0
instance.setValue(history_list[history_cursor-1])
},
"Down": function(instance) {
if(!history_cursor)
return false // if we're already all the way down, don't change anything
history_cursor--
var prev = ''
if(!history_cursor) // we were at 1, so reset from our buffer
prev = history_buffer
else
prev = history_list[history_cursor-1]
instance.setValue(prev)
},
})
repl.display.wrapper.style.backgroundColor = background
repl.on("change", function(instance, change) {
if(ac_on && repl.getValue() && change.origin != 'setValue')
CodeMirror.commands.autocomplete(instance)
})
repl.on("beforeChange", function(instance, change) {
// NOTE: change.text stores an array of lines, so you *have* to join to remove pasted newlines
if(change.update && (/\n/.test(change.text) || change.text.length > 1)) {
var newtext = change.text.join("").replace(/\n/g, "") // THINK: when would this replace get triggered?
change.update(change.from, change.to, [newtext])
return true
}
// add space to changes caused by autocomplete
if(change.from.constructor != CodeMirror.Pos && !change.origin) {
change.update(change.from, change.to, [change.text[0] + " "])
return true
}
})
repl_display = function(code) {
D.run(code, false, false, function(value) {
// preprocess history: remove existing copies of this item
while(history_list.indexOf(code) != -1)
history_list.splice(history_list.indexOf(code), 1)
// add to history and store it
history_list.unshift(code)
localStorage.setItem('repl-history', JSON.stringify(history_list))
// display it
value = D.stringify(value)
history_el.innerHTML = history_el.innerHTML
+ '<div class="cmd"><p class="input">' + code + '</p>'
+ '<p class="result">' + (value || ' ') + '</p></div>'
// TODO: select the correct element
console_el.scrollTop = 1000000
})
}
// from http://stackoverflow.com/questions/13026285/codemirror-for-just-one-line-textfield
repl.setSize("100%", repl.defaultTextHeight() + 8) // 8 for font
document.addEventListener('click', function(ev) {
if(ev.target.nodeName != 'PRE' || ev.target.parentNode.nodeName != 'CODE')
return true
var code = ev.target.innerText.replace(/^\s+|\s+$/g, '')
repl.setValue(code)
repl.focus()
repl.setCursor(1, 1000)
})
// function tempTooltip(cm, content) {
// var where = cm.cursorCoords();
// var tip = makeTooltip(where.right + 1, where.bottom, content);
// function clear() {
// if (!tip.parentNode) return;
// cm.off("cursorActivity", clear);
// fadeOut(tip);
// }
// setTimeout(clear, 1700);
// cm.on("cursorActivity", clear);
// }
//
// function makeTooltip(x, y, content) {
// var node = elt("div", cls + "tooltip", content);
// node.style.left = x + "px";
// node.style.top = y + "px";
// document.body.appendChild(node);
// return node;
// }
// TODO: change these to repl.display.foo references
repl.on("change", function(instance, change) {
//document.querySelector(".CodeMirror-hscrollbar").style.display = 'none'
repl.getWrapperElement().children[1].style.display = 'none'
repl.getWrapperElement().children[2].style.display = 'none'
})
repl.getScrollerElement().style.overflow = 'hidden'
</script>
<script src="../resources/js/jquery.js"></script>
<script src="../resources/js/bootstrap.min.js"></script>
</body>
</html>