Build on Locus' syntax
This commit is contained in:
parent
93de9c0164
commit
aa6d13025c
1 changed files with 44 additions and 18 deletions
|
|
@ -92,26 +92,48 @@ BR.Profile = L.Evented.extend({
|
||||||
return e.startsWith('global');
|
return e.startsWith('global');
|
||||||
});
|
});
|
||||||
if (global) {
|
if (global) {
|
||||||
|
// Remove ---context:global line
|
||||||
global = global[0].split('\n').slice(1);
|
global = global[0].split('\n').slice(1);
|
||||||
|
|
||||||
// Comment is mandatory
|
// Comment is mandatory
|
||||||
var assignRegex = /assign\s*(\w*)\s*=?\s*([\w\.]*)\s*#\s*(.*)\s*$/;
|
var assignRegex = /assign\s*(\w*)\s*=?\s*([\w\.]*)\s*#\s*%(.*)%\s*(\|\s*(.*)\s*\|\s*(.*)\s*)?$/;
|
||||||
var params = {};
|
var params = {};
|
||||||
global.forEach(function(item) {
|
global.forEach(function(item) {
|
||||||
var match = item.match(assignRegex);
|
var match = item.match(assignRegex);
|
||||||
var value;
|
var value;
|
||||||
if (match) {
|
if (match) {
|
||||||
if (match[2] == 'true' || match[2] == 'false') {
|
var name = match[1];
|
||||||
paramType = 'checkbox';
|
var value = match[2];
|
||||||
value = match[2] == 'true';
|
var description = match[5];
|
||||||
} else {
|
|
||||||
value = Number.parseFloat(match[2]);
|
// Find out type
|
||||||
|
var paramType = match[6];
|
||||||
|
if (paramType.match(/\[.*\]/)) {
|
||||||
|
console.log('TODO: ' + paramType); // TODO
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type is missing, let's try to induce it from value
|
||||||
|
if (!paramType) {
|
||||||
|
if (value == 'true' || value == 'false') {
|
||||||
|
paramType = 'boolean';
|
||||||
|
} else {
|
||||||
|
paramType = 'number';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sanitize value according to type
|
||||||
|
if (paramType == 'boolean') {
|
||||||
|
value = value == 'true';
|
||||||
|
} else if (paramType == 'number') {
|
||||||
|
value = Number.parseFloat(value);
|
||||||
if (Number.isNaN(value)) {
|
if (Number.isNaN(value)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
paramType = 'number';
|
|
||||||
}
|
}
|
||||||
params[match[1]] = {
|
|
||||||
comment: match[3],
|
params[name] = {
|
||||||
|
description: description,
|
||||||
type: paramType,
|
type: paramType,
|
||||||
value: value
|
value: value
|
||||||
};
|
};
|
||||||
|
|
@ -124,19 +146,23 @@ BR.Profile = L.Evented.extend({
|
||||||
var div = document.createElement('div');
|
var div = document.createElement('div');
|
||||||
var label = document.createElement('label');
|
var label = document.createElement('label');
|
||||||
var input = document.createElement('input');
|
var input = document.createElement('input');
|
||||||
input.type = params[param].type;
|
|
||||||
if (input.type == 'checkbox') {
|
var paramType = params[param].type;
|
||||||
input.checked = params[param].value;
|
if (paramType == 'number') {
|
||||||
label.appendChild(input);
|
input.type = 'number';
|
||||||
label.append(' ' + param);
|
|
||||||
} else {
|
|
||||||
input.value = params[param].value;
|
input.value = params[param].value;
|
||||||
label.append(param + ' ');
|
} else if (paramType == 'boolean') {
|
||||||
label.appendChild(input);
|
input.type = 'checkbox';
|
||||||
|
input.checked = params[param].value;
|
||||||
|
} else {
|
||||||
|
// Unknown parameter type, skip it
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
label.appendChild(input);
|
||||||
|
label.append(' ' + param);
|
||||||
div.appendChild(label);
|
div.appendChild(label);
|
||||||
var small = document.createElement('small');
|
var small = document.createElement('small');
|
||||||
small.innerHTML = ' (' + params[param].comment + ')';
|
small.innerHTML = ' (' + params[param].description.replace(/^\s+|\s+$/g, '') + ')';
|
||||||
div.appendChild(small);
|
div.appendChild(small);
|
||||||
paramsSection.appendChild(div);
|
paramsSection.appendChild(div);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue