// 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: 'Di presente è uscito dalle stampe la mia interpretatione dell\'obelisco egittiaco, già l\'anno a dietro ritrovato quì in Roma; Io che desidero continuare la servitù che professo V[ostra] Altezza, cerco quasivoglia occasione per essercitarla; perciò le ne\' lò mandato con il Latore presente un\'essemplare, acciò che nel medesimo tempo che lei partecipa delle mie fatiche io sia fatto degno della sua humanità, allaquale degli accersce ogni di più autorità nel commendarmi. e con quella river[ente] bacio le mani pregandole da Dio {ogni contento.}(This is written on the right side of the page.)\n\n[fig](This figure is added to showcase a feature of the DSL.)\n---\nDi V[ostra] Altezza Seren[issima].\nHumilissimo e divotissimo\nAthanasio Kircher [...]' }); window.editor = this.editor; this.editor.on('change', (function(_this) { return function() { return _this.compile(); }; })(this)); return this.compile(); }, render: function() { this.editor.refresh(); return _.defer((function(_this) { return function() { return _this.editor.setSize(); }; })(this)); }, 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.highlight_all(data.marks); this.model.set('data', data, { silent: true }); return this.model.trigger('change'); } catch (error) { e = error; this.status_bar.text("Line " + e.location.start.line + ": " + e.message); return this.status_bar.classed('error', true); } }, highlight_all: function(marks) { return marks.forEach((function(_this) { return function(d) { switch (d.type) { case 'gap': return _this.highlight(d.code_location, 'gap'); case 'figure': return _this.highlight(d.code_location, 'figure'); case 'comment': _this.highlight(d.content_code_location, 'comment'); _this.highlight(d.opener_code_location, 'comment_symbol'); return _this.highlight(d.closer_code_location, 'comment_symbol'); case 'author_addition': _this.highlight(d.content_code_location, 'author_addition'); _this.highlight(d.opener_code_location, 'author_addition_symbol'); return _this.highlight(d.closer_code_location, 'author_addition_symbol'); case 'editor_addition': _this.highlight(d.content_code_location, 'editor_addition'); _this.highlight(d.opener_code_location, 'editor_addition_symbol'); return _this.highlight(d.closer_code_location, 'editor_addition_symbol'); case 'break': return _this.highlight(d.code_location, 'break'); } }; })(this)); }, highlight: function(loc, classname) { return this.editor.markText({ line: loc.start.line - 1, ch: loc.start.column - 1 }, { line: loc.end.line - 1, ch: loc.end.column - 1 }, { className: classname }); } }); }).call(this);