notationSiteVariables function

Map<String, Json> notationSiteVariables(
  1. Object? manifestVariables,
  2. NotationAppState? app, {
  3. void say(
    1. int line,
    2. String message
    )?,
})

The variables a site's pages read: the manifest's (manifestVariables, its variables as written) and app.txt's (app, null: no such file), as NotationOptions.projectVariables takes them. A name both declare is app.txt's, and said in say at its line of app.txt.

Implementation

Map<String, Json> notationSiteVariables(Object? manifestVariables, NotationAppState? app, {void Function(int line, String message)? say}) {
  final out = <String, Json>{
    for (final v in Variable.declarationsFromJson(manifestVariables)) v.name: {'type': v.type.name, ...v.toJson()},
  };
  if (app == null) return out;
  for (final e in app.variables.entries) {
    if (out.containsKey(e.key)) {
      say?.call(
        app.lines[e.key] ?? 1,
        '${e.key} is declared here and in site.json\'s variables: one name is one value. This one is used; take "${e.key}" out of site.json.',
      );
    }
    if (e.value.containsKey(notationInlineFormulaKey)) {
      out[e.key] = e.value;
    } else if (Variable.fromJson({...e.value, 'name': e.key}) case final v?) {
      out[e.key] = {'type': v.type.name, ...v.toJson()};
    }
  }
  return out;
}