Started documenting

This commit is contained in:
Devine Lu Linvega 2019-07-18 08:48:00 +09:00
parent 5d9472af18
commit aa0415a200
3 changed files with 18 additions and 14 deletions

View File

@ -178,18 +178,22 @@ function Commander (ronin) {
for (const id in payload) { for (const id in payload) {
const parts = payload[id].split(' = ') const parts = payload[id].split(' = ')
const name = parts[0] const name = parts[0]
const params = parts[1].match(/\(([^)]+)\)/) const parent = parts[1].match(/\(([^)]+)\)/)
if (!params) { console.warn('Docs', 'Misformatted ' + name); continue } const params = parent ? parent[1].split(',').map((word) => { return word.trim() }) : []
this.dict[name] = params[1].split(',').map((word) => { return word.trim() }) const note = payload[id].indexOf('// ') > -1 ? payload[id].split('//')[1].trim() : ''
this.dict[name] = { note, params }
if (params.length < 1) { console.warn('Docs', 'Missing params for ' + name) }
if (note === '') { console.warn('Docs', 'Missing note for ' + name) }
} }
console.log('Dict', `Loaded ${Object.keys(this.dict).length} functions.`) console.log('Docs', `Loaded ${Object.keys(this.dict).length} functions.`)
console.log(this.toMarkdown()) console.log(this.toMarkdown())
}, },
toMarkdown: function () { toMarkdown: function () {
return Object.keys(this.dict).reduce((acc, item, key) => { return Object.keys(this.dict).reduce((acc, item, key) => {
return `${acc}- \`(${item} ${this.dict[item].reduce((acc, item) => { const example = `${item} ${this.dict[item].params.reduce((acc, item) => {
return `${acc}${item} ` return `${acc}${item} `
}, '').trim()})\`\n` }, '').trim()}`
return `${acc}- \`(${example.trim()})\` ${this.dict[item].note}\n`
}, '') }, '')
} }
} }

View File

@ -31,25 +31,25 @@ function Library (ronin) {
return ronin.surface.crop(rect) return ronin.surface.crop(rect)
} }
this.folder = (path = ronin.source.path) => { this.folder = (path = ronin.source.path) => { // Returns the content of a folder path.
return fs.existsSync(path) ? fs.readdirSync(path) : [] return fs.existsSync(path) ? fs.readdirSync(path) : []
} }
this.exit = () => { this.exit = (force = false) => { // Exits Ronin/
ronin.source.quit() ronin.source.quit(force)
} }
// Logic // Logic
this.gt = (a, b) => { this.gt = (a, b) => { // Returns true if a is greater than b, else false.
return a > b return a > b
} }
this.lt = (a, b) => { this.lt = (a, b) => { // Returns true if a is less than b, else false.
return a < b return a < b
} }
this.eq = (a, b) => { this.eq = (a, b) => { // Returns true if a is equal to b, else false.
return a === b return a === b
} }

View File

@ -75,8 +75,8 @@ function Source (ronin) {
ronin.commander._input.value = data ronin.commander._input.value = data
} }
this.quit = function () { this.quit = function (force = false) {
if (this.hasChanges() === true) { if (this.hasChanges() === true && force === false) {
this.verify() this.verify()
} else { } else {
app.exit() app.exit()