Saving modules to files
This commit is contained in:
parent
ed103ed2cb
commit
d6466555df
3 changed files with 62 additions and 3 deletions
|
|
@ -12,9 +12,13 @@ textEditor = name \
|
|||
buffersKey = "textEditorBuffers";
|
||||
|
||||
# load from staging buffers if it exists there. if not, load from source
|
||||
source = getAt [buffersKey, name]
|
||||
| None \ getSource name
|
||||
| Some v \ v;
|
||||
# source = getAt [buffersKey, name]
|
||||
# | None \ getSource name
|
||||
# | Some v \ v;
|
||||
|
||||
source = getModuleSource name
|
||||
| Some s \ s
|
||||
| None \ getSource name;
|
||||
|
||||
lines = split "\n" source;
|
||||
|
||||
|
|
|
|||
|
|
@ -122,6 +122,12 @@ export const _rt = {
|
|||
if (!def) return "";
|
||||
return prettyPrint(def);
|
||||
},
|
||||
getModuleSource: (moduleName: string) => {
|
||||
const moduleDefs = [...definitions.values()]
|
||||
.filter(d => d.module === moduleName);
|
||||
if (moduleDefs.length === 0) return { _tag: 'None' };
|
||||
return { _tag: 'Some', _0: moduleDefs.map(d => prettyPrint(d)).join('\n\n') };
|
||||
},
|
||||
"saveImage!": () => {
|
||||
const saved: Record<string, string> = {};
|
||||
for (const [name, ast] of definitions) {
|
||||
|
|
@ -138,6 +144,22 @@ export const _rt = {
|
|||
URL.revokeObjectURL(url);
|
||||
return { _tag: 'Ok' };
|
||||
},
|
||||
"saveModule!": (moduleName: string) => {
|
||||
const moduleDefs = [...definitions.values()]
|
||||
.filter(d => d.module === moduleName);
|
||||
if (moduleDefs.length === 0) return { _tag: 'Err', _0: 'No module: ' + moduleName };
|
||||
|
||||
const content = '@' + moduleName + '\n\n' +
|
||||
moduleDefs.map(d => prettyPrint(d)).join('\n\n') + '\n\n@\n';
|
||||
|
||||
fetch('/api/save', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ filename: moduleName, content })
|
||||
});
|
||||
|
||||
return { _tag: 'Defined', _0: moduleName };
|
||||
},
|
||||
rebind: (name: string, pathOrValue: any, maybeValue?: any) => {
|
||||
if (maybeValue === undefined) {
|
||||
store[name] = pathOrValue;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue