// Generated by CoffeeScript 1.10.0 (function() { window.Editor = Backbone.D3View.extend({ namespace: null, tagName: 'div', events: { input: 'compile' }, initialize: function(conf) { var editor_div, wrapper; this.d3el.classed('Editor', true); editor_div = this.d3el.append('div').attr({ "class": 'editor_div' }).style({ position: 'relative' }); wrapper = editor_div.append('div').style({ position: 'absolute', height: '100%', width: '100%' }); this.status_bar = this.d3el.append('div').attr({ "class": 'status_bar' }); this.parser = PEG.buildParser(conf.grammar); this.editor = CodeMirror(wrapper.node(), { lineWrapping: true, value: 'This is a new version of <>(B), a language that can be used to select portions of text for <>(A).\n\n<>(1) are allowed>>(2), as well as <>(N). Moreover, <>(B) <11>(ONE) for specifying overlapping spans>2>(TWO). You can also mark a portion of text as <> without linking something to it.\n\nThe actual meaning of the <>(A) is left open. <>(B) merely links a body (the part between round brackets) with the section of the text surrounded by angle brackets.' }); this.editor.on('change', (function(_this) { return function() { return _this.compile(); }; })(this)); return this.compile(); }, render: function() { return this.editor.refresh(); }, compile: function() { var data, e, error; this.status_bar.text('All ok.'); this.status_bar.classed('error', false); this.editor.getAllMarks().forEach(function(mark) { return mark.clear(); }); try { data = this.parser.parse(this.editor.getValue()); this.spans_highlight(data.spans); return this.model.set('annotations', data.spans); } catch (error) { e = error; this.status_bar.text("Line " + e.location.start.line + ": " + e.message); return this.status_bar.classed('error', true); } }, spans_highlight: function(spans) { return spans.forEach((function(_this) { return function(s) { _this.editor.markText({ line: s.start_code_location.end.line - 1, ch: s.start_code_location.end.column - 1 }, { line: s.end_code_location.start.line - 1, ch: s.end_code_location.start.column - 1 }, { className: 'span' }); _this.editor.markText({ line: s.start_code_location.start.line - 1, ch: s.start_code_location.start.column - 1 }, { line: s.start_code_location.end.line - 1, ch: s.start_code_location.end.column - 1 }, { className: 'code' }); return _this.editor.markText({ line: s.end_code_location.start.line - 1, ch: s.end_code_location.start.column - 1 }, { line: s.end_code_location.end.line - 1, ch: s.end_code_location.end.column - 1 }, { className: 'code' }); }; })(this)); } }); }).call(this);