renderIf method

void renderIf(
  1. Element element,
  2. CodeBuffer buffer,
  3. SymbolTable scope,
  4. bool html5,
)

Implementation

void renderIf(
    Element element, CodeBuffer buffer, SymbolTable scope, bool html5) {
  var attribute = element.attributes.singleWhere((a) => a.name == 'if');

  var vv = attribute.value!.compute(scope);

  if (scope.resolve('!strict!')?.value == false) {
    vv = vv == true;
  }

  var v = vv as bool;

  if (!v) return;

  var otherAttributes = element.attributes.where((a) => a.name != 'if');
  late Element strippedElement;

  if (element is SelfClosingElement) {
    strippedElement = SelfClosingElement(element.lt, element.tagName,
        otherAttributes, element.slash, element.gt);
  } else if (element is RegularElement) {
    strippedElement = RegularElement(
        element.lt,
        element.tagName,
        otherAttributes,
        element.gt,
        element.children,
        element.lt2,
        element.slash,
        element.tagName2,
        element.gt2);
  }

  renderElement(strippedElement, buffer, scope, html5);
}