indenting_buffer

Pub build status

A StringBuffer derivative that supports indentation.

Usage

Example of writing a nicely-formatted function:

main() {  
    var js = new IndentingBuffer()..writeln('function main() {');
    js.indent()
      ..writeln('var x = "Hello, world!";')
      ..writeln('window.alert(x);');
    js.outdent().writeln('}');
    print(js);
}

Output:

function main() {
  var x = "Hello, world!";
  window.alert(x);
}

You can write text that ignores indentation:

direct() => buf.withoutIndentation('<some-text>');

Libraries

indenting_buffer