dok

jsdoc(file)

Generate docs JSON by using patched JSDoc haruki template. The patched version includes lineno.

Returns

parseArgs(fn)

Generate a String with comma separated function arguments. Put square brackets around optional arguments. Ignore child arguments like config.key.

Returns

Example

var fn = {
  name: 'sum',
  description: '...',
  parameters: [
    {
      name: 'x',
      optional: ''
    },
    {
      name: 'y',
      optional: true
    }
  ]
};
var out = parseArgs(fn);
// x, [y]

parseDescription(desc)

Generate gfm description from JSDoc description. Replace code tags with markdown code tags.

Returns

Example

var desc = '<p>Some description with variable <code>a</code></p>'
var parsed = parseDescription(desc);
// Some description with variable `a`

parseExamples(examples)

Generate gfm compatible code block from JSDoc parsed examples array.

Returns

Example

var examples = [
  'var z = sum(10, 20);\nconsole.log(z);\n// 40'
];
var parsed = parseExamples(examples);
// [
//   '```javascript\nvar z = sum(10, 20);\nconsole.log(z);\n// 40\n```'
// ]

parseParams(params)

Generate markdown list item from parameter object.

Returns

Example

var params = [
  {
    name: 'x',
    type: 'Number',
    description: '<p>First number</p>'
  },
  {
    name: 'y',
    type: 'Number',
    description: '<p>Second number</p>',
    default: '20',
    optional: true
  }
];
var parsed = parseParams(params);
// [
//   - `x` **Number** - First number
//   - `y` **Number** *optional*  - Second number - default `20`
// ]

parseReturns(returns)

Generate markdown returns block.

Returns

Example

var returns = {
  type: 'String',
  description: '<p>Some description here</p>'
};
var parsed = parseReturns(returns);
// - **String** - Some description here

render(fns)

Use handlebars to render template to index.html. Include line number for link to source code on GitHub.

clean()

Remove docs/ folder.

copy()

Copy CSS and JS folder to modules docs/ folder. These static assets are required for index.html.

write()

Write markdown files for each function.

create(file)

Create docs/ directory with .md partials in includes/ directory. Render index.html and copy statis assets (CSS and JS) to /docs directory.

getLevel(str)

Return heading level. Count number of hashes (#) in str.

Returns

Example

var one = '## a';
var levelOne = getLevel(one);  // 2
var two = '#### b';
var levelTwo = getLevel(two);  // 4

index(section, headings)

Find section index in array with all README.md headings.

Example

var section = 'c';
var headings = ['# a', '## b', '## c', '## d', '## e'];
// 2

find(level, headings)

Find first heading with given level in headings array. headings is a subarray sliced just behind the heading after that we'd like to include the markdown content.

Example

var level = 3;
var headings = ['# a', '### b', '## c', '## d'];
var index = find(level, headings);
// 1

clear(section, readme)

Clear old content from readme. Start just behind section and look for next heading that has the same level. Everything in between is cleared.

Returns

Example

README.md

# Some title

## Installation

`npm install module`

## Config

Here is how to configure the module.

### Sub config

...

## Methods

### sum(x,y)

Returns the sum of two Numbers.

...

## Test

...

## License

...

index.js

var readme = fs.readFileSync('./README.md', 'utf8');
var section = 'Methods';
readme = clear(section, readme);
// # Some title
//
// ## Installation
//
// `npm install module`
//
// ## Config
//
// Here is how to configure the module.
//
// ### Sub config
//
// ...
//
// ## Methods
//
// ## Test
//
// ...
//
// ## License
//
// ...

include(section, readme, content)

Include markdown content into readme.

updateReadme(section)

Include .md partials in README.md below section.