mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 11:35:40 +01:00
Add support for file protocol
This commit is contained in:
parent
a4e18e4226
commit
0b41054ac2
3 changed files with 211 additions and 37 deletions
17
gulpfile.js
17
gulpfile.js
|
|
@ -389,7 +389,22 @@ gulp.task('website', ['clean-website', 'playground-samples'], function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('simpleserver', function(cb) {
|
gulp.task('generate-test-samples', function() {
|
||||||
|
var sampleNames = fs.readdirSync(path.join(__dirname, 'test/samples'));
|
||||||
|
var samples = sampleNames.map(function(sampleName) {
|
||||||
|
var samplePath = path.join(__dirname, 'test/samples', sampleName);
|
||||||
|
var sampleContent = fs.readFileSync(samplePath).toString();
|
||||||
|
return {
|
||||||
|
name: sampleName,
|
||||||
|
content: sampleContent
|
||||||
|
};
|
||||||
|
});
|
||||||
|
var prefix = '//This is a generated file via gulp generate-test-samples\ndefine([], function() { return';
|
||||||
|
var suffix = '; });'
|
||||||
|
fs.writeFileSync(path.join(__dirname, 'test/samples-all.js'), prefix + JSON.stringify(samples, null, '\t') + suffix );
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('simpleserver', ['generate-test-samples'], function(cb) {
|
||||||
httpServer.createServer({ root: '../', cache: 5 }).listen(8080);
|
httpServer.createServer({ root: '../', cache: 5 }).listen(8080);
|
||||||
httpServer.createServer({ root: '../', cache: 5 }).listen(8088);
|
httpServer.createServer({ root: '../', cache: 5 }).listen(8088);
|
||||||
console.log('LISTENING on 8080 and 8088');
|
console.log('LISTENING on 8080 and 8088');
|
||||||
|
|
|
||||||
187
test/samples-all.js
Normal file
187
test/samples-all.js
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -1,6 +1,11 @@
|
||||||
/// <reference path="../node_modules/monaco-editor-core/monaco.d.ts" />
|
/// <reference path="../node_modules/monaco-editor-core/monaco.d.ts" />
|
||||||
|
|
||||||
define([], function() {
|
define(['./samples-all'], function(ALL_SAMPLES) {
|
||||||
|
|
||||||
|
var XHR_SAMPLES = {};
|
||||||
|
ALL_SAMPLES.forEach(function(sample) {
|
||||||
|
XHR_SAMPLES[sample.name] = sample.content;
|
||||||
|
});
|
||||||
|
|
||||||
var samples = [];
|
var samples = [];
|
||||||
|
|
||||||
|
|
@ -12,9 +17,7 @@ define([], function() {
|
||||||
name: 'sample - ' + modeId,
|
name: 'sample - ' + modeId,
|
||||||
mimeType: modeId,
|
mimeType: modeId,
|
||||||
loadText: function() {
|
loadText: function() {
|
||||||
return xhr('samples/sample.' + modeId + '.txt').then(function(xhrResponse) {
|
return monaco.Promise.as(XHR_SAMPLES['sample.' + modeId + '.txt']);
|
||||||
return xhrResponse.responseText;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -25,9 +28,7 @@ define([], function() {
|
||||||
name: name,
|
name: name,
|
||||||
mimeType: mimeType,
|
mimeType: mimeType,
|
||||||
loadText: function() {
|
loadText: function() {
|
||||||
return xhr('samples/' + modelUrl).then(function(xhrResponse) {
|
return monaco.Promise.as(XHR_SAMPLES[modelUrl]);
|
||||||
return textModifier(xhrResponse.responseText);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -239,33 +240,4 @@ define([], function() {
|
||||||
addXHRSample('Z___f12___css','run-editor-sample-f12-css.txt','text/css');
|
addXHRSample('Z___f12___css','run-editor-sample-f12-css.txt','text/css');
|
||||||
|
|
||||||
return samples;
|
return samples;
|
||||||
|
|
||||||
function xhr(url) {
|
|
||||||
var req = null;
|
|
||||||
return new monaco.Promise(function(c,e,p) {
|
|
||||||
req = new XMLHttpRequest();
|
|
||||||
req.onreadystatechange = function () {
|
|
||||||
if (req._canceled) { return; }
|
|
||||||
|
|
||||||
if (req.readyState === 4) {
|
|
||||||
if ((req.status >= 200 && req.status < 300) || req.status === 1223) {
|
|
||||||
c(req);
|
|
||||||
} else {
|
|
||||||
e(req);
|
|
||||||
}
|
|
||||||
req.onreadystatechange = function () { };
|
|
||||||
} else {
|
|
||||||
p(req);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
req.open("GET", url, true );
|
|
||||||
req.responseType = "";
|
|
||||||
|
|
||||||
req.send(null);
|
|
||||||
}, function () {
|
|
||||||
req._canceled = true;
|
|
||||||
req.abort();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue