2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
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 = {
|
2022-09-15 08:43:17 +00:00
|
|
|
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('/'));
|
2022-01-04 16:24:09 +00:00
|
|
|
case 'xml':
|
|
|
|
return fs.get(['codemirror', 'mode', 'xml', 'xml.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,
|
|
|
|
};
|