2018-08-16 17:56:37 +00:00
|
|
|
import { registerHelper } from '@ember/test';
|
|
|
|
|
|
|
|
const invariant = (truthy, error) => {
|
|
|
|
if (!truthy) throw new Error(error);
|
|
|
|
};
|
|
|
|
|
2018-08-23 00:34:25 +00:00
|
|
|
export function getCodeMirrorInstance(container) {
|
|
|
|
return function(selector) {
|
|
|
|
const cmService = container.lookup('service:code-mirror');
|
2018-08-16 17:56:37 +00:00
|
|
|
|
|
|
|
const element = document.querySelector(selector);
|
|
|
|
invariant(element, `Selector ${selector} matched no elements`);
|
|
|
|
|
|
|
|
const cm = cmService.instanceFor(element.id);
|
|
|
|
invariant(cm, `No registered CodeMirror instance for ${selector}`);
|
|
|
|
|
|
|
|
return cm;
|
2018-08-23 00:34:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function registerCodeMirrorHelpers() {
|
|
|
|
registerHelper('getCodeMirrorInstance', function(app, selector) {
|
|
|
|
const helper = getCodeMirrorInstance(app.__container__);
|
|
|
|
return helper(selector);
|
2018-08-16 17:56:37 +00:00
|
|
|
});
|
|
|
|
}
|