From c0c862ad90862d55224cd3aef47740ceebce6d70 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Mon, 22 Apr 2024 07:05:26 +0200
Subject: [PATCH 1/7] Fetch tutorial snippet from URL by file name
---
static/web.js | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/static/web.js b/static/web.js
index 1f59d4c..8964b86 100644
--- a/static/web.js
+++ b/static/web.js
@@ -292,6 +292,23 @@
);
}
+ function fetchSnippet(session, result, snippet_file_name, do_evaluate, evaluateButton) {
+ session.setValue("// Loading snippet: https://github.com/ponylang/pony-tutorial/blob/cmain/code-samples/actors-behaviors.pony" + snippet_file_name + " ...");
+ httpRequest("GET", "https://raw.githubusercontent.com/ponylang/pony-tutorial/main/code-samples/" + snippet_file_name, null, 200,
+ function (response) {
+ session.setValue(response);
+
+ if (do_evaluate) {
+ doEvaluate();
+ }
+ },
+ function (status, response) {
+ set_result(result, "
Failed to fetch snippet" +
+ "
Are you connected to the Internet?");
+ }
+ );
+ }
+
function getQueryParameters() {
var a = window.location.search.substr(1).split('&');
if (a === "") return {};
@@ -519,6 +536,10 @@
// fetchGist() must defer evaluation until after the content has been loaded
fetchGist(session, result, query.gist, query.run === "1", evaluateButton);
query.run = 0;
+ } else if ("snippet" in query) {
+ // fetchSnippet() must defer evaluation until after the content has been loaded
+ fetchSnippet(session, result, query.snippet, query.run === "1", evaluateButton);
+ query.run = 0;
} else {
var code = optionalLocalStorageGetItem("code");
if (code !== null) {
From a2d853c078197c07c133f9a3d891f02c411b72ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Tue, 30 Apr 2024 09:41:45 +0200
Subject: [PATCH 2/7] Remove non-dynamic path prefix
Co-authored-by: Matthias Wahl
---
static/web.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/static/web.js b/static/web.js
index 8964b86..da66c63 100644
--- a/static/web.js
+++ b/static/web.js
@@ -293,7 +293,7 @@
}
function fetchSnippet(session, result, snippet_file_name, do_evaluate, evaluateButton) {
- session.setValue("// Loading snippet: https://github.com/ponylang/pony-tutorial/blob/cmain/code-samples/actors-behaviors.pony" + snippet_file_name + " ...");
+ session.setValue("// Loading snippet: https://github.com/ponylang/pony-tutorial/blob/cmain/code-samples/" + snippet_file_name + " ...");
httpRequest("GET", "https://raw.githubusercontent.com/ponylang/pony-tutorial/main/code-samples/" + snippet_file_name, null, 200,
function (response) {
session.setValue(response);
From 1e2b24eeeb3ccbbe88240ac5caa54555da28cc22 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Tue, 30 Apr 2024 10:53:55 +0200
Subject: [PATCH 3/7] =?UTF-8?q?fix(code-loading):=20=E2=9C=8F=EF=B8=8F=20F?=
=?UTF-8?q?ix=20typo?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
static/web.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/static/web.js b/static/web.js
index da66c63..e777c79 100644
--- a/static/web.js
+++ b/static/web.js
@@ -293,7 +293,7 @@
}
function fetchSnippet(session, result, snippet_file_name, do_evaluate, evaluateButton) {
- session.setValue("// Loading snippet: https://github.com/ponylang/pony-tutorial/blob/cmain/code-samples/" + snippet_file_name + " ...");
+ session.setValue("// Loading snippet: https://github.com/ponylang/pony-tutorial/blob/main/code-samples/" + snippet_file_name + " ...");
httpRequest("GET", "https://raw.githubusercontent.com/ponylang/pony-tutorial/main/code-samples/" + snippet_file_name, null, 200,
function (response) {
session.setValue(response);
From fca68538119c495aba5e5fa3eb2b10e92bb0d1bd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 22 May 2024 18:20:31 +0200
Subject: [PATCH 4/7] refactor(code-loading): Respect branch if passed via URL
---
static/web.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/static/web.js b/static/web.js
index e777c79..5678bfa 100644
--- a/static/web.js
+++ b/static/web.js
@@ -294,7 +294,7 @@
function fetchSnippet(session, result, snippet_file_name, do_evaluate, evaluateButton) {
session.setValue("// Loading snippet: https://github.com/ponylang/pony-tutorial/blob/main/code-samples/" + snippet_file_name + " ...");
- httpRequest("GET", "https://raw.githubusercontent.com/ponylang/pony-tutorial/main/code-samples/" + snippet_file_name, null, 200,
+ httpRequest("GET", "https://raw.githubusercontent.com/ponylang/pony-tutorial/" + (query.get("branch") ?? "main") + "/code-samples/" + snippet_file_name, null, 200,
function (response) {
session.setValue(response);
From fabbd5eaa6ac42a9eec4d8c9e6e4b33d81675467 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 22 May 2024 18:24:51 +0200
Subject: [PATCH 5/7] Make ready for #222
---
static/web.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/static/web.js b/static/web.js
index 5678bfa..fdc2a84 100644
--- a/static/web.js
+++ b/static/web.js
@@ -536,9 +536,9 @@
// fetchGist() must defer evaluation until after the content has been loaded
fetchGist(session, result, query.gist, query.run === "1", evaluateButton);
query.run = 0;
- } else if ("snippet" in query) {
+ } else if (query.has("snippet")) {
// fetchSnippet() must defer evaluation until after the content has been loaded
- fetchSnippet(session, result, query.snippet, query.run === "1", evaluateButton);
+ fetchSnippet(session, result, query.get("snippet"), query.get("run") === "1", evaluateButton);
query.run = 0;
} else {
var code = optionalLocalStorageGetItem("code");
From 45734bf2f9665fa3cc8b91c993b401b56779a707 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Sat, 25 May 2024 13:37:00 +0200
Subject: [PATCH 6/7] Add JSDoc block comment to fetchSnippet()
---
static/web.js | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/static/web.js b/static/web.js
index 783a7d6..ccd3bc2 100644
--- a/static/web.js
+++ b/static/web.js
@@ -320,7 +320,7 @@
}
/**
- *
+ * Fetches a gist from the [gist.github.com](https://gist.github.com/) and loads it into the code editor
* @param {Ace.EditSession} session (see [ace.Ace.Editor::getSession](https://ajaxorg.github.io/ace-api-docs/interfaces/ace.Ace.Editor.html#getSession))
* @param {HTMLDivElement} result
* @param {String} gist_id
@@ -358,6 +358,16 @@
);
}
+ /**
+ * Fetches a code snippet from the [`ponylang/pony-tutorial`](https://github.com/ponylang/pony-tutorial) repository on GitHub
+ * and loads it into the code editor
+ * @param {Ace.EditSession} session (see [ace.Ace.Editor::getSession](https://ajaxorg.github.io/ace-api-docs/interfaces/ace.Ace.Editor.html#getSession))
+ * @param {HTMLDivElement} result
+ * @param {String} gist_id
+ * @param {bool} do_evaluate
+ * @param {HTMLButtonElement} evaluateButton
+ * @return {void}
+ */
function fetchSnippet(session, result, snippet_file_name, do_evaluate, evaluateButton) {
session.setValue("// Loading snippet: https://github.com/ponylang/pony-tutorial/blob/main/code-samples/" + snippet_file_name + " ...");
httpRequest("GET", "https://raw.githubusercontent.com/ponylang/pony-tutorial/" + (query.get("branch") ?? "main") + "/code-samples/" + snippet_file_name, null, 200,
From f47d3c7f69816b13c335c456107c37379753c693 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Tue, 28 May 2024 20:21:26 +0200
Subject: [PATCH 7/7] Do not use `branch` query param for fetching code
snippets from ponylang/pony-tutorial
since it was meant to be used by ponylang/ponyc
Co-authored-by: Joe Eli McIlvain
---
static/web.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/static/web.js b/static/web.js
index ccd3bc2..ec28e27 100644
--- a/static/web.js
+++ b/static/web.js
@@ -370,7 +370,7 @@
*/
function fetchSnippet(session, result, snippet_file_name, do_evaluate, evaluateButton) {
session.setValue("// Loading snippet: https://github.com/ponylang/pony-tutorial/blob/main/code-samples/" + snippet_file_name + " ...");
- httpRequest("GET", "https://raw.githubusercontent.com/ponylang/pony-tutorial/" + (query.get("branch") ?? "main") + "/code-samples/" + snippet_file_name, null, 200,
+ httpRequest("GET", "https://raw.githubusercontent.com/ponylang/pony-tutorial/main/code-samples/" + snippet_file_name, null, 200,
function (response) {
session.setValue(response);