github.com/outbrain/consul@v1.4.5/ui-v2/app/initializers/ivy-codemirror.js (about)

     1  import { inject as service } from '@ember/service';
     2  import { get } from '@ember/object';
     3  import lint from 'consul-ui/utils/editor/lint';
     4  const MODES = [
     5    {
     6      name: 'JSON',
     7      mime: 'application/json',
     8      mode: 'javascript',
     9      ext: ['json', 'map'],
    10      alias: ['json5'],
    11    },
    12    {
    13      name: 'HCL',
    14      mime: 'text/x-ruby',
    15      mode: 'ruby',
    16      ext: ['rb'],
    17      alias: ['jruby', 'macruby', 'rake', 'rb', 'rbx'],
    18    },
    19    { name: 'YAML', mime: 'text/x-yaml', mode: 'yaml', ext: ['yaml', 'yml'], alias: ['yml'] },
    20  ];
    21  export function initialize(application) {
    22    const IvyCodeMirrorComponent = application.resolveRegistration('component:ivy-codemirror');
    23    const IvyCodeMirrorService = application.resolveRegistration('service:code-mirror');
    24    // Make sure ivy-codemirror respects/maintains a `name=""` attribute
    25    IvyCodeMirrorComponent.reopen({
    26      attributeBindings: ['name'],
    27    });
    28    // Add some method to the code-mirror service so I don't have to have 2 services
    29    // for dealing with codemirror
    30    IvyCodeMirrorService.reopen({
    31      dom: service('dom'),
    32      modes: function() {
    33        return MODES;
    34      },
    35      lint: function() {
    36        return lint(...arguments);
    37      },
    38      getEditor: function(element) {
    39        return get(this, 'dom').element('textarea + div', element).CodeMirror;
    40      },
    41    });
    42  }
    43  
    44  export default {
    45    initialize,
    46  };