Methods
(static) DOMcontentsubvars(element, scope) → {Element}
Substitute variables into a DOM element (works recursively on the element's children).
Ignores iframes and elements with the attribute nosubvars
.
Parameters:
Name | Type | Description |
---|---|---|
element |
Element | |
scope |
Numbas.jme.Scope |
Returns:
Type | Description |
---|---|
Element |
(static) DOMsubvars(str, scope, doc) → {Array.<Array.<Node>>}
Substitute variables into the contents of a text node. Substituted values might contain HTML elements, so the return value is a collection of DOM elements, not another string.
Parameters:
Name | Type | Description |
---|---|---|
str |
string | The contents of the text node. |
scope |
Numbas.jme.Scope | |
doc |
Document | The document the text node belongs to. |
Returns:
Type | Description |
---|---|
Array.<Array.<Node>> |
|
(static) computeRuleset(name, todo, scope, path) → {Numbas.jme.rules.Ruleset}
Collect together a ruleset, evaluating all its dependencies first.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the ruleset to evaluate. |
todo |
Object.<Array.<string>> | Dictionary of rulesets still to evaluate. |
scope |
Numbas.jme.Scope | |
path |
Array.<string> | Breadcrumbs - Rulesets names currently being evaluated, so we can detect circular dependencies. |
Returns:
Type | Description |
---|---|
Numbas.jme.rules.Ruleset |
(static) computeVariable(name, todo, scope, path, computeFnopt) → {Numbas.jme.token}
Evaluate a variable, evaluating all its dependencies first.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
string | The name of the variable to evaluate. |
||
todo |
Numbas.jme.variables.variable_data_dict | Dictionary of variables still to evaluate. |
||
scope |
Numbas.jme.Scope | |||
path |
Array.<string> | Breadcrumbs - Variable names currently being evaluated, so we can detect circular dependencies. |
||
computeFn |
function |
<optional> |
Numbas.jme.variables.computeVariable | A function to call when a dependency needs to be computed. |
Returns:
Type | Description |
---|---|
Numbas.jme.token |
(static) makeConstants(definitions, scope, enabled) → {Array.<string>}
Add a list of constants to the scope.
Parameters:
Name | Type | Description |
---|---|---|
definitions |
Array.<Numbas.jme.constant_definition> | |
scope |
Numbas.jme.Scope | |
enabled |
Object.<boolean> | For each constant name, is it enabled? If not given, then the |
Returns:
Type | Description |
---|---|
Array.<string> |
|
(static) makeFunction(def, scope, withEnv) → {Numbas.jme.funcObj}
Make a custom function.
Parameters:
Name | Type | Description |
---|---|---|
def |
Numbas.jme.variables.func_data | Contains |
scope |
Numbas.jme.Scope | |
withEnv |
object | Dictionary of local variables for javascript functions. |
Returns:
Type | Description |
---|---|
Numbas.jme.funcObj |
(static) makeFunctions(tmpFunctions, scope, withEnv) → {Object.<Numbas.jme.funcObj>}
Make up custom functions.
Parameters:
Name | Type | Description |
---|---|---|
tmpFunctions |
Array.<Numbas.jme.variables.func_data> | |
scope |
Numbas.jme.Scope | |
withEnv |
object | Dictionary of local variables for javascript functions. |
Returns:
Type | Description |
---|---|
Object.<Numbas.jme.funcObj> |
(static) makeJMEFunction(fn, scope) → {function}
Make a new function, whose definition is written in JME.
Parameters:
Name | Type | Description |
---|---|---|
fn |
object | Contains |
scope |
Numbas.jme.Scope |
Returns:
Type | Description |
---|---|
function |
|
(static) makeJavascriptFunction(fn, withEnv) → {function}
Make a new function, whose definition is written in JavaScript.
The JavaScript is wrapped with (function(<paramNames>){
and }
).
Parameters:
Name | Type | Description |
---|---|---|
fn |
object | Contains |
withEnv |
object | Dictionary of local variables for javascript functions. |
Returns:
Type | Description |
---|---|
function |
|
(static) makeRulesets(todo, scope) → {Object.<Numbas.jme.rules.Ruleset>}
Gather together a set of ruleset definitions.
Parameters:
Name | Type | Description |
---|---|---|
todo |
Object.<Array.<string>> | A dictionary mapping ruleset names to definitions. |
scope |
Numbas.jme.Scope | The scope to gather the rulesets in. The rulesets are added to this scope as a side-effect. |
Returns:
Type | Description |
---|---|
Object.<Numbas.jme.rules.Ruleset> |
A dictionary of rulesets. |
(static) makeVariables(todo, scope, condition, computeFn, targets) → {object}
Evaluate dictionary of variables.
Parameters:
Name | Type | Description |
---|---|---|
todo |
Numbas.jme.variables.variable_data_dict | Dictionary of variables mapped to their definitions. |
scope |
Numbas.jme.Scope | |
condition |
Numbas.jme.tree | Condition on the values of the variables which must be satisfied. |
computeFn |
function | A function to compute a variable. Default is Numbas.jme.variables.computeVariable. |
targets |
Array.<string> | Variables which must be re-evaluated, even if they're already present in the scope. |
Returns:
Type | Description |
---|---|
object |
|
(static) remakeVariables(todo, changed_variables, scope, computeFnopt, targets) → {Numbas.jme.Scope}
Remake a dictionary of variables, only re-evaluating variables which depend on the changed_variables.
A new scope is created with the values from changed_variables
, and then the dependent variables are evaluated in that scope.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
todo |
Numbas.jme.variables.variable_data_dict | Dictionary of variables mapped to their definitions. |
|
changed_variables |
Object.<Numbas.jme.token> | Dictionary of changed variables. These will be added to the scope, and will not be re-evaluated. |
|
scope |
Numbas.jme.Scope | ||
computeFn |
function |
<optional> |
A function to compute a variable. Default is Numbas.jme.variables.computeVariable. |
targets |
Array.<string> | Variables which must be re-evaluated, even if they're already present in the scope. |
Returns:
Type | Description |
---|---|
Numbas.jme.Scope |
(static) splitVariableNames(s) → {Array.<string>}
Split up a list of variable names separated by commas, for destructuring assignment.
Parameters:
Name | Type | Description |
---|---|---|
s |
string |
Returns:
Type | Description |
---|---|
Array.<string> |
(static) variableDependants(todo, ancestors, scope) → {object}
Given a todo dictionary of variables, return a dictionary with only the variables depending on the given list of variables.
Parameters:
Name | Type | Description |
---|---|---|
todo |
object | Dictionary of variables mapped to their definitions. |
ancestors |
Array.<string> | List of variable names whose dependants we should find. |
scope |
Numbas.jme.Scope | The scope to use for normalising names. |
Returns:
Type | Description |
---|---|
object |
|
Type Definitions
func_data
The definition of a custom JME function.
Type:
Properties:
Name | Type | Description |
---|---|---|
name |
string | |
definition |
string | Definition of the function, either in |
language |
string | Either |
outtype |
string | Name of the |
parameters |
Array.<object> | Definition of the function's calling signature: an array of objects with properties |
note_definition
A definition of a note.
The note's name, followed by an optional description enclosed in parentheses, then a colon, and finally a JME
expression to evaluate.
Type:
variable_data_dict
A dictionary describing a variable to be evaluated.
Type:
Properties:
Name | Type | Description |
---|---|---|
tree |
Numbas.jme.tree | Definition of the variable. |
vars |
Array.<string> | Names of variables this variable depends on. |