provide option sorter=[alpha|method]

This commit is contained in:
Chris Hatch
2014-07-27 21:18:18 +08:00
parent 6dc12f733e
commit 5d2bed7025
3 changed files with 15 additions and 9 deletions

View File

@@ -1,13 +1,18 @@
class MainView extends Backbone.View
initialize: (opts={}) ->
if opts.swaggerOptions.sortAlphabetically == true
pathSorter = (a,b) -> return a.path.localeCompare(b.path)
# sort apis
@model.apisArray.sort pathSorter
# sort operations
for route in @model.apisArray
route.operationsArray.sort pathSorter
sorters = {
'alpha' : (a,b) -> return a.path.localeCompare(b.path),
'method' : (a,b) -> return a.method.localeCompare(b.method),
}
initialize: (opts={}) ->
if opts.swaggerOptions.sorter
sorterName = opts.swaggerOptions.sorter
sorter = sorters[sorterName]
for route in @model.apisArray
route.operationsArray.sort sorter
if (sorterName == "alpha") # sort top level paths if alpha
@model.apisArray.sort sorter
render: ->
# Render the outer container for resources
$(@el).html(Handlebars.templates.main(@model))