Skip to content

Commit

Permalink
ui: Refactors the code-mirror linting/restrict legacy tokens to HCL (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
johncowen authored and John Cowen committed Nov 26, 2018
1 parent 7eda9b0 commit de847d1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 36 deletions.
2 changes: 1 addition & 1 deletion ui-v2/app/components/code-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
35 changes: 0 additions & 35 deletions ui-v2/app/initializers/ivy-codemirror.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
33 changes: 33 additions & 0 deletions ui-v2/app/services/code-mirror/linter.js
Original file line number Diff line number Diff line change
@@ -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;
},
});
12 changes: 12 additions & 0 deletions ui-v2/tests/unit/services/code-mirror/linter-test.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit de847d1

Please sign in to comment.