Updated to docs format v3, adds support for interfaces

This commit is contained in:
Amish Shah
2016-08-18 13:07:42 +01:00
parent 4d4258b4e2
commit 18299970bd
6 changed files with 59 additions and 13 deletions

File diff suppressed because one or more lines are too long

View File

@@ -4,7 +4,7 @@ let parse;
const customDocs = require('../custom/index'); const customDocs = require('../custom/index');
const GEN_VERSION = 2; const GEN_VERSION = 3;
try { try {
fs = require('fs-extra'); fs = require('fs-extra');
@@ -20,7 +20,7 @@ console.log('Starting...');
let json = ''; let json = '';
const stream = parse({ const stream = parse({
src: ['./src/*.js', './src/*/*.js'], src: ['./src/*.js', './src/*/*.js', './src/**/*.js'],
}); });
const cwd = (`${process.cwd()}\\`).replace(/\\/g, '/'); const cwd = (`${process.cwd()}\\`).replace(/\\/g, '/');
@@ -36,6 +36,7 @@ function cleanPaths() {
function clean() { function clean() {
const cleaned = { const cleaned = {
classes: {}, classes: {},
interfaces: {},
}; };
for (const item of json) { for (const item of json) {
if (item.kind === 'class') { if (item.kind === 'class') {
@@ -45,10 +46,19 @@ function clean() {
properties: [], properties: [],
events: [], events: [],
}; };
} else if (item.kind === 'interface') {
cleaned.interfaces[item.longname] = {
meta: item,
functions: [],
properties: [],
events: [],
};
} else if (item.kind === 'member') { } else if (item.kind === 'member') {
cleaned.classes[item.memberof].properties.push(item); const obj = cleaned.classes[item.memberof] || cleaned.interfaces[item.memberof];
obj.properties.push(item);
} else if (item.kind === 'function' && item.memberof) { } else if (item.kind === 'function' && item.memberof) {
cleaned.classes[item.memberof].functions.push(item); const obj = cleaned.classes[item.memberof] || cleaned.interfaces[item.memberof];
obj.functions.push(item);
} }
} }
json = cleaned; json = cleaned;
@@ -58,7 +68,6 @@ function next() {
json = JSON.parse(json); json = JSON.parse(json);
cleanPaths(); cleanPaths();
console.log('parsed inline code'); console.log('parsed inline code');
console.log(json);
clean(); clean();
json = { json = {
meta: { meta: {

View File

@@ -4,7 +4,7 @@
"description": "A way to interface with the Discord API", "description": "A way to interface with the Discord API",
"main": "./src/index", "main": "./src/index",
"scripts": { "scripts": {
"test": "node test/random", "test": "eslint src/ && node test/random",
"docs": "node docs/gen/index.js" "docs": "node docs/gen/index.js"
}, },
"repository": { "repository": {

View File

@@ -5,6 +5,7 @@ const TextBasedChannel = require('./interface/TextBasedChannel');
/** /**
* Represents a Server Text Channel on Discord. * Represents a Server Text Channel on Discord.
* @extends {GuildChannel} * @extends {GuildChannel}
* @implements {TextBasedChannel}
*/ */
class TextChannel extends GuildChannel { class TextChannel extends GuildChannel {

View File

@@ -2,6 +2,7 @@ const TextBasedChannel = require('./interface/TextBasedChannel');
/** /**
* Represents a User on Discord. * Represents a User on Discord.
* @implements {TextBasedChannel}
*/ */
class User { class User {
constructor(client, data) { constructor(client, data) {
@@ -99,6 +100,10 @@ class User {
return base; return base;
} }
sendMessage() {
return;
}
} }
TextBasedChannel.applyToClass(User); TextBasedChannel.applyToClass(User);

View File

@@ -1,12 +1,43 @@
function sendMessage(content, options = {}) { /**
return this.client.rest.methods.sendMessage(this, content, options.tts); * Interface for classes that have text-channel-like features
* @interface
*/
class TextBasedChannel {
/**
* Send a message to this channel
* @param {String} content the content to send
* @param {MessageOptions} [options={}] the options to provide
* @returns {Promise<Message>}
* @example
* // send a message
* channel.sendMessage('hello!')
* .then(message => console.log(`Sent message: ${message.content}`))
* .catch(console.log);
*/
sendMessage(content, options = {}) {
return this.client.rest.methods.sendMessage(this, content, options.tts);
}
/**
* Send a text-to-speech message to this channel
* @param {String} content the content to send
* @returns {Promise<Message>}
* @example
* // send a TTS message
* channel.sendTTSMessage('hello!')
* .then(message => console.log(`Sent tts message: ${message.content}`))
* .catch(console.log);
*/
sendTTSMessage(content) {
return this.client.rest.methods.sendMessage(this, content, true);
}
} }
function sendTTSMessage(content) { function applyProp(structure, prop) {
return this.client.rest.methods.sendMessage(this, content, true); structure.prototype[prop] = TextBasedChannel.prototype[prop];
} }
exports.applyToClass = structure => { exports.applyToClass = structure => {
structure.prototype.sendMessage = sendMessage; for (const prop of ['sendMessage', 'sendTTSMessage']) {
structure.prototype.sendTTSMessage = sendTTSMessage; applyProp(structure, prop);
}
}; };