Comparing version 0.13.0 to 0.14.0
195
lib/rule.js
@@ -38,3 +38,2 @@ "use strict"; | ||
var props = this.props; | ||
var config = props.config; | ||
@@ -44,5 +43,3 @@ var _compile = (0, _formula.COMPILE)(props.exp), | ||
config = config || {}; | ||
function renderFunction(f, depth) { | ||
function renderFunction(config, f, depth) { | ||
return _react2.default.createElement( | ||
@@ -55,3 +52,3 @@ "div", | ||
(0, _formula.IF)(config.hasOwnProperty("renderFunction"), function () { | ||
return config.renderFunction(f, depth, renderRule); | ||
return config.renderFunction(config, f, depth, renderRule); | ||
}, function () { | ||
@@ -64,7 +61,3 @@ return _react2.default.createElement( | ||
{ className: "xander-rules-function-begin" }, | ||
(0, _formula.IF)(config.hasOwnProperty("renderFunctionBegin"), function () { | ||
return config.renderFunctionBegin(f, depth); | ||
}, function () { | ||
return config["label" + f.name] || f.name + "("; | ||
}) | ||
"config.renderFunctionBegin(config, f, depth)," | ||
), | ||
@@ -75,3 +68,3 @@ _react2.default.createElement( | ||
f.args.map(function (d) { | ||
return renderRule(d, depth + 1); | ||
return renderRule(config, d, depth + 1); | ||
}) | ||
@@ -82,7 +75,3 @@ ), | ||
{ className: "xander-rules-function-end " }, | ||
(0, _formula.IF)(config.hasOwnProperty("renderFunctionEnd"), function () { | ||
return config.renderFunctionEnd(f, depth); | ||
}, function () { | ||
return config["labelAfter" + f.name] || ")"; | ||
}) | ||
config.renderFunctionEnd(config, f, depth) | ||
) | ||
@@ -94,3 +83,3 @@ ); | ||
function renderValue(o, depth) { | ||
function renderValue(config, o, depth) { | ||
var type = o.type, | ||
@@ -110,122 +99,24 @@ subtype = o.subtype, | ||
}, | ||
(0, _formula.IF)(subtype === "string", function () { | ||
return "\"" + value + "\""; | ||
}, subtype === "number", function () { | ||
return (0, _formula.IF)(config.hasOwnProperty("renderNumber"), function () { | ||
return config.renderNumber(value); | ||
}, config.hasOwnProperty("renderValue"), function () { | ||
return config.renderValue(value); | ||
}, value); | ||
}, subtype === "boolean", function () { | ||
return (0, _formula.IF)(config.hasOwnProperty("renderBoolean"), function () { | ||
return config.renderBoolean(value); | ||
}, config.hasOwnProperty("renderValue"), function () { | ||
return config.renderValue(value); | ||
}, value ? config.labelTRUE || "TRUE" : config.labelFALSE || "FALSE"); | ||
}, subtype === "array", function () { | ||
return (0, _formula.IF)(config.hasOwnProperty("renderArray"), function () { | ||
return config.renderArray(value); | ||
}, config.hasOwnProperty("renderValue"), function () { | ||
return config.renderValue(value); | ||
}, function () { | ||
return _react2.default.createElement( | ||
"span", | ||
null, | ||
"[", | ||
items.map(function (d) { | ||
return _react2.default.createElement( | ||
"div", | ||
{ | ||
key: key++, | ||
className: "xander-rules-value xander-rules-array" | ||
}, | ||
renderRule(d, depth + 1) | ||
); | ||
}), | ||
"]" | ||
); | ||
}); | ||
}, "error: unknown operand") | ||
); | ||
} | ||
function renderOperator(o, depth) { | ||
var subtype = o.subtype, | ||
operands = o.operands; | ||
return _react2.default.createElement( | ||
"div", | ||
{ | ||
style: (config.renderOperatorStyle || function () {})(o, depth), | ||
className: "xander-rules-section xander-rules-operator" | ||
}, | ||
(0, _formula.IF)(config.hasOwnProperty("renderOperator"), function () { | ||
return config.renderOperator(o, depth, renderRule); | ||
}, operands.length === 1, function () { | ||
(0, _formula.IF)(subtype === "string", config.renderString(value), subtype === "number", config.renderNumber(value), subtype === "boolean", config.renderBoolean(value), subtype === "array", function () { | ||
return _react2.default.createElement( | ||
"div", | ||
{ | ||
style: (config.renderOperatorStyle || function () {})(o, depth), | ||
className: "xander-rules-operator" | ||
}, | ||
_react2.default.createElement( | ||
"span", | ||
{ | ||
style: (config.renderPrefixStyle || function () {})(o, depth), | ||
className: "xander-rules-operator-" + subtype | ||
}, | ||
(0, _formula.IF)(subtype == "prefix-minus", config.labelPrefixMINUS || "-", subtype == "prefix-plus", config.labelPrefixPLUS || "+") | ||
), | ||
_react2.default.createElement( | ||
"span", | ||
{ | ||
className: "xander-rules-rhs", | ||
style: (config.renderRHSStyle || function () {})(o, depth) | ||
}, | ||
renderRule(operands[0], depth + 1) | ||
) | ||
"span", | ||
null, | ||
"[", | ||
items.map(function (d) { | ||
return _react2.default.createElement( | ||
"div", | ||
{ | ||
key: key++, | ||
className: "xander-rules-value xander-rules-array" | ||
}, | ||
renderRule(d, depth + 1) | ||
); | ||
}), | ||
"]" | ||
); | ||
}, operands.length === 2, function () { | ||
return _react2.default.createElement( | ||
"div", | ||
{ | ||
style: (config.renderOperatorStyle || function () {})(o, depth), | ||
className: "xander-rules-operator" | ||
}, | ||
_react2.default.createElement( | ||
"span", | ||
{ | ||
style: (config.renderLHSStyle || function () {})(o, depth), | ||
className: "xander-rules-lhs" | ||
}, | ||
renderRule(operands[0], depth + 1) | ||
), | ||
" ", | ||
_react2.default.createElement( | ||
"span", | ||
{ | ||
style: (config.rendeInfixStyle || function () {})(o, depth), | ||
className: "xander-rules-operator-" + subtype | ||
}, | ||
(0, _formula.IF)(subtype == "infix-eq", config.labelEQ || "=", subtype == "infix-ne", config.labelNE || "<>", subtype == "infix-gt", config.labelGT || "<", subtype == "infix-gte", config.labelGTE || "<=", subtype == "infix-lt", config.labelLE || ">", subtype == "infix-lte", config.labelLTE || ">=", subtype == "infix-add", config.labelADD || "+", subtype == "infix-subtract", config.labelSUB || "-", subtype == "infix-multiply", config.labelMUL || "*", subtype == "infix-divide", config.labelDIV || "/", subtype == "infix-power", config.labelMUL || "^", subtype == "infix-concat", config.labelMUL || "&", config.labelDefault || "huh?") | ||
), | ||
" ", | ||
_react2.default.createElement( | ||
"span", | ||
{ | ||
style: (config.renderRHSStyle || function () {})(o, depth), | ||
className: "xander-rules-rhs" | ||
}, | ||
renderRule(operands[1], depth + 1) | ||
) | ||
); | ||
}, _react2.default.createElement( | ||
"div", | ||
null, | ||
"unexpected number of operands!" | ||
)) | ||
}, "error: unknown operand") | ||
); | ||
} | ||
function renderGroup(g, depth) { | ||
function renderGroup(config, g, depth) { | ||
return _react2.default.createElement( | ||
@@ -244,3 +135,3 @@ "div", | ||
function renderRange(r, depth) { | ||
function renderRange(config, r, depth) { | ||
return _react2.default.createElement( | ||
@@ -264,3 +155,3 @@ "div", | ||
function renderVariable(v, depth) { | ||
function renderVariable(config, v, depth) { | ||
var scope = v.scope, | ||
@@ -289,4 +180,4 @@ name = v.name; | ||
function renderRule(ast) { | ||
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
function renderRule(config, ast) { | ||
var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; | ||
var type = ast.type, | ||
@@ -301,29 +192,19 @@ subtype = ast.subtype; | ||
}, | ||
(0, _formula.IF)(type === "group", function () { | ||
return renderGroup(ast, depth); | ||
}, type === "function", function () { | ||
return renderFunction(ast, depth); | ||
}, type === "operator", function () { | ||
return renderOperator(ast, depth); | ||
}, type === "variable", function () { | ||
return renderVariable(ast, depth); | ||
}, type === "value", function () { | ||
return renderValue(ast, depth); | ||
}, type === "range", function () { | ||
return renderRange(ast, depth); | ||
}, function () { | ||
return _react2.default.createElement( | ||
"div", | ||
null, | ||
"error: ", | ||
type | ||
); | ||
}) | ||
_formula.WALKERCONFIGDEFAULT.renderRule(config, ast, depth) | ||
); | ||
} | ||
var newConfig = (0, _formula.ASSIGN)(_formula.WALKERCONFIGDEFAULT, { | ||
renderRule: renderRule, | ||
renderVariable: renderVariable, | ||
renderRange: renderRange, | ||
renderGroup: renderGroup, | ||
renderValue: renderValue, | ||
renderFunction: renderFunction | ||
}); | ||
return _react2.default.createElement( | ||
"div", | ||
{ className: "xander-rules-formula" }, | ||
renderRule(ast) | ||
renderRule(newConfig, ast) | ||
); | ||
@@ -330,0 +211,0 @@ } |
{ | ||
"name": "xander", | ||
"version": "0.13.0", | ||
"version": "0.14.0", | ||
"description": "Single page app framework", | ||
@@ -37,4 +37,4 @@ "repository": "git+https://github.com/FormBucket/xander.git", | ||
"fluxury": "^3.1.0", | ||
"formula": "^3.2.0" | ||
"formula": "^3.4.2" | ||
} | ||
} |
51693
1162
Updatedformula@^3.4.2