Skip to content

Commit e976069

Browse files
committed
Added example
1 parent 6fdd89a commit e976069

27 files changed

+1073
-39
lines changed

easycoder/easycoder-min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

easycoder/easycoder.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3504,7 +3504,9 @@ const EasyCoder = {
35043504
this.reportError({
35053505
message: `Line ${(lino >= 0) ? lino : ``}: ${message}`
35063506
}, this.program);
3507-
this.program.aborted = true;
3507+
if (this.program) {
3508+
this.program.aborted = true;
3509+
}
35083510
},
35093511
nonNumericValueError: function (lino) {
35103512
this.runtimeError(lino, `Non-numeric value`);

easycoder/easycoder.zip

-44.8 KB
Binary file not shown.

easycoder/plugins/browser.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,8 @@ const EasyCoder_Browser = {
19791979
const styleName = compiler.getValue();
19801980
let type = `setStyle`;
19811981
let symbolName = ``;
1982-
if (compiler.tokenIs(`of`)) {
1982+
token = compiler.getToken();
1983+
if (token === `of`) {
19831984
if (compiler.nextToken() === `body`) {
19841985
type = `setBodyStyle`;
19851986
} else if (compiler.isSymbol()) {
@@ -2007,6 +2008,20 @@ const EasyCoder_Browser = {
20072008
}
20082009
}
20092010
}
2011+
else if (token === `to`) {
2012+
const styleValue = compiler.getNextValue();
2013+
if (styleValue) {
2014+
compiler.addCommand({
2015+
domain: `browser`,
2016+
keyword: `set`,
2017+
lino,
2018+
type: `setHeadStyle`,
2019+
styleName,
2020+
styleValue
2021+
});
2022+
return true;
2023+
}
2024+
}
20102025
} else if (token === `default`) {
20112026
if (compiler.nextTokenIs(`of`)) {
20122027
if (compiler.nextIsSymbol()) {
@@ -2121,7 +2136,8 @@ const EasyCoder_Browser = {
21212136
targetId = program.getValue(symbol.value[symbol.index]);
21222137
target = document.getElementById(targetId);
21232138
}
2124-
program.getValue(command.value).split().forEach(function(item) {
2139+
program.getValue(command.value).split(` `).forEach(function(item) {
2140+
target.classList.remove(item);
21252141
target.classList.add(item);
21262142
});
21272143
break;
@@ -2233,6 +2249,23 @@ const EasyCoder_Browser = {
22332249
break;
22342250
}
22352251
break;
2252+
case `setHeadStyle`:
2253+
const headStyleName = program.getValue(command.styleName);
2254+
const headStyleValue = program.getValue(command.styleValue);
2255+
var style = document.createElement('style');
2256+
style.innerHTML = `${headStyleName} ${headStyleValue}`;
2257+
for (let i = 0; i < document.head.childNodes.length; i++) {
2258+
let node = document.head.childNodes[i];
2259+
if (node.tagName === `STYLE`) {
2260+
let data = node.innerHTML;
2261+
if (data.indexOf(`${headStyleName} `) === 0) {
2262+
document.head.removeChild(node);
2263+
break;
2264+
}
2265+
}
2266+
}
2267+
document.head.appendChild(style);
2268+
break;
22362269
case `setBodyStyle`:
22372270
const bodyStyleValue = program.getValue(command.styleValue);
22382271
switch (command.styleName.content) {

easycoder/plugins/json.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,14 @@ const EasyCoder_Json = {
319319
if (content.domain.endsWith(`/`)) {
320320
content.domain = content.domain.substr(0, content.domain.length - 1);
321321
}
322+
n = content.domain.indexOf(`/`);
323+
if (n > 0) {
324+
content.path = content.domain.substr(n + 1);
325+
content.domain = content.domain.substr(0, n);
326+
}
327+
else {
328+
content.path = ``;
329+
}
322330
targetRecord.value[targetRecord.index] = {
323331
type: `constant`,
324332
numeric: false,

easycoder/plugins/vfx.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ const EasyCoder_VFX = {
6767
const image = document.createElement(`img`);
6868
targetRecord.animation[targetRecord.index].image = image;
6969
container.appendChild(image);
70+
image.style[`display`] = `none`;
7071
image.style[`position`] = `absolute`;
72+
image.style[`max-width`] = `none`;
7173
return command.pc + 1;
7274
}
7375
},
@@ -122,7 +124,7 @@ const EasyCoder_VFX = {
122124
if (compiler.tokenIs(`the`)) {
123125
type = compiler.nextToken();
124126
}
125-
if ([`url`, `specification`, `spec`].includes(type)) {
127+
if ([`url`, `specification`, `spec`, `opacity`].includes(type)) {
126128
if (compiler.nextTokenIs(`of`)) {
127129
if (compiler.nextIsSymbol()) {
128130
const symbolRecord = compiler.getSymbolRecord();
@@ -148,15 +150,15 @@ const EasyCoder_VFX = {
148150
const command = program[program.pc];
149151
let targetRecord = program.getSymbolRecord(command.target);
150152
let container = targetRecord.element[targetRecord.index];
151-
let animation = targetRecord.animation[targetRecord.index];
153+
let animation;
152154
switch (command.type) {
153155
case `url`:
154156
let url = program.getValue(command.value);
155157
animation.image.setAttribute(`src`, url);
156158
break;
157159
case `specification`:
158160
case `spec`:
159-
let animation = targetRecord.animation[targetRecord.index];
161+
animation = targetRecord.animation[targetRecord.index];
160162
let spec = JSON.parse(program.getValue(command.value));
161163
animation.spec = spec;
162164
animation.step = spec.steps;
@@ -198,14 +200,19 @@ const EasyCoder_VFX = {
198200
animation.top = animation.topS;
199201
animation.width = animation.widthS;
200202
let image = animation.image;
201-
image.setAttribute(`src`, spec.url);
202203
image.style.left = `-${animation.left}px`;
203204
image.style.top = `-${animation.top}px`;
204205
image.style.width = `${animation.width}px`;
206+
image.setAttribute(`src`, spec.url);
205207
} else {
206208
program.runtimeError(command.lino, `Unknown animation type '${spec.type}'`);
207209
return 0;
208210
}
211+
case `opacity`:
212+
animation = targetRecord.animation[targetRecord.index];
213+
let image = animation.image;
214+
image.style.opacity = command.value;
215+
break;
209216
}
210217
return command.pc + 1;
211218
}
@@ -239,6 +246,7 @@ const EasyCoder_VFX = {
239246
animation.left = animation.leftS;
240247
animation.top = animation.topS;
241248
animation.width = animation.widthS;
249+
animation.image.style.display = `inline-block`;
242250
return command.pc + 1;
243251
}
244252
},

js/easycoder/Main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const EasyCoder = {
1313
this.reportError({
1414
message: `Line ${(lino >= 0) ? lino : ``}: ${message}`
1515
}, this.program);
16-
this.program.aborted = true;
16+
if (this.program) {
17+
this.program.aborted = true;
18+
}
1719
},
1820
nonNumericValueError: function (lino) {
1921
this.runtimeError(lino, `Non-numeric value`);

js/plugins/browser.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,8 @@ const EasyCoder_Browser = {
21362136
targetId = program.getValue(symbol.value[symbol.index]);
21372137
target = document.getElementById(targetId);
21382138
}
2139-
program.getValue(command.value).split().forEach(function(item) {
2139+
program.getValue(command.value).split(` `).forEach(function(item) {
2140+
target.classList.remove(item);
21402141
target.classList.add(item);
21412142
});
21422143
break;
@@ -2253,6 +2254,16 @@ const EasyCoder_Browser = {
22532254
const headStyleValue = program.getValue(command.styleValue);
22542255
var style = document.createElement('style');
22552256
style.innerHTML = `${headStyleName} ${headStyleValue}`;
2257+
for (let i = 0; i < document.head.childNodes.length; i++) {
2258+
let node = document.head.childNodes[i];
2259+
if (node.tagName === `STYLE`) {
2260+
let data = node.innerHTML;
2261+
if (data.indexOf(`${headStyleName} `) === 0) {
2262+
document.head.removeChild(node);
2263+
break;
2264+
}
2265+
}
2266+
}
22562267
document.head.appendChild(style);
22572268
break;
22582269
case `setBodyStyle`:

resources/codex/md/contact.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@ Here are some ~ec~ contact options:
44

55
1. Email to [info@easycoder.software](mailto:info@easycoder.software)
66

7-
1. Contact the author on [Fleep Messenger](mailto:graham.trott@fleep.io).
8-
97
1. Join our [Slack channel](https://join.slack.com/t/easycoder-software/shared_invite/enQtNTU5ODEwOTQ5NTU0LWQ1NWVkOTUxOGQ3NzJmNDI1ZGRlOTdmMjc1NDAxMGIwMTFjODg1ZDJhODEzMzUzODc2MDNlZWU4NmYyZWRlOWI).

resources/doc/core.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@
209209
"syntax": "filter {array} with {function}",
210210
"description": "This is a generalized filter function that will extract wanted values from a JSON array using a function supplied in the script. In the following description, refer to the example above.%0a%0aThe filter function is called once for every element in the array, each with the element. This is always called ~m:a~ and is supplied as a named argument in the array variable. The function does whatever is needed in the context and places the result value (true or false) into a ~m:v~ argument.%0a%0aSee also ~l:sort~ and ~l:append~.",
211211
"examples": "&nbsp;&nbsp;variable Items%0a&nbsp;&nbsp;variable A%0a&nbsp;&nbsp;variable V%0a %0a&nbsp;&nbsp;put empty into Items%0a&nbsp;&nbsp;append `fish` to Items%0a&nbsp;&nbsp;append `cabbage` to Items%0a&nbsp;&nbsp;append `sugar` to Items%0a&nbsp;&nbsp;append `beef` to Items%0a&nbsp;&nbsp;append `potatoes` to Items%0a&nbsp;&nbsp;filter Items with MyFilter%0a&nbsp;&nbsp;alert Items%0a&nbsp;&nbsp;exit%0a%0aMyFilter:%0a&nbsp;&nbsp;put arg `a` of Items into A%0a&nbsp;&nbsp;if the length of A is greater than 5%0a&nbsp;&nbsp;&nbsp;&nbsp;set V%0a&nbsp;&nbsp;&nbsp;&nbsp;else clear V%0a&nbsp;&nbsp;set arg `v` of Items to V%0a&nbsp;&nbsp;stop"
212+
},
213+
"CORE": {
214+
"syntax": "Core variables and commands",
215+
"description": "The ~m:core~ package contains all the basic stuff required of any programming language: variables, control structures, values and conditionals. With these it's possible to write and run simple command-line programs.\n\nThe other packages all provide features related to specific areas of programming, such as for browsers, storage, comms and special things like maps and text editors.",
216+
"examples": ""
212217
}
213218
},
214219
"values": {

0 commit comments

Comments
 (0)