Skip to content

Commit

Permalink
Merge pull request #25 from kyleholzinger/master
Browse files Browse the repository at this point in the history
Add prefix to examples
  • Loading branch information
tkqubo authored May 17, 2017
2 parents 4672c1c + ff86da1 commit 0e86f07
Show file tree
Hide file tree
Showing 5 changed files with 664 additions and 32 deletions.
6 changes: 3 additions & 3 deletions body-template.md.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
##### Examples

{{#each rule.optionExamples }}
{{{json . false}}}
{{{json . false ../rule.ruleName }}}
{{/each}}
{{/if}}

{{#if rule.options }}
##### Schema

{{{json rule.options true }}}
{{{json rule.options true '' }}}
{{/if}}

For more information see [this page](https://palantir.github.io/tslint/rules/{{{rule.ruleName}}}).
For more information see [this page](https://palantir.github.io/tslint/rules/{{{rule.ruleName}}}).
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@
"lodash": "^4.17.4",
"rxjs": "^5.3.0",
"tslint": "5.0.0",
"tslint-config-airbnb": "^5.0.0",
"tslint-config-standard": "^5.0.2",
"tslint-eslint-rules": "^4.0.0"
"tslint-eslint-rules": "^4.0.0",
"tslint-react": "^3.0.0"
}
}
6 changes: 4 additions & 2 deletions src/contentRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import * as path from 'path';
import * as fs from 'fs';
import * as handlebars from 'handlebars';
import {IRuleMetadata} from 'tslint';
import * as _ from 'lodash';
const autobind: any = require('autobind-decorator');

handlebars.registerHelper('notesHeader', (rule: IRuleMetadata) => {
return (rule.typescriptOnly || rule.hasFix || rule.requiresTypeInfo) ? `\n##### Notes\n` : '';
});
handlebars.registerHelper('json', (obj: any, escape: boolean = false) => {
handlebars.registerHelper('json', (obj: any, escape: boolean = false, prefix: string) => {
const json = escape ? JSON.stringify(obj, null, 2) : obj;
return '```json\n' + json + '\n```';
const prefixString = !_.isEmpty(prefix) ? '"' + prefix + '": ' : '';
return '```json\n' + prefixString + json + '\n```';
});

@autobind
Expand Down
5 changes: 3 additions & 2 deletions src/test/contentRenderer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('ContentRenderer', () => {
requiresTypeInfo: true,
typescriptOnly: true
};
const optionExamples = rule.optionExamples.map(o => '```json\n' + o + '\n```').join('\n');
const optionExamples = rule.optionExamples.map(o => '```json\n' + '"' + rule.ruleName + '": ' + o + '\n```').join('\n');
const options = '```json\n' + JSON.stringify(rule.options, null, 2) + '\n```';
const expected = `# Rule: ${rule.ruleName}
Expand Down Expand Up @@ -60,7 +60,8 @@ ${optionExamples}
${options}
For more information see [this page](https://palantir.github.io/tslint/rules/${rule.ruleName}).`;
For more information see [this page](https://palantir.github.io/tslint/rules/${rule.ruleName}).
`;
// When
const actual = renderer.render(rule);
// Then
Expand Down
Loading

0 comments on commit 0e86f07

Please sign in to comment.