Skip to content

Commit 4cb2013

Browse files
committed
Document build/make_default_helpers.js
1 parent 875be61 commit 4cb2013

File tree

1 file changed

+66
-65
lines changed

1 file changed

+66
-65
lines changed

build/make_default_helpers.js

Lines changed: 66 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
var _ = require("lodash"),
2-
path = require("path"),
3-
stmd_to_html = require("../stmd_to_html"),
4-
deepExtendWithoutBody = require("./deep_extend_without_body"),
5-
escape = require('escape-html'),
6-
striptags = require('striptags'),
7-
DocMapInfo = require("../doc-map-info"),
8-
unescapeHTML = require("unescape-html");
9-
// Helper helpers
10-
1+
var _ = require("lodash");
2+
var path = require("path");
3+
var stmd_to_html = require("../stmd_to_html");
4+
var deepExtendWithoutBody = require("./deep_extend_without_body");
5+
var escape = require('escape-html');
6+
var striptags = require('striptags');
7+
var DocMapInfo = require("../doc-map-info");
8+
var unescapeHTML = require("unescape-html");
119

10+
// Helper helpers
1211

13-
var sortChildren = function(child1, child2){
14-
12+
var sortChildren = function(child1, child2) {
1513
if(typeof child1.order == "number"){
1614
if(typeof child2.order == "number"){
1715
// same order given?
@@ -24,7 +22,6 @@ var sortChildren = function(child1, child2){
2422
} else {
2523
return child1.order - child2.order;
2624
}
27-
2825
} else {
2926
return -1;
3027
}
@@ -43,15 +40,15 @@ var sortChildren = function(child1, child2){
4340

4441
var docsFilename = require("../write/filename");
4542

46-
var linksRegExp = /[\[](.*?)\]/g,
47-
linkRegExp = /^(\S+)\s*(.*)/,
48-
httpRegExp = /^http/;
43+
var linksRegExp = /[\[](.*?)\]/g;
44+
var linkRegExp = /^(\S+)\s*(.*)/;
45+
var httpRegExp = /^http/;
4946

5047
/**
51-
* @add documentjs.generators.html.defaultHelpers
52-
*/
48+
* @parent bit-docs-generate-html/templates
49+
* @module {function} bit-docs-generate-html/build/make_default_helpers
50+
*/
5351
module.exports = function(docMap, config, getCurrent, Handlebars){
54-
5552
var docMapInfo = new DocMapInfo(docMap, getCurrent);
5653

5754
var urlTo = function(name){
@@ -153,9 +150,10 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
153150
},
154151

155152
// GENERIC HELPERS
153+
156154
/**
157-
* @function documentjs.generators.html.defaultHelpers.ifEqual
158-
*/
155+
* @function bit-docs-generate-html/build/make_default_helpers.ifEqual ifEqual
156+
*/
159157
ifEqual: function( first, second, options ) {
160158
if(first == second){
161159
return options.fn(this);
@@ -164,8 +162,8 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
164162
}
165163
},
166164
/**
167-
* @function documentjs.generators.html.defaultHelpers.ifAny
168-
*/
165+
* @function bit-docs-generate-html/build/make_default_helpers.ifAny ifAny
166+
*/
169167
ifAny: function(){
170168
var last = arguments.length -1,
171169
options = arguments[last];
@@ -177,16 +175,15 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
177175
return options.inverse(this);
178176
},
179177
/**
180-
* @function documentjs.generators.html.defaultHelpers.ifNotEqual
181-
*/
178+
* @function bit-docs-generate-html/build/make_default_helpers.ifNotEqual ifNotEqual
179+
*/
182180
ifNotEqual: function( first, second, options ) {
183181
if(first !== second){
184182
return options.fn(this);
185183
} else {
186184
return options.inverse(this);
187185
}
188186
},
189-
190187
config: function(){
191188
var configCopy = {};
192189
for(var prop in config){
@@ -196,28 +193,29 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
196193
}
197194
return JSON.stringify(configCopy);
198195
},
199-
200196
/**
201-
* @function documentjs.generators.html.defaultHelpers.generatedWarning
197+
* @function bit-docs-generate-html/build/make_default_helpers.generatedWarning generatedWarning
202198
* @signature `{{{generatedWarning}}}`
203199
*
204200
* @body
205201
*
206202
* ## Use
203+
*
207204
* ```
208205
* {{{generatedWarning}}}
209206
* ```
207+
*
210208
* MUST use triple-braces to escape HTML so it is hidden in a comment.
211209
*
212210
* Creates a warning that looks like this:
213211
*
214-
* ```
212+
* ```html
215213
* <!--####################################################################
216214
* THIS IS A GENERATED FILE -- ANY CHANGES MADE WILL BE OVERWRITTEN
217215
*
218216
* INSTEAD CHANGE:
219-
* source: lib/tags/iframe.js
220-
* @@constructor documentjs.tags.iframe
217+
* source: docs/modules/bit-docs-tag-demo/bit-docs.js
218+
* @@module bit-docs-tag-demo
221219
* ######################################################################## -->
222220
* ```
223221
*/
@@ -231,10 +229,11 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
231229
"\n######################################################################## -->";
232230
},
233231
/**
234-
* @function documentjs.generators.html.defaultHelpers.makeTitle
235-
* Given the docObject context, returns a "pretty" name that is used
236-
* in the sidebar and the page header.
237-
*/
232+
* @function bit-docs-generate-html/build/make_default_helpers.makeTitle makeTitle
233+
*
234+
* Given the [bit-docs/types/docObject] context, returns a "pretty"
235+
* name that is used in the sidebar and the page header.
236+
*/
238237
makeTitle: function () {
239238
var node = this, title;
240239

@@ -259,9 +258,10 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
259258
return title;
260259
},
261260
/**
262-
* @function documentjs.generators.html.defaultHelpers.makeLinks
263-
* Looks for links like [].
264-
*/
261+
* @function bit-docs-generate-html/build/make_default_helpers.makeLinks makeLinks
262+
*
263+
* Looks for links like [].
264+
*/
265265
makeLinks: function(text){
266266
if (!text) return "";
267267
var replacer = function (match, content) {
@@ -313,22 +313,22 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
313313
}
314314
},
315315
/**
316-
* @function documentjs.generators.html.defaultHelpers.urlTo
317-
*
318-
* Returns a url that links to a docObject's name.
319-
*/
316+
* @function bit-docs-generate-html/build/make_default_helpers.urlTo urlTo
317+
*
318+
* Returns a url that links to a [bit-docs/types/docObject] name.
319+
*/
320320
urlTo: function (name) {
321321
return urlTo(name);
322322
},
323323
// If the current docObject is something
324324
/**
325-
* @function documentjs.generators.html.defaultHelpers.ifActive
326-
*
327-
* Renders the truthy section if the current item's name matches
328-
* the current docObject being rendered
329-
*
330-
* @param {HandlebarsOptions} options
331-
*/
325+
* @function bit-docs-generate-html/build/make_default_helpers.ifActive ifActive
326+
*
327+
* Renders the truthy section if the current item's name matches the
328+
* current docObject being rendered
329+
*
330+
* @param {HandlebarsOptions} options
331+
*/
332332
ifActive: function(options){
333333
if(this.name == getCurrent().name){
334334
return options.fn(this);
@@ -337,18 +337,18 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
337337
}
338338
},
339339
/**
340-
* @function documentjs.generators.html.defaultHelpers.chain
341-
*
342-
* Chains multiple calls to mustache.
343-
*
344-
* @signature `{{chain [helperName...] content}}`
345-
*
346-
*/
340+
* @function bit-docs-generate-html/build/make_default_helpers.chain chain
341+
*
342+
* Chains multiple calls to mustache.
343+
*
344+
* @signature `{{chain [helperName...] content}}`
345+
*/
347346
chain: function(){
348347
var helpersToCall = [].slice.call(arguments, 0, arguments.length - 2).map(function(name){
349348
return Handlebars.helpers[name];
350-
}),
351-
value = arguments[arguments.length - 2] || "";
349+
});
350+
351+
var value = arguments[arguments.length - 2] || "";
352352

353353
helpersToCall.forEach(function(helper){
354354
value = helper.call(Handlebars, value);
@@ -360,23 +360,24 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
360360
return stmd_to_html(content);
361361
},
362362
renderAsTemplate: function(content) {
363-
var templateRender = config.templateRender || getCurrent().templateRender,
364-
renderer;
363+
var templateRender = config.templateRender || getCurrent().templateRender;
364+
var renderer;
365365

366366
if (templateRender === true) {
367367
// Render {{}} if templateRender tag/option is true
368368
renderer = Handlebars.compile(content.toString());
369369
return renderer(docMap);
370370
} else if (templateRender && templateRender.length === 2) {
371371
// Render custom delimiters if supplied by templateRender
372-
var open = new RegExp(templateRender[0], 'g'),
373-
close = new RegExp(templateRender[1], 'g'),
374-
toRender = content
372+
var open = new RegExp(templateRender[0], 'g');
373+
var close = new RegExp(templateRender[1], 'g');
374+
var toRender = content
375375
.replace(/{{/g, '\\{\\{')
376376
.replace(/}}/g, '\\}\\}')
377377
.replace(open, '{{')
378378
.replace(close, '}}');
379379
renderer = Handlebars.compile(toRender);
380+
380381
return renderer(docMap)
381382
.replace(/\\{\\{/g, '{{')
382383
.replace(/\\}\\}/g, '}}');
@@ -386,9 +387,9 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
386387
}
387388
},
388389
/**
389-
* @function bit-docs-generate-html/theme/templates/helpers/getTitle
390+
* @function bit-docs-generate-html/build/make_default_helpers.getTitle getTitle
390391
*
391-
* Returns the parent docObject's title.
392+
* Returns the parent [bit-docs/types/docObject] title.
392393
*/
393394
getTitle: function(){
394395
var root = docMap[config.parent];

0 commit comments

Comments
 (0)