4f6674f16f
This commit adds a bit of string wrangling to avoid the keys in our javascript source file also being transformed. Additionally, whilst looking at this we decided that Maps are a better dictionary than javascript objects, so we moved to use those here also (but this doesn't affect the issue)
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
/* 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
|
|
const fs = new Map(
|
|
Object.entries(JSON.parse(doc.querySelector(`[data-${appName}-fs]`).textContent))
|
|
);
|
|
// configure syntax highlighting for CodeMirror
|
|
CodeMirror.modeURL = {
|
|
replace: function(n, mode) {
|
|
switch (mode.trim()) {
|
|
case 'javascript':
|
|
return fs.get(['codemirror', 'mode', 'javascript', 'javascript.js'].join('/'));
|
|
case 'ruby':
|
|
return fs.get(['codemirror', 'mode', 'ruby', 'ruby.js'].join('/'));
|
|
case 'yaml':
|
|
return fs.get(['codemirror', 'mode', 'yaml', 'yaml.js'].join('/'));
|
|
}
|
|
},
|
|
};
|
|
|
|
const IvyCodeMirrorComponent = application.resolveRegistration('component:ivy-codemirror');
|
|
// Make sure ivy-codemirror respects/maintains a `name=""` attribute
|
|
IvyCodeMirrorComponent.reopen({
|
|
attributeBindings: ['name'],
|
|
});
|
|
}
|
|
|
|
export default {
|
|
initialize,
|
|
};
|