# dochammer

> Project documentation made easy and fun

Latest version **1.1.0** (published 2019-04-21) · 0 weekly downloads

## Install

```sh
npm install dochammer
pnpm add dochammer
yarn add dochammer
bun add dochammer
```

Provides the command `dochammer`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2019-04-21 |
| First published | 2019-04-11 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 11.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ben-hur Santos Ott |
| Maintainers | benhurott |
| Keywords | documentation, markdown, generator, simple |

## Links

- npm: https://www.npmjs.com/package/dochammer
- Repository: https://github.com/benhurott/dochammer
- Homepage: https://github.com/benhurott/dochammer#readme
- Issues: https://github.com/benhurott/dochammer/issues
- npm.io page: https://npm.io/package/dochammer

## Dependencies (3)

- [glob](https://npm.io/package/glob.md) ^7.1.3
- [fs-extra](https://npm.io/package/fs-extra.md) ^7.0.1
- [markdown-toc](https://npm.io/package/markdown-toc.md) ^1.2.0

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2019-04-21
- 1.0.3 — 2019-04-19
- 1.0.2 — 2019-04-12
- 1.0.1 — 2019-04-12
- 1.0.0 — 2019-04-11

## README

# dochammer

Code documentation made easy and fun.


## Motivation

Most of the projects uses the documentation in a different place (wiki, a readme, etc) and all the docs are centralized there.

The problem with this approach is because some times the members could forgot to update the doc because it's not directly visible.

The `dochammer` was created to have the `markdown` documentation side-by-side with your code **without** changing your code file (like jsdocs, etc).

## Setup

Install dochammer:

```
npm install -g dochammer
```

In your project, create a `dochammer.config.js` on the root (same level as `node_modules`).

```js
module.exports = {
  outputDir: './docs',
  inputDir: './my-app-src',
  inputFileExt: '.doc.md'
}
```

| config | type | required | description |
| ------ | ---- | -------- | ----------- |
| outputDir | string | yes | Where the generated documentation should be stored |
| inputDir | string | yes | Where `dochammer` should look for documentation files |
| inputFileExt | string | yes | The extensions of the documentation file. The `dochammer` will use it to find the docs. In the sample, `dochammer` will considere all the files ending with `.doc.md` as documentation file. |


## Usage

The `dochammer` has 2 types of documents you can create: `page` and `component`.

### Page
A `page` is a document that will be generated. To explain better, let's use this sample:

You have a service in your application that returns a user by it's id:

```
+ services/
  + user/
    - get-user.service.js
```
```js
module.exports = async id => {
  // ...
  return {
    // user data
  }
}
```

You can create a doc file for the service:
```
+ services/
  + user/
    - get-user.service.js
    - get-user.service.doc.md
```

```md
---
type: page
filename: services
---

## Get User Service

This service returns a user by it's id.

### Usage:

const service = require('./get-user.service')
const user = await service('user-id-1')
```

Where:

| header | description |
| ------ | ----------- |
| type | the type of the doc, in this case: `page` |
| filename | all the pages will be generated in a file. The `filename` header indicate the name of the file. If more than one doc uses the same filename, it will be concatenated in the same file |

Ok, we are done with our page.

Now, in the terminal in the root of your project, just run:

```bash
dochammer
```

It will generate a folder named `docs` (that we configured  in the `dochammer.config.js` as `outputFolder`) with a file `services.md` (that was the `filename` in the doc header)

```
+ docs/
  - services.md
```

### Component

Components are the best way to **reuse** documentation inside other documents.

To create a component, you just need to create a doc with:

```md
---
type: component
id: my-component
---

## My component

bla bla bla
```

You can use it in your pages using:

```md
---
type: page
filename: services
---

## My service

%{component:my-component}
```

Where `my-component` is the `id` of your component.

Now, if you run `dochammer` to generate the docs, the `%{component:my-component}` will be replaced with the content of the component doc.


**component**
```md
---
type: component
id: my-component
---

## My component

bla bla bla
```

**page**
```md
---
type: page
filename: services
---

## My service

%{component:my-component}
```

**result**
```md
---
type: page
filename: services
---

## My service

## My component

bla bla bla
```

## Using variables

You can use pre-configured variables in your template rendering.

To use it, you need to:

### Add the variables to dochammer.config.js

```js
// dochammer.config.js
module.exports = {
  variables: {
    api_url: 'http://api.com'
  },
  //...
}
```

### Use the variable inside your doc

```md
---
type: component
id: my-component
---

Hey this is a component

%{variable:api_url}
```

### Including a table of contents in pages

Each generated page file can have an index guide if you want.

To add the table of contents index, just add `includeTableOfContent` to your config file:

```js
// dochammer.config.js
module.exports = {
  includeTableOfContent: true,
  //...
}
```

---
_Source: https://npm.io/package/dochammer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
