Skip to content

Commit

Permalink
Small design fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexprey committed Oct 30, 2018
1 parent 6df622e commit 92ebfb9
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/node_modules
*.log
/build
/build
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/test
.eslintrc.json
.gitignore
yarn.lock
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# The sveltedoc parser

## Key Features
Generate a JSON documentation for a Svelte file

[![npm](https://img.shields.io/npm/v/sveltedoc-parser.svg)](https://www.npmjs.com/package/sveltedoc-parser)

## Install

```shell
npm install --save sveltedoc-parser
```

## Features

- JSDoc support
- Extract the component description from JSDoc
Expand All @@ -22,10 +32,27 @@
|---------|-----------|---------------|
| **filename** | The filename to parse. **Required**, unless `fileContent` is passed. | |
| **fileContent** | The file content to parse. **Required**, unless `filename` is passed. | |
| **encoding** | The file encoding. | 'utf8' |
| **encoding** | The file encoding. | `utf8` |
| **features** | The component features to parse and extracting. | By default used all supported features. |
| **ignoredVisibilities** | The list of ignored visibilities. | `['private', 'protected']` |

## Usage

```js
const sveltedoc = require('sveltedoc-parser');
const options = {
filename: 'main.svelte'
};

sveltedoc.parse(options)
.then(componentDoc => {
console.log(componentDoc);
})
.catch(e => {
console.error(e);
});
```

## Issues

All list of known issues presented at [this page](https://github.com/alexprey/sveltedoc-parser/issues).
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@sveltedoc/parser",
"name": "sveltedoc-parser",
"version": "1.0.0",
"description": "Generate a JSON documentation for a Svelte file",
"main": "index.js",
Expand Down
23 changes: 23 additions & 0 deletions test/events/event.method.fire.identifier.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<div>
<button on:click="handleButtonClick(event)">
Click to fire
</button>
</div>

<script>
const ComponentEventNames = {
Click: 'click'
};
export default {
methods: {
handleButtonClick(event) {
/**
* Event fired when user clicked on button.
*/
this.fire(ComponentEventNames.Click, event);
}
}
}
</script>
24 changes: 24 additions & 0 deletions test/events/events.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@ describe('Events', () => {
});
});

it('Fired events with identifier event name in component methods should be parsed', (done) => {
parser.parse({
filename: path.resolve(__dirname, 'event.method.fire.identifier.svelte'),
features: ['events'],
ignoredVisibilities: []
}).then((doc) => {
expect(doc, 'Document should be provided').to.exist;
expect(doc.events, 'Document events should be parsed').to.exist;

expect(doc.events.length).to.equal(1);
const event = doc.events[0];

expect(event, 'Event should be a valid entity').to.exist;
expect(event.name).to.equal('click');
expect(event.visibility).to.equal('public');
expect(event.parent).to.be.null;
expect(event.description).to.equal('Event fired when user clicked on button.');

done();
}).catch(e => {
done(e);
});
});

it('Propogated events in markup should be parsed', (done) => {
parser.parse({
filename: path.resolve(__dirname, 'event.markup.propogate.svelte'),
Expand Down

0 comments on commit 92ebfb9

Please sign in to comment.