Provide option highlightSizeThreshold to allow conditional syntax highlighting based on response size

This commit is contained in:
John Bryson
2014-07-31 11:56:13 -04:00
parent c948b40d34
commit 28c7597138
4 changed files with 7 additions and 3 deletions

View File

@@ -33,7 +33,7 @@ class MainView extends Backbone.View
addResource: (resource) ->
# Render a resource and add it to resources li
resourceView = new ResourceView({model: resource, tagName: 'li', id: 'resource_' + resource.id, className: 'resource'})
resourceView = new ResourceView({model: resource, tagName: 'li', id: 'resource_' + resource.id, className: 'resource', swaggerOptions: @options.swaggerOptions})
$('#resources').append resourceView.render().el
clear: ->

View File

@@ -365,7 +365,10 @@ class OperationView extends Backbone.View
$(".response", $(@el)).slideDown()
$(".response_hider", $(@el)).show()
$(".response_throbber", $(@el)).hide()
hljs.highlightBlock($('.response_body', $(@el))[0])
response_body_el = $('.response_body', $(@el))[0]
# only highlight the response if response is less than threshold, default state is highlight response
opts = @options.swaggerOptions
if opts.highlightSizeThreshold && response.data.length > opts.highlightSizeThreshold then response_body_el else hljs.highlightBlock(response_body_el)
toggleOperationContent: ->
elem = $('#' + Docs.escapeResourceName(@model.parentId) + "_" + @model.nickname + "_content")

View File

@@ -27,7 +27,7 @@ class ResourceView extends Backbone.View
operation.number = @number
# Render an operation and add it to operations li
operationView = new OperationView({model: operation, tagName: 'li', className: 'endpoint'})
operationView = new OperationView({model: operation, tagName: 'li', className: 'endpoint', swaggerOptions: @options.swaggerOptions})
$('.endpoints', $(@el)).append operationView.render().el
@number++