Skip to content

Commit bf53a36

Browse files
committed
index files setting JSON object; added rosetta db
1 parent b41563b commit bf53a36

File tree

8 files changed

+59
-46
lines changed

8 files changed

+59
-46
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

Controller.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,17 @@ Controller.prototype = {
161161
},
162162

163163
// Also called from index file 0index.js
164-
addIndex: function (sDir, input) { // optional sDir
165-
var sInput, aIndex, i;
166-
167-
sInput = input.trim();
168-
aIndex = JSON.parse(sInput);
169-
for (i = 0; i < aIndex.length; i += 1) {
170-
aIndex[i].dir = sDir;
171-
this.model.setExample(aIndex[i]);
164+
addIndex: function (_sDir, input) { // optional sDir
165+
var sValue, aItem, i;
166+
167+
for (sValue in input) {
168+
if (input.hasOwnProperty(sValue)) {
169+
aItem = input[sValue]
170+
for (i = 0; i < aItem.length; i += 1) {
171+
//aItem[i].dir = sDir;
172+
this.model.setExample(aItem[i]);
173+
}
174+
}
172175
}
173176
},
174177

cpcbasic.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ cpcBasic = {
4444
},
4545

4646
addIndex: function (sDir, input) {
47-
if (typeof input !== "string") {
48-
input = this.fnHereDoc(input);
47+
var tmp;
48+
if (typeof input === "function") {
49+
tmp = JSON.parse(this.fnHereDoc(input).trim());
50+
input = {};
51+
input[sDir] = tmp;
4952
}
5053
return cpcBasic.controller.addIndex(sDir, input);
5154
},

cpcconfig.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"use strict";
44

55
var cpcconfig = { // eslint-disable-line no-unused-vars
6-
databaseDirs: "examples,https://benchmarko.github.io/CPCBasicApps/apps,storage",
7-
//databaseDirs: "examples,../CPCBasicApps/apps,storage", // use this, if CPCBasicApps is available locally
8-
//databaseDirs: "https://benchmarko.github.io/CPCBasic/examples,https://benchmarko.github.io/CPCBasicApps/apps,storage", // all remote
6+
databaseDirs: "examples,https://benchmarko.github.io/CPCBasicApps/apps,https://benchmarko.github.io/CPCBasicApps/rosetta,storage",
7+
//databaseDirs: "examples,../CPCBasicApps/apps,../CPCBasicApps/rosetta,storage", // use this, if CPCBasicApps is available locally
8+
//databaseDirs: "https://benchmarko.github.io/CPCBasic/examples,https://benchmarko.github.io/CPCBasicApps/apps,https://benchmarko.github.io/CPCBasicApps/rosetta,storage", // all remote
99

1010
redirectExamples: {
1111
"examples/art": {

examples/0index.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33

44
"use strict";
55

6-
cpcBasic.addIndex("./examples", function () { /*
7-
[
8-
{
9-
"key": "1st",
10-
"title": "First Program (empty)"
11-
},
12-
{
13-
"key": "cpcbasic",
14-
"title": "CPC Basic"
15-
},
16-
{
17-
"key": "test/testpage",
18-
"title": "Test Page"
19-
},
20-
{
21-
"key": "test/testpage.dat",
22-
"title": "Test data for Test Page",
23-
"meta": "D"
24-
}
25-
]
26-
*/ });
6+
cpcBasic.addIndex("./examples", {
7+
"examples": [
8+
{
9+
"key": "1st",
10+
"title": "First Program (empty)"
11+
},
12+
{
13+
"key": "cpcbasic",
14+
"title": "CPC Basic"
15+
},
16+
{
17+
"key": "test/testpage",
18+
"title": "Test Page"
19+
},
20+
{
21+
"key": "test/testpage.dat",
22+
"title": "Test data for Test Page",
23+
"meta": "D"
24+
}
25+
]
26+
});

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<link rel="stylesheet" href="cpcbasic.css" />
7-
<title id="title">CPC Basic v0.10.16</title>
7+
<title id="title">CPC Basic v0.10.17</title>
88
</head>
99

1010
<body id="pageBody">

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cpcbasic",
3-
"version": "0.10.16",
3+
"version": "0.10.17",
44
"description": "# CPCBasic - Run CPC BASIC in a Browser",
55
"main": "cpcbasic.js",
66
"directories": {

test/testParseExamples.qunit.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,17 @@ cpcBasic = {
155155
return aDatabaseNames;
156156
},
157157

158-
addIndex2: function (sDir, input) { // optional sDir
159-
var sInput, aIndex, i;
160-
161-
sInput = input.trim();
162-
aIndex = JSON.parse(sInput);
163-
for (i = 0; i < aIndex.length; i += 1) {
164-
aIndex[i].dir = sDir;
165-
this.model.setExample(aIndex[i]);
158+
addIndex2: function (_sDir, input) { // optional sDir
159+
var sValue, aItem, i;
160+
161+
for (sValue in input) {
162+
if (input.hasOwnProperty(sValue)) {
163+
aItem = input[sValue]
164+
for (i = 0; i < aItem.length; i += 1) {
165+
//aItem[i].dir = sDir;
166+
this.model.setExample(aItem[i]);
167+
}
168+
}
166169
}
167170
},
168171

@@ -191,8 +194,11 @@ cpcBasic = {
191194
},
192195

193196
addIndex: function (sDir, input) {
194-
if (typeof input !== "string") {
195-
input = this.fnHereDoc(input);
197+
var tmp;
198+
if (typeof input === "function") {
199+
tmp = JSON.parse(this.fnHereDoc(input).trim());
200+
input = {};
201+
input[sDir] = tmp;
196202
}
197203
return this.addIndex2(sDir, input);
198204
},

0 commit comments

Comments
 (0)