2021-03-17 10:46:21 +00:00
|
|
|
/* globals CodeMirror */
|
|
|
|
export function initialize(application) {
|
|
|
|
const appName = application.application.name;
|
|
|
|
const doc = application.lookup('service:-document');
|
|
|
|
// pick codemirror syntax highlighting paths out of index.html
|
2021-07-14 17:55:35 +00:00
|
|
|
const fs = new Map(
|
|
|
|
Object.entries(JSON.parse(doc.querySelector(`[data-${appName}-fs]`).textContent))
|
|
|
|
);
|
2021-03-17 10:46:21 +00:00
|
|
|
// configure syntax highlighting for CodeMirror
|
|
|
|
CodeMirror.modeURL = {
|
|
|
|
replace: function(n, mode) {
|
2021-07-14 17:55:35 +00:00
|
|
|
switch (mode.trim()) {
|
2021-03-17 10:46:21 +00:00
|
|
|
case 'javascript':
|
2021-07-14 17:55:35 +00:00
|
|
|
return fs.get(['codemirror', 'mode', 'javascript', 'javascript.js'].join('/'));
|
2021-03-17 10:46:21 +00:00
|
|
|
case 'ruby':
|
2021-07-14 17:55:35 +00:00
|
|
|
return fs.get(['codemirror', 'mode', 'ruby', 'ruby.js'].join('/'));
|
2021-03-17 10:46:21 +00:00
|
|
|
case 'yaml':
|
2021-07-14 17:55:35 +00:00
|
|
|
return fs.get(['codemirror', 'mode', 'yaml', 'yaml.js'].join('/'));
|
2021-03-17 10:46:21 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const IvyCodeMirrorComponent = application.resolveRegistration('component:ivy-codemirror');
|
|
|
|
// Make sure ivy-codemirror respects/maintains a `name=""` attribute
|
|
|
|
IvyCodeMirrorComponent.reopen({
|
|
|
|
attributeBindings: ['name'],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
initialize,
|
|
|
|
};
|