// Generated by CoffeeScript 1.7.1 (function() { var $, App, Expression, Results, TestStrings, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; $ = jQuery; Expression = (function(_super) { __extends(Expression, _super); function Expression() { return Expression.__super__.constructor.apply(this, arguments); } Expression.prototype.elements = { 'input[name=expression]': 'regexp', 'input[name=option]': 'option' }; Expression.prototype.events = { 'keyup input': 'onKeyPress' }; Expression.prototype.onKeyPress = function(event) { var error; try { this.value = this.buildRegex(this.regexp.val(), this.option.val()); } catch (_error) { error = _error; } return this.trigger('update'); }; Expression.prototype.buildRegex = function(value, option) { return new RegExp(value, option); }; Expression.prototype.asUrlPart = function() { return encodeURIComponent(this.regexp.val() + "||||" + this.option.val()); }; return Expression; })(Spine.Controller); TestStrings = (function(_super) { __extends(TestStrings, _super); function TestStrings() { return TestStrings.__super__.constructor.apply(this, arguments); } TestStrings.prototype.elements = { 'textarea': 'input' }; TestStrings.prototype.events = { 'keyup textarea': 'onKeyPress' }; TestStrings.prototype.onKeyPress = function(event) { this.getValues(this.input.val()); return this.trigger('update'); }; TestStrings.prototype.getValues = function(val) { return this.values = val.split('\n'); }; TestStrings.prototype.asUrlPart = function() { return encodeURIComponent(JSON.stringify(this.values)); }; return TestStrings; })(Spine.Controller); Results = (function() { function Results(expression, test_strings) { this.expression = expression; this.test_strings = test_strings; this.compile = __bind(this.compile, this); this.expression.bind('update', this.compile); this.test_strings.bind('update', this.compile); } Results.prototype.compile = function() { var count, error, matches, value, _i, _len, _ref; $('ul#results').empty(); $('ul#groups').empty(); count = 1; if (this.expression.regexp.val() === '' && this.test_strings.input.val() === '') { this.showIntro(); return true; } else if (this.expression.regexp.val() === '' || this.test_strings.input.val() === '') { this.showError(); return true; } else if (!this.test_strings.values) { return true; } try { _ref = this.test_strings.values; for (_i = 0, _len = _ref.length; _i < _len; _i++) { value = _ref[_i]; matches = value.match(this.expression.value); this.matchResults(value, matches); this.matchGroups(value, matches, count); count += 1; } this.addShareLink(this.expression.asUrlPart(), this.test_strings.asUrlPart()); return this.showOutput(); } catch (_error) { error = _error; return this.showError(); } }; Results.prototype.addShareLink = function(expression_url, test_strings_url) { var url; url = window.location.protocol + "//" + window.location.host; url += "/#" + expression_url + encodeURIComponent("||||") + test_strings_url; return $("#share_link").attr("href", url); }; /* escape function from Peter Hoffman found at https://peter-hoffmann.com/2012/coffeescript-string-interpolation-with-html-escaping.html */ Results.prototype.escape = function(s) { return ('' + s).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g, '/'); }; Results.prototype.matchResults = function(value, matches) { var string; if (!matches) { return; } string = this.generateMatches(value, this.expression.value); return this.drawResult(string); }; Results.prototype.generateMatches = function(value, regex) { return this.escape(value.replace(regex, "~~scriptular_begin_match~~$&~~scriptular_end_match~~")).replace(/~~scriptular_begin_match~~/g, '').replace(/~~scriptular_end_match~~/g, ''); }; Results.prototype.drawResult = function(string) { return $('ul#results').append("