diff --git a/ui-v2/app/components/code-editor.js b/ui-v2/app/components/code-editor.js index 524fd597bd..fbf87a180d 100644 --- a/ui-v2/app/components/code-editor.js +++ b/ui-v2/app/components/code-editor.js @@ -11,7 +11,7 @@ const DEFAULTS = { }; export default Component.extend({ settings: service('settings'), - helper: service('code-mirror'), + helper: service('code-mirror/linter'), classNames: ['code-editor'], syntax: '', onchange: function(value) { diff --git a/ui-v2/app/initializers/ivy-codemirror.js b/ui-v2/app/initializers/ivy-codemirror.js index 16f12963ec..c4f3436057 100644 --- a/ui-v2/app/initializers/ivy-codemirror.js +++ b/ui-v2/app/initializers/ivy-codemirror.js @@ -1,44 +1,9 @@ -import { inject as service } from '@ember/service'; -import { get } from '@ember/object'; -import lint from 'consul-ui/utils/editor/lint'; -const MODES = [ - { - name: 'JSON', - mime: 'application/json', - mode: 'javascript', - ext: ['json', 'map'], - alias: ['json5'], - }, - { - name: 'HCL', - mime: 'text/x-ruby', - mode: 'ruby', - ext: ['rb'], - alias: ['jruby', 'macruby', 'rake', 'rb', 'rbx'], - }, - { name: 'YAML', mime: 'text/x-yaml', mode: 'yaml', ext: ['yaml', 'yml'], alias: ['yml'] }, -]; export function initialize(application) { const IvyCodeMirrorComponent = application.resolveRegistration('component:ivy-codemirror'); - const IvyCodeMirrorService = application.resolveRegistration('service:code-mirror'); // Make sure ivy-codemirror respects/maintains a `name=""` attribute IvyCodeMirrorComponent.reopen({ attributeBindings: ['name'], }); - // Add some method to the code-mirror service so I don't have to have 2 services - // for dealing with codemirror - IvyCodeMirrorService.reopen({ - dom: service('dom'), - modes: function() { - return MODES; - }, - lint: function() { - return lint(...arguments); - }, - getEditor: function(element) { - return get(this, 'dom').element('textarea + div', element).CodeMirror; - }, - }); } export default { diff --git a/ui-v2/app/services/code-mirror/linter.js b/ui-v2/app/services/code-mirror/linter.js new file mode 100644 index 0000000000..f607ce3026 --- /dev/null +++ b/ui-v2/app/services/code-mirror/linter.js @@ -0,0 +1,33 @@ +import Service, { inject as service } from '@ember/service'; +import { get } from '@ember/object'; +import lint from 'consul-ui/utils/editor/lint'; +const MODES = [ + { + name: 'JSON', + mime: 'application/json', + mode: 'javascript', + ext: ['json', 'map'], + alias: ['json5'], + }, + { + name: 'HCL', + mime: 'text/x-ruby', + mode: 'ruby', + ext: ['rb'], + alias: ['jruby', 'macruby', 'rake', 'rb', 'rbx'], + }, + { name: 'YAML', mime: 'text/x-yaml', mode: 'yaml', ext: ['yaml', 'yml'], alias: ['yml'] }, +]; + +export default Service.extend({ + dom: service('dom'), + modes: function() { + return MODES; + }, + lint: function() { + return lint(...arguments); + }, + getEditor: function(element) { + return get(this, 'dom').element('textarea + div', element).CodeMirror; + }, +}); diff --git a/ui-v2/tests/unit/services/code-mirror/linter-test.js b/ui-v2/tests/unit/services/code-mirror/linter-test.js new file mode 100644 index 0000000000..6283eb92e2 --- /dev/null +++ b/ui-v2/tests/unit/services/code-mirror/linter-test.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('service:code-mirror/linter', 'Unit | Service | code mirror/linter', { + // Specify the other units that are required for this test. + needs: ['service:dom'], +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let service = this.subject(); + assert.ok(service); +});