provide option sorter=[alpha|method]
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user