Created
December 18, 2015 23:58
-
-
Save matthewconstantine/fd026fbe8c3b395e40f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Github PR File sorter. Customize the last line as needed. By default it sorts by fileDepth then fileName. | |
var path = function(el) { | |
return $(el).find('.user-select-contain').attr('title').replace(/.* → /,''); | |
} | |
var directory = function(el) { | |
return path(el).replace(/.* /,'').replace(/[^\/]*$/,''); | |
} | |
var fileName = function(el) { | |
return path(el).replace(/^.*[\/]_?/, ''); // remove path and preceding _ from file names | |
} | |
var fileDepth = function(el) { | |
return path(el).split('/').length | |
} | |
var _singleSorter = function(fn) {return function(a,b) {return fn(a) === fn(b) ? 0 : fn(a) > fn(b) ? 1 : -1;} } | |
var sorter = function() { | |
var sorters = [].slice.call(arguments); | |
return function(a,b) { | |
var result = 0, i = 0; | |
while (result === 0 && i < sorters.length) { result = _singleSorter(sorters[i])(a,b); i +=1 } | |
return result | |
} | |
} | |
// takes a sorter function and returns it in order of matches in regexes | |
var custom = function(fn, regexes) { | |
return function(value) { | |
return regexes.map(function(re) {return re.test(fn(value))}).indexOf(true) | |
} | |
} | |
// Sort by path depth, then by | |
$('#files .file').sort(sorter( | |
fileDepth, | |
custom(directory, [/routes/,/controllers/,/views/,/templates/,/styles/]), | |
fileName | |
)).appendTo('#files'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment