summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Sotoudeh <matthewsot@outlook.com>2017-07-27 15:46:17 -0700
committerMatthew Sotoudeh <matthewsot@outlook.com>2017-07-27 15:46:17 -0700
commitc0e74f58fa89a6ba60ddefad1dace9df352f99dd (patch)
tree6143cf185d0b22379ef373310deceee77501579e
parentf4635dac4198758e163f07f37508a50def95a9d6 (diff)
Added hangman project
-rw-r--r--.gitignore2
-rw-r--r--content/scripts/editor.js36
-rw-r--r--content/scripts/frame.js2
-rw-r--r--content/scripts/projects/hangman.js23
-rw-r--r--content/styles/projects/hangman.css14
-rw-r--r--editor.html1
-rw-r--r--index.html7
-rw-r--r--package.json13
8 files changed, 79 insertions, 19 deletions
diff --git a/.gitignore b/.gitignore
index de15dca..346ace5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,6 @@
*.swp
+*.swo
+*.lock
# Logs
logs
diff --git a/content/scripts/editor.js b/content/scripts/editor.js
index 432ea31..792c21b 100644
--- a/content/scripts/editor.js
+++ b/content/scripts/editor.js
@@ -1,4 +1,5 @@
-window.lang = window.location.hash.split('#')[1];
+window.lang = window.location.hash.split('#')[1].split(',')[0];
+window.proj = window.location.hash.split('#')[1].split(',')[1];
var langDict = { "yaepl": "YAEPL", "javascript": "Javascript" };
document.getElementById("lang").textContent = langDict[window.lang];
@@ -46,6 +47,18 @@ function runYAEPL() {
interpretLine(0);
};
+window.sandbox = {
+ 'alert': window.alert,
+ 'write': function (a) { term.print(a); },
+ 'prompt': async function (a) {
+ var promptPromise = new Promise(function (resolve, reject) {
+ window.term.input(a, function (ret) {
+ resolve(ret);
+ });
+ });
+ return await promptPromise;
+ }
+};
const vm = require('vm');
function runJS() {
term.clear();
@@ -54,23 +67,13 @@ function runJS() {
scriptStr = wrapAwait(scriptStr);
const script = new vm.Script(scriptStr);
- var sandbox = {
- 'alert': window.alert,
- 'write': function (a) { term.print(a); },
- 'prompt': async function (a) {
- var promptPromise = new Promise(function (resolve, reject) {
- window.term.input(a, function (ret) {
- resolve(ret);
- });
- });
- return await promptPromise;
- }
- };
- const context = new vm.createContext(sandbox);
+ const context = new vm.createContext(window.sandbox);
script.runInContext(context);
};
+window.preRun = function () { };
function run() {
+ window.preRun();
switch (window.lang) {
case "yaepl":
runYAEPL();
@@ -90,3 +93,8 @@ editor.setOption("extraKeys", {
window.save();
}
});
+
+if (proj.length > 0) {
+ document.writeln("<link rel=\"stylesheet\" href=\"content/styles/projects/" + proj + ".css\" />");
+ document.writeln("<script src=\"content/scripts/projects/" + proj + ".js\"></script>");
+}
diff --git a/content/scripts/frame.js b/content/scripts/frame.js
index 7fd5190..b47f63c 100644
--- a/content/scripts/frame.js
+++ b/content/scripts/frame.js
@@ -1,6 +1,6 @@
var lis = document.querySelectorAll("nav > ul > li");
for (var l = 0; l < lis.length; l++) {
lis[l].onclick = function () {
- document.getElementById("view").src = "editor.html#" + this.getAttribute("lang");
+ document.getElementById("view").src = "editor.html#" + this.getAttribute("lang") + "," + this.getAttribute("proj");
};
}
diff --git a/content/scripts/projects/hangman.js b/content/scripts/projects/hangman.js
new file mode 100644
index 0000000..a577981
--- /dev/null
+++ b/content/scripts/projects/hangman.js
@@ -0,0 +1,23 @@
+function _hangman() {
+ var container = document.getElementById("proj");
+ container.innerHTML = "";
+
+ var ul = document.createElement("ul");
+ ul.id = "hangman-letters";
+ container.appendChild(ul);
+
+ window.preRun = function () {
+ ul.innerHTML = "";
+ };
+
+ window.sandbox["addBlank"] = function () {
+ var li = document.createElement("li");
+ li.innerHTML = " ";
+ ul.appendChild(li);
+ };
+
+ window.sandbox["fillBlank"] = function (index, letter) {
+ ul.children[index].textContent = letter;
+ };
+}
+_hangman();
diff --git a/content/styles/projects/hangman.css b/content/styles/projects/hangman.css
new file mode 100644
index 0000000..7710c56
--- /dev/null
+++ b/content/styles/projects/hangman.css
@@ -0,0 +1,14 @@
+#hangman-letters {
+ list-style-type: none;
+}
+ #hangman-letters li {
+ display: inline-block;
+ border: 1px solid black;
+ height: 35px;
+ width: 30px;
+ font-size: 30px;
+ vertical-align: middle;
+ }
+ #hangman-letters li + li {
+ margin-left: 5px;
+ }
diff --git a/editor.html b/editor.html
index c032bfa..3e6867e 100644
--- a/editor.html
+++ b/editor.html
@@ -8,6 +8,7 @@
</head>
<body>
<h1>Code Editor - <span id="lang"></span></h1>
+ <div id="proj"></div>
<main>
<textarea id="editor"></textarea>
<div id="terminal"></div>
diff --git a/index.html b/index.html
index 22906c9..f64ba3d 100644
--- a/index.html
+++ b/index.html
@@ -8,12 +8,15 @@
<body>
<nav>
<ul>
- <li lang="yaepl">
+ <li lang="yaepl" proj="">
YAEPL Editor
</li>
- <li lang="javascript">
+ <li lang="javascript" proj="">
Javascript Editor
</li>
+ <li lang="javascript" proj="hangman">
+ Hangman Project
+ </li>
</ul>
</nav>
<webview src="editor.html#yaepl" id="view" nodeintegration disablewebsecurity></webview>
diff --git a/package.json b/package.json
index 4655afe..eda4b4a 100644
--- a/package.json
+++ b/package.json
@@ -4,16 +4,25 @@
"description": "YAEPL/JS app for Develop '17.",
"main": "main.js",
"scripts": {
- "start": "electron ."
+ "start": "electron .",
+ "pack": "electron-builder --dir",
+ "dist": "electron-builder"
},
"repository": "https://github.com/matthewsot/yaepl-app",
"author": "Matthew Sotoudeh/Develop Academy",
"license": "CC0-1.0",
"devDependencies": {
- "electron": "~1.6.2"
+ "electron": "~1.6.2",
+ "electron-builder": "^19.6.3"
},
"dependencies": {
"escodegen": "^1.8.1",
"esprima": "^4.0.0"
+ },
+ "build": {
+ "appId": "your.id",
+ "mac": {
+ "category": "your.app.category.type"
+ }
}
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback