diff --git a/lib/apidoc.js b/lib/apidoc.js index 7bd54e7d..7544d1c1 100644 --- a/lib/apidoc.js +++ b/lib/apidoc.js @@ -291,7 +291,7 @@ function createOutputFiles(blocks, packageInfos) { app.log.debug('write js file: ' + options.dest + 'api_data.js'); if( ! options.simulate) - fs.writeFileSync(options.dest + './api_data.js', 'define({ api: ' + apiData + ' });'); + fs.writeFileSync(options.dest + './api_data.js', 'define({ "api": ' + apiData + ' });'); // Write api_project app.log.debug('write json file: ' + options.dest + 'api_project.json'); diff --git a/template/handlebars_helper.js b/template/handlebars_helper.js index 703cbdfc..b01113b1 100644 --- a/template/handlebars_helper.js +++ b/template/handlebars_helper.js @@ -3,6 +3,21 @@ define([ 'handlebars', 'diffMatchPatch' ], function(locale, Handlebars, DiffMatchPatch) { + + /** + * start/stop timer for simple performance check. + */ + var timer; + Handlebars.registerHelper('startTimer', function(text) { + timer = new Date(); + return ''; + }); + + Handlebars.registerHelper('stopTimer', function(text) { + console.log(new Date() - timer); + return ''; + }); + /** * Return localized Text. * @param string text @@ -81,8 +96,12 @@ define([ /** * */ + var templateCache = {}; Handlebars.registerHelper('subTemplate', function(name, sourceContext) { - var template = Handlebars.compile($('#template-' + name).html()); + if ( ! templateCache[name]) + templateCache[name] = Handlebars.compile($('#template-' + name).html()); + + var template = templateCache[name]; var templateContext = $.extend({}, this, sourceContext.hash); return new Handlebars.SafeString( template(templateContext) ); }); diff --git a/template/main.js b/template/main.js index 0484ba3e..685471c7 100644 --- a/template/main.js +++ b/template/main.js @@ -46,7 +46,7 @@ require([ 'pathToRegexp' ], function($, _, locale, Handlebars, apiProject, apiData, prettyPrint, sampleRequest) { - // Load google web fonts. + // load google web fonts loadGoogleFontCss(); var api = apiData.api; @@ -81,13 +81,12 @@ require([ // // Data transform // - - // Grouped by group + // grouped by group var apiByGroup = _.groupBy(api, function(entry) { return entry.group; }); - // Grouped by group and name + // grouped by group and name var apiByGroupAndName = {}; $.each(apiByGroup, function(index, entries) { apiByGroupAndName[index] = _.groupBy(entries, function(entry) { @@ -157,7 +156,7 @@ require([ apiVersions.reverse(); // - // Create Navigationlist + // create Navigationlist // var nav = []; apiGroups.forEach(function(group) { @@ -246,6 +245,7 @@ require([ // Render Sections and Articles // var articleVersions = {}; + var content = ''; apiGroups.forEach(function(groupEntry) { var articles = []; var oldName = ''; @@ -254,7 +254,7 @@ require([ var description = ''; articleVersions[groupEntry] = {}; - // render all Articls of a group + // render all articles of a group api.forEach(function(entry) { if(groupEntry === entry.group) { if (oldName !== entry.name) { @@ -271,9 +271,7 @@ require([ article: entry, versions: articleVersions[entry.group][entry.name] }; - } - else - { + } else { fields = { article: entry, hidden: true, @@ -310,8 +308,9 @@ require([ description: description, articles: articles }; - $('#sections').append( templateSections(fields) ); + content += templateSections(fields); }); + $('#sections').append( content ); // Bootstrap Scrollspy var $scrollSpy = $(this).scrollspy({ target: '#scrollingNav', offset: 25 });