refactoring
This commit is contained in:
parent
9922372447
commit
f6b89d6202
|
@ -74,7 +74,7 @@ module.exports = new Package('angular.io', [basePackage])
|
|||
|
||||
.config(function(templateEngine, getInjectables) {
|
||||
templateEngine.filters = templateEngine.filters.concat(getInjectables([require('./rendering/trimBlankLines')]));
|
||||
templateEngine.filters = templateEngine.filters.concat(getInjectables([require('./rendering/indentNonMixin')]));
|
||||
templateEngine.filters = templateEngine.filters.concat(getInjectables([require('./rendering/indentForMarkdown')]));
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
module.exports = function(encodeCodeBlock) {
|
||||
// var MIXIN_PATTERN = /\S*\+\S*\(.*/;
|
||||
return {
|
||||
name: 'indentForMarkdown',
|
||||
process: function (str, width ) {
|
||||
if(str == null || str.length === 0) {
|
||||
return '';
|
||||
}
|
||||
width = width || 4;
|
||||
|
||||
var lines = str.split('\n');
|
||||
var newLines = [];
|
||||
var sp = spaces(width);
|
||||
var spMixin = spaces(width - 2);
|
||||
var isAfterMarkdownTag = true;
|
||||
lines.forEach(function(line) {
|
||||
// indent lines that match mixin pattern by 2 less than specified width
|
||||
if (line.indexOf('{@example') >= 0) {
|
||||
if (isAfterMarkdownTag) {
|
||||
// happens if example follows example
|
||||
if (newLines.length > 0) {
|
||||
newLines.pop();
|
||||
} else {
|
||||
// wierd case - first expression in str is an @example
|
||||
// in this case the :markdown appear above the str passed in,
|
||||
// so we need to put 'something' into the markdown tag.
|
||||
newLines.push(sp + "."); // '.' is a dummy char
|
||||
}
|
||||
}
|
||||
newLines.push(spMixin + line);
|
||||
// after a mixin line we need to reenter markdown.
|
||||
newLines.push(spMixin + ':markdown');
|
||||
isAfterMarkdownTag = true;
|
||||
} else {
|
||||
if ((!isAfterMarkdownTag) || (line.trim().length > 0)) {
|
||||
newLines.push(sp + line);
|
||||
isAfterMarkdownTag = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (isAfterMarkdownTag) {
|
||||
if (newLines.length > 0) {
|
||||
// if last line is a markdown tag remove it.
|
||||
newLines.pop();
|
||||
}
|
||||
}
|
||||
|
||||
var res = newLines.join('\n');
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
function spaces(n) {
|
||||
var str = '';
|
||||
for(var i=0; i<n; i++) {
|
||||
str += ' ';
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
};
|
|
@ -1,49 +0,0 @@
|
|||
module.exports = function(encodeCodeBlock) {
|
||||
var MIXIN_PATTERN = /\S*\+\S*\(.*/;
|
||||
return {
|
||||
name: 'indentNonMixin',
|
||||
process: function (str, width, indentfirst) {
|
||||
str = normalize(str, '');
|
||||
|
||||
if (str === '') return '';
|
||||
|
||||
width = width || 4;
|
||||
var res = '';
|
||||
var lines = str.split('\n');
|
||||
var sp = repeat(' ', width);
|
||||
var spMixin = repeat(' ', width - 2);
|
||||
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
if (i === 0 && !indentfirst) {
|
||||
res += lines[i] + '\n';
|
||||
}
|
||||
else {
|
||||
// indent lines that match mixin pattern by 2 less.
|
||||
if (lines[i].indexOf('{@example') != -1) {
|
||||
res += spMixin + lines[i] + '\n';
|
||||
} else {
|
||||
res += sp + lines[i] + '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
function normalize(value, defaultValue) {
|
||||
if(value === null || value === undefined || value === false) {
|
||||
return defaultValue;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function repeat(char_, n) {
|
||||
var str = '';
|
||||
for(var i=0; i<n; i++) {
|
||||
str += char_;
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
};
|
|
@ -8,7 +8,7 @@ p.location-badge.
|
|||
defined in {$ githubViewLink(doc) $}
|
||||
|
||||
:markdown
|
||||
{$ doc.description | indentNonMixin(2, true) | trimBlankLines $}
|
||||
{$ doc.description | indentForMarkdown(2) | trimBlankLines $}
|
||||
|
||||
{%- if doc.decorators %}
|
||||
.l-main-section
|
||||
|
@ -37,7 +37,7 @@ p.location-badge.
|
|||
{$ doc.constructorDoc.name $}{$ paramList(doc.constructorDoc.parameters) | indent(8, false) | trim $}
|
||||
{% endif %}
|
||||
:markdown
|
||||
{$ doc.constructorDoc.description | indentNonMixin(6, true) | replace('## Example', '') | replace('# Example', '') | trimBlankLines $}
|
||||
{$ doc.constructorDoc.description | indentForMarkdown(6) | replace('## Example', '') | replace('# Example', '') | trimBlankLines $}
|
||||
|
||||
|
||||
{% endif -%}
|
||||
|
@ -52,7 +52,7 @@ p.location-badge.
|
|||
{$ member.name $}{$ paramList(member.parameters) | indent(8, false) | trim $}{$ returnType(doc.returnType) $}
|
||||
{% endif %}
|
||||
:markdown
|
||||
{$ member.description | indentNonMixin(6, true) | replace('## Example', '') | replace('# Example', '') | trimBlankLines $}
|
||||
{$ member.description | indentForMarkdown(6) | replace('## Example', '') | replace('# Example', '') | trimBlankLines $}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -17,6 +17,6 @@
|
|||
defined in {$ githubViewLink(doc) $}
|
||||
|
||||
:markdown
|
||||
{$ doc.description | indentNonMixin(4, true) | trimBlankLines $}
|
||||
{$ doc.description | indentForMarkdown(4) | trimBlankLines $}
|
||||
|
||||
{% endblock %}
|
|
@ -8,5 +8,5 @@
|
|||
defined in {$ githubViewLink(doc) $}
|
||||
|
||||
:markdown
|
||||
{$ doc.description | indentNonMixin(4, true) | trimBlankLines $}
|
||||
{$ doc.description | indentForMarkdown(4) | trimBlankLines $}
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in New Issue