Implemented docs

This commit is contained in:
Devine Lu Linvega 2019-07-18 08:24:43 +09:00
parent 521ece7937
commit eedd6868a1
3 changed files with 29 additions and 8 deletions

View File

@ -10,8 +10,8 @@ function Commander (ronin) {
this.el.appendChild(this._input)
this.el.appendChild(this._status)
host.appendChild(this.el)
this._input.addEventListener('input', this.onInput)
this.docs.install()
}
this.start = function () {
@ -162,4 +162,27 @@ function Commander (ronin) {
this.hide()
}
}
// Docs micro-module
this.docs = {
path: 'sources/scripts/library.js',
load: function () {
const fs = require('fs')
if (!fs.existsSync(this.path)) { console.warn('Docs', 'File does not exist: ' + this.path); return }
const lines = fs.readFileSync(this.path, 'utf8').split('\n').filter((line) => { return line.substr(0, 7) === ' this.' })
return lines.map((line) => { return line.trim().substr(5, line.length - 5).trim() })
},
install: function (payload = this.load()) {
const dict = {}
for (const id in payload) {
const parts = payload[id].split(' = ')
const name = parts[0]
const params = parts[1].match(/\(([^)]+)\)/)
if (!params) { console.warn('Docs', 'Misformatted ' + name); continue }
dict[name] = params[1].split(',').map((word) => { return word.trim() })
}
console.log(dict)
}
}
}

View File

@ -1,5 +1,4 @@
function Library (ronin) {
console.log(ronin)
this.open = async (path) => {
return ronin.surface.open(path)
}
@ -215,7 +214,7 @@ function Library (ronin) {
// Gradients
this.gradient = ([x1,y1,x2,y2], colors=['white','black']) => {
this.gradient = ([x1, y1, x2, y2], colors = ['white', 'black']) => {
return ronin.surface.linearGradient(x1, y1, x2, y2, colors)
}
@ -337,5 +336,4 @@ function Library (ronin) {
// javascript interop
this.js = window
}

View File

@ -61,11 +61,11 @@ function Surface (ronin) {
context.closePath()
}
this.linearGradient = function(x1, y1, x2, y2, colors, context = this.context) {
this.linearGradient = function (x1, y1, x2, y2, colors, context = this.context) {
const gradient = context.createLinearGradient(x1, y1, x2, y2)
const step = 1/(colors.length - 1)
colors.forEach((color,i) => {
gradient.addColorStop(i*step, color)
const step = 1 / (colors.length - 1)
colors.forEach((color, i) => {
gradient.addColorStop(i * step, color)
})
return gradient
}