Hotfix parameterization
This commit is contained in:
parent
488fba0768
commit
47d15c0261
6 changed files with 60 additions and 6 deletions
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "ergogen",
|
"name": "ergogen",
|
||||||
"version": "3.1.0",
|
"version": "3.1.1",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "ergogen",
|
"name": "ergogen",
|
||||||
"version": "3.1.0",
|
"version": "3.1.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@jscad/openjscad": "github:ergogen/oldjscad",
|
"@jscad/openjscad": "github:ergogen/oldjscad",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ergogen",
|
"name": "ergogen",
|
||||||
"version": "3.1.0",
|
"version": "3.1.1",
|
||||||
"description": "Ergonomic keyboard layout generator",
|
"description": "Ergonomic keyboard layout generator",
|
||||||
"author": "Bán Dénes <mr@zealot.hu>",
|
"author": "Bán Dénes <mr@zealot.hu>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
@ -25,6 +25,7 @@ const process = async (raw, debug=false, logger=()=>{}) => {
|
||||||
logger('Preprocessing input...')
|
logger('Preprocessing input...')
|
||||||
config = prepare.unnest(config)
|
config = prepare.unnest(config)
|
||||||
config = prepare.inherit(config)
|
config = prepare.inherit(config)
|
||||||
|
config = prepare.parameterize(config)
|
||||||
const results = {}
|
const results = {}
|
||||||
if (debug) {
|
if (debug) {
|
||||||
results.raw = raw
|
results.raw = raw
|
||||||
|
|
|
@ -80,6 +80,13 @@ exports.inherit = config => traverse(config, config, [], (target, key, val, root
|
||||||
})
|
})
|
||||||
|
|
||||||
exports.parameterize = config => traverse(config, config, [], (target, key, val, root, breadcrumbs) => {
|
exports.parameterize = config => traverse(config, config, [], (target, key, val, root, breadcrumbs) => {
|
||||||
|
|
||||||
|
// we only care about objects
|
||||||
|
if (a.type(val)() !== 'object') {
|
||||||
|
target[key] = val
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let params = val.$params
|
let params = val.$params
|
||||||
let args = val.$args
|
let args = val.$args
|
||||||
|
|
||||||
|
@ -108,7 +115,7 @@ exports.parameterize = config => traverse(config, config, [], (target, key, val,
|
||||||
let str = JSON.stringify(val)
|
let str = JSON.stringify(val)
|
||||||
const zip = rows => rows[0].map((_, i) => rows.map(row => row[i]))
|
const zip = rows => rows[0].map((_, i) => rows.map(row => row[i]))
|
||||||
for (const [par, arg] of zip([params, args])) {
|
for (const [par, arg] of zip([params, args])) {
|
||||||
str = str.replace(new RegExp(`"${par}"`, 'g'), JSON.stringify(arg))
|
str = str.replace(new RegExp(`${par}`, 'g'), arg)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
val = JSON.parse(str)
|
val = JSON.parse(str)
|
||||||
|
|
|
@ -56,6 +56,36 @@ describe('Interface', function() {
|
||||||
ergogen.process({points: {zones: {}}}, true, () => {}).should.be.rejectedWith('any points')
|
ergogen.process({points: {zones: {}}}, true, () => {}).should.be.rejectedWith('any points')
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('preprocessor', async function() {
|
||||||
|
return Promise.all([
|
||||||
|
// unnesting
|
||||||
|
ergogen.process({'points.zones.matrix': {}}).should.eventually.have.deep.property('canonical', {
|
||||||
|
points: {zones: {matrix: {}}}
|
||||||
|
}),
|
||||||
|
// inheritance
|
||||||
|
ergogen.process({
|
||||||
|
'points.zones.parent.key.a': 1,
|
||||||
|
'points.zones.child': {
|
||||||
|
'$extends': 'points.zones.parent',
|
||||||
|
'key.b': 2
|
||||||
|
}
|
||||||
|
}).should.eventually.have.deep.nested.property('canonical.points.zones.child.key', {
|
||||||
|
a: 1,
|
||||||
|
b: 2
|
||||||
|
}),
|
||||||
|
// parameterization
|
||||||
|
ergogen.process({
|
||||||
|
'points.zones.matrix.key': {
|
||||||
|
a: 'PAR',
|
||||||
|
$params: ['PAR'],
|
||||||
|
$args: [1]
|
||||||
|
}
|
||||||
|
}).should.eventually.have.deep.nested.property('canonical.points.zones.matrix.key', {
|
||||||
|
a: '1'
|
||||||
|
})
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
it('engine', async function() {
|
it('engine', async function() {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
|
|
|
@ -64,7 +64,23 @@ describe('Prepare', function() {
|
||||||
$args: [1]
|
$args: [1]
|
||||||
}
|
}
|
||||||
}).decl.should.deep.equal({
|
}).decl.should.deep.equal({
|
||||||
a: 1
|
a: '1'
|
||||||
|
})
|
||||||
|
|
||||||
|
p.parameterize({
|
||||||
|
decl: {
|
||||||
|
normal_use: 'PAR1',
|
||||||
|
sub: {
|
||||||
|
nested_use: 'PAR2 * 2'
|
||||||
|
},
|
||||||
|
$params: ['PAR1', 'PAR2'],
|
||||||
|
$args: ['text', 14]
|
||||||
|
}
|
||||||
|
}).decl.should.deep.equal({
|
||||||
|
normal_use: 'text',
|
||||||
|
sub: {
|
||||||
|
nested_use: '14 * 2',
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
p.parameterize.bind(this, {
|
p.parameterize.bind(this, {
|
||||||
|
@ -84,7 +100,7 @@ describe('Prepare', function() {
|
||||||
decl: {
|
decl: {
|
||||||
a: 'PAR',
|
a: 'PAR',
|
||||||
$params: ['PAR'],
|
$params: ['PAR'],
|
||||||
$args: [undefined]
|
$args: ['in"jection']
|
||||||
}
|
}
|
||||||
}).should.throw('valid')
|
}).should.throw('valid')
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue