diff --git a/package.json b/package.json index 3ab9ae702d..93d04d4440 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "lazypipe": "^0.2.3", "lodash": "^2.4.1", "minimist": "^1.1.3", + "node-html-encoder": "0.0.2", "node-libs-browser": "^0.5.2", "node-uuid": "^1.4.1", "q": "^1.4.1", diff --git a/scripts/docs/dgeni-config.js b/scripts/docs/dgeni-config.js index 7ce1f0e252..0d54423ce1 100644 --- a/scripts/docs/dgeni-config.js +++ b/scripts/docs/dgeni-config.js @@ -76,7 +76,7 @@ module.exports = function(currentVersion){ // strip ionic from path root .replace(/^ionic\//, '') // replace extension with .html - .replace(/\.\w*$/, '.html'); + .replace(/\.\w*$/, '.md'); } }]; }) @@ -128,6 +128,12 @@ module.exports = function(currentVersion){ commentEnd: '#>' }; + // add custom filters to nunjucks + templateEngine.filters.push( + require('./filters/capital'), + require('./filters/code') + ); + templateFinder.templateFolders.unshift(path.resolve(__dirname, 'templates')); // Specify how to match docs to templates. diff --git a/scripts/docs/filters/capital.js b/scripts/docs/filters/capital.js new file mode 100644 index 0000000000..f63edd91ff --- /dev/null +++ b/scripts/docs/filters/capital.js @@ -0,0 +1,7 @@ +module.exports = { + name: 'capital', + process: function(str) { + str || (str = ''); + return str.charAt(0).toUpperCase() + str.substring(1); + } +}; diff --git a/scripts/docs/filters/code.js b/scripts/docs/filters/code.js new file mode 100644 index 0000000000..d0eaee2734 --- /dev/null +++ b/scripts/docs/filters/code.js @@ -0,0 +1,25 @@ +var encoder = new require('node-html-encoder').Encoder(); + +function code(str, inline, lang) { + // Encode any HTML entities in the code string + str = encoder.htmlEncode(str, true); + + // If a language is provided then attach a CSS class to the code element + lang = lang ? ' class="lang-' + lang + '"' : ''; + + str = '' + str + ''; + + // If not inline then wrap the code element in a pre element + if ( !inline ) { + str = '
' + str + '
'; + } + + return str; +}; + +module.exports = { + name: 'code', + process: function(str, lang) { + return code(str, true, lang); + } +}; diff --git a/scripts/docs/templates/common.template.html b/scripts/docs/templates/common.template.html index 281c46b68d..368a0aee27 100644 --- a/scripts/docs/templates/common.template.html +++ b/scripts/docs/templates/common.template.html @@ -1,7 +1,7 @@ --- <@ include "lib/yaml.template.html" @> title: "<@ if doc.docType == "directive" @><$ doc.name | dashCase $><@ else @><$ doc.name $><@ endif @>" -header_sub_title: "<$ doc.docType $> in module <$ doc.module $>" +header_sub_title: "<$ doc.docType | capital $> in module <$ doc.module $>" doc: "<$ doc.name $>" docType: "<$ doc.docType $>" --- @@ -17,6 +17,54 @@ docType: "<$ doc.docType $>" <$ doc.fileInfo.relativePath $> (line <$ doc.location.start.line+1 $>) <@- endmacro -@> +<@ macro paramTable(params, isDirective) @> + + + + + + + + + + <@ for param in params @> + + + + + + <@ endfor @> + +
<@ if isDirective @>Attr<@ else @>Param<@ endif @>TypeDetails
+ <$ param.name $> + <@ if param.alias @>| <$ param.alias $><@ endif @> + <@ if param.type.optional @>
(optional)
<@ endif @> +
+ <$ typeList(param.typeList) $> + + <$ param.description | marked $> + <@ if param.default @>

(default: <$ param.default $>)

<@ endif @> +
+<@ endmacro @> + +<@- macro functionSyntax(fn) @> +<@- set sep = joiner(', ') -@> +<$ fn.name $>(<@- for param in fn.params @><$ sep() $> + <@- if param.type.optional @>[<@ endif -@> + <$ param.name $> + <@- if param.type.optional @>]<@ endif -@> + <@ endfor @>)<@ if fn.alias @>(alias: <$ fn.alias $>)<@ endif @> +<@ endmacro -@> + +<@ macro typeList(types) -@> + <@ set separator = joiner("|") @> + <@ for type in types @><$ separator() $><$ type | code $><@ endfor @> +<@- endmacro -@> + +<@- macro typeInfo(fn) -@> +<$ typeList(fn.typeList) $> <$ fn.description $> +<@- endmacro -@> + <@ block body @>
@@ -72,6 +120,34 @@ defined in <$ githubViewLink(doc) $> <@ endfor @> <@ endif -@> +<@- if doc.members @> +## Members +<@- for method in doc.members @> + +
+

+ <$ functionSyntax(method) $> +

+ +<$ method.description $> + +<@ if method.params @> +<$ paramTable(method.params) $> +<@ endif @> + +<@ if method.this @> +#### Method's `this` +<$ method.this $> +<@ endif @> + +<@ if method.returns @> +* Returns: <$ typeInfo(method.returns) $> +<@ endif @> + +<@ endfor -@> +<@- endif -@> + + <@ endblock @> <@ endblock @>