|
320 | 320 | }
|
321 | 321 |
|
322 | 322 | /**
|
323 |
| - * |
| 323 | + * Fetches a gist from the [gist.github.com](https://gist.github.com/) and loads it into the code editor |
324 | 324 | * @param {Ace.EditSession} session (see [ace.Ace.Editor::getSession](https://ajaxorg.github.io/ace-api-docs/interfaces/ace.Ace.Editor.html#getSession))
|
325 | 325 | * @param {HTMLDivElement} result
|
326 | 326 | * @param {String} gist_id
|
|
358 | 358 | );
|
359 | 359 | }
|
360 | 360 |
|
| 361 | + /** |
| 362 | + * Fetches a code snippet from the [`ponylang/pony-tutorial`](https://github.com/ponylang/pony-tutorial) repository on GitHub |
| 363 | + * and loads it into the code editor |
| 364 | + * @param {Ace.EditSession} session (see [ace.Ace.Editor::getSession](https://ajaxorg.github.io/ace-api-docs/interfaces/ace.Ace.Editor.html#getSession)) |
| 365 | + * @param {HTMLDivElement} result |
| 366 | + * @param {String} gist_id |
| 367 | + * @param {bool} do_evaluate |
| 368 | + * @param {HTMLButtonElement} evaluateButton |
| 369 | + * @return {void} |
| 370 | + */ |
| 371 | + function fetchSnippet(session, result, snippet_file_name, do_evaluate, evaluateButton) { |
| 372 | + session.setValue("// Loading snippet: https://github.com/ponylang/pony-tutorial/blob/main/code-samples/" + snippet_file_name + " ..."); |
| 373 | + httpRequest("GET", "https://raw.githubusercontent.com/ponylang/pony-tutorial/main/code-samples/" + snippet_file_name, null, 200, |
| 374 | + function (response) { |
| 375 | + session.setValue(response); |
| 376 | + |
| 377 | + if (do_evaluate) { |
| 378 | + doEvaluate(); |
| 379 | + } |
| 380 | + }, |
| 381 | + function (status, response) { |
| 382 | + set_result(result, "<p class=error>Failed to fetch snippet" + |
| 383 | + "<p class=error-explanation>Are you connected to the Internet?"); |
| 384 | + } |
| 385 | + ); |
| 386 | + } |
| 387 | + |
361 | 388 | /**
|
362 | 389 | * Get URL query parameters as Object
|
363 | 390 | * @returns {URLSearchParams}
|
|
620 | 647 | // fetchGist() must defer evaluation until after the content has been loaded
|
621 | 648 | fetchGist(session, result, query.get("gist"), query.get("run") === "1", evaluateButton);
|
622 | 649 | query.set("run", 0);
|
| 650 | + } else if (query.has("snippet")) { |
| 651 | + // fetchSnippet() must defer evaluation until after the content has been loaded |
| 652 | + fetchSnippet(session, result, query.get("snippet"), query.get("run") === "1", evaluateButton); |
| 653 | + query.set("run", 0); |
623 | 654 | } else {
|
624 | 655 | var code = optionalLocalStorageGetItem("code");
|
625 | 656 | if (code !== null) {
|
|
0 commit comments