Skip to content

Commit

Permalink
performance swagger-api#1956 added highlightSizeThreshold option disa…
Browse files Browse the repository at this point in the history
…ble highlight when length more than highlightSizeThreshold
  • Loading branch information
bodnia committed Feb 22, 2016
1 parent 8a658a1 commit ed7c726
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 22 deletions.
5 changes: 5 additions & 0 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<script src='lib/backbone-min.js' type='text/javascript'></script>
<script src='swagger-ui.js' type='text/javascript'></script>
<script src='lib/highlight.9.1.0.pack.js' type='text/javascript'></script>
<script src='lib/highlight.9.1.0.pack_extended.js' type='text/javascript'></script>
<script src='lib/jsoneditor.min.js' type='text/javascript'></script>
<script src='lib/marked.js' type='text/javascript'></script>
<script src='lib/swagger-oauth.js' type='text/javascript'></script>
Expand All @@ -38,6 +39,10 @@
url = "http://petstore.swagger.io/v2/swagger.json";
}

hljs.configure({
highlightSizeThreshold: 5000
});

// Pre load translate...
if(window.SwaggerTranslator) {
window.SwaggerTranslator.translate();
Expand Down
20 changes: 6 additions & 14 deletions dist/swagger-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,27 +905,19 @@ this["Handlebars"]["templates"]["response_content_type"] = Handlebars.template({
return buffer + "</select>\n";
},"useData":true});
this["Handlebars"]["templates"]["signature"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var stack1, helper, helperMissing=helpers.helperMissing, functionType="function", escapeExpression=this.escapeExpression, buffer = " <div class=\"snippet_json\">\n <pre><code class=\"";
stack1 = ((helpers.ifCond || (depth0 && depth0.ifCond) || helperMissing).call(depth0, ((stack1 = (depth0 != null ? depth0.sampleJSON : depth0)) != null ? stack1.length : stack1), ">", 5000, {"name":"ifCond","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data}));
if (stack1 != null) { buffer += stack1; }
buffer += "\">"
var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = " <div class=\"snippet_json\">\n <pre><code>"
+ escapeExpression(((helper = (helper = helpers.sampleJSON || (depth0 != null ? depth0.sampleJSON : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"sampleJSON","hash":{},"data":data}) : helper)))
+ "</code></pre>\n ";
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isParam : depth0), {"name":"if","hash":{},"fn":this.program(4, data),"inverse":this.noop,"data":data});
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isParam : depth0), {"name":"if","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data});
if (stack1 != null) { buffer += stack1; }
return buffer + "\n </div>\n";
},"2":function(depth0,helpers,partials,data) {
return "nohighlight";
},"4":function(depth0,helpers,partials,data) {
return "<small class=\"notice\" data-sw-translate></small>";
},"6":function(depth0,helpers,partials,data) {
var stack1, helper, helperMissing=helpers.helperMissing, functionType="function", escapeExpression=this.escapeExpression, buffer = " <div class=\"snippet_xml\">\n <pre><code class=\"";
stack1 = ((helpers.ifCond || (depth0 && depth0.ifCond) || helperMissing).call(depth0, ((stack1 = (depth0 != null ? depth0.sampleXML : depth0)) != null ? stack1.length : stack1), ">", 5000, {"name":"ifCond","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data}));
if (stack1 != null) { buffer += stack1; }
buffer += "\">"
},"4":function(depth0,helpers,partials,data) {
var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = " <div class=\"snippet_xml\">\n <pre><code>"
+ escapeExpression(((helper = (helper = helpers.sampleXML || (depth0 != null ? depth0.sampleXML : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"sampleXML","hash":{},"data":data}) : helper)))
+ "</code></pre>\n ";
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isParam : depth0), {"name":"if","hash":{},"fn":this.program(4, data),"inverse":this.noop,"data":data});
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isParam : depth0), {"name":"if","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data});
if (stack1 != null) { buffer += stack1; }
return buffer + "\n </div>\n";
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
Expand All @@ -935,7 +927,7 @@ this["Handlebars"]["templates"]["signature"] = Handlebars.template({"1":function
buffer += "\n </div>\n\n <div class=\"snippet\">\n";
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.sampleJSON : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.noop,"data":data});
if (stack1 != null) { buffer += stack1; }
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.sampleXML : depth0), {"name":"if","hash":{},"fn":this.program(6, data),"inverse":this.noop,"data":data});
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.sampleXML : depth0), {"name":"if","hash":{},"fn":this.program(4, data),"inverse":this.noop,"data":data});
if (stack1 != null) { buffer += stack1; }
return buffer + " </div>\n</div>\n";
},"useData":true});
Expand Down
12 changes: 6 additions & 6 deletions dist/swagger-ui.min.js

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions lib/highlight.9.1.0.pack_extended.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

(function () {
var configure, highlightBlock;

configure = hljs.configure;
// "extending" hljs.configure method
hljs.configure = function _configure (options) {
var size = options.highlightSizeThreshold;

// added highlightSizeThreshold option to set maximum size
// of processed string. Set to null if not a number
hljs.highlightSizeThreshold = size === +size ? size : null;

configure.call(this, options);
};

highlightBlock = hljs.highlightBlock;

// "extending" hljs.highlightBlock method
hljs.highlightBlock = function _highlightBlock (el) {
var innerHTML = el.innerHTML;
var size = hljs.highlightSizeThreshold;

// check if highlightSizeThreshold is not set or element innerHTML
// is less than set option highlightSizeThreshold
if (size == null || size > innerHTML.length) {
// proceed with hljs.highlightBlock
highlightBlock.call(hljs, el);
}
};

})();

5 changes: 5 additions & 0 deletions src/main/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<script src='lib/backbone-min.js' type='text/javascript'></script>
<script src='swagger-ui.js' type='text/javascript'></script>
<script src='lib/highlight.9.1.0.pack.js' type='text/javascript'></script>
<script src='lib/highlight.9.1.0.pack_extended.js' type='text/javascript'></script>
<script src='lib/jsoneditor.min.js' type='text/javascript'></script>
<script src='lib/marked.js' type='text/javascript'></script>
<script src='lib/swagger-oauth.js' type='text/javascript'></script>
Expand All @@ -38,6 +39,10 @@
url = "http://petstore.swagger.io/v2/swagger.json";
}

hljs.configure({
highlightSizeThreshold: 5000
});

// Pre load translate...
if(window.SwaggerTranslator) {
window.SwaggerTranslator.translate();
Expand Down
4 changes: 2 additions & 2 deletions src/main/template/signature.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
<div class="snippet">
{{#if sampleJSON}}
<div class="snippet_json">
<pre><code class="{{#ifCond sampleJSON.length ">" 5000}}nohighlight{{/ifCond}}">{{sampleJSON}}</code></pre>
<pre><code>{{sampleJSON}}</code></pre>
{{#if isParam}}<small class="notice" data-sw-translate></small>{{/if}}
</div>
{{/if}}
{{#if sampleXML}}
<div class="snippet_xml">
<pre><code class="{{#ifCond sampleXML.length ">" 5000}}nohighlight{{/ifCond}}">{{sampleXML}}</code></pre>
<pre><code>{{sampleXML}}</code></pre>
{{#if isParam}}<small class="notice" data-sw-translate></small>{{/if}}
</div>
{{/if}}
Expand Down

0 comments on commit ed7c726

Please sign in to comment.