From 976495c787232fabcd860c1e1786f1e213f2f998 Mon Sep 17 00:00:00 2001 From: Winston Date: Sun, 6 Apr 2014 18:03:15 +0800 Subject: Implement fuzzy matching for route search on routing error html page. --- .../middleware/templates/routes/_table.html.erb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erb b/actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erb index 323873ba4b..6ee48f95ea 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erb @@ -88,13 +88,15 @@ }); } - // takes an array of elements with a data-regexp attribute and + // Takes an array of elements with a data-regexp attribute and // passes their parent into the callback function - // if the regexp matches a given path - function eachElemsForPath(elems, path, func) { + // if the user input fuzzy matches a route or if the regexp matches a given path + function eachElemsForPath(elems, value, func) { + var path = sanitizePath(value); each(elems, function(e){ - var reg = e.getAttribute("data-regexp"); - if (path.match(RegExp(reg))) { + var route = e.getAttribute("data-route-path"), + regexp = e.getAttribute("data-regexp"); + if (route.match(RegExp(value)) || path.match(RegExp(regexp))) { func(e.parentNode.cloneNode(true)); } }) @@ -121,14 +123,14 @@ // On key press perform a search for matching paths pathElem.onkeyup = function(e){ - var path = sanitizePath(pathElem.value), - defaultText = 'Paths Matching (' + path + '):'; + var userInput = pathElem.value, + defaultText = 'Paths Matching (' + userInput +'):'; // Clear out results section selectedSection.innerHTML= defaultText; // Display matches if they exist - eachElemsForPath(regexpElems, path, function(e){ + eachElemsForPath(regexpElems, userInput, function(e){ selectedSection.appendChild(e); }); -- cgit v1.2.3