getMatchingElementTemplate method

String getMatchingElementTemplate()

Gets a template string for an element that matches the selector.

Implementation

String getMatchingElementTemplate() {
  final attributeBuffer = StringBuffer();
  final tagName = element ?? 'div';

  if (classNames.isNotEmpty) {
    attributeBuffer
      ..write(' class="')
      ..write(classNames.join(' '))
      ..write('"');
  }

  for (var attr in attrs) {
    attributeBuffer
      ..write(' ')
      ..write(attr.name);
    if (attr.value != null) {
      attributeBuffer
        ..write('="')
        ..write(attr.value)
        ..write('"');
    }
  }
  return (getHtmlTagDefinition(tagName).isVoid)
      ? '<$tagName$attributeBuffer>'
      : '<$tagName$attributeBuffer></$tagName>';
}