import 'dart:math'; import 'package:code_buffer/code_buffer.dart'; import 'package:jael/jael.dart' as jael; import 'package:symbol_table/symbol_table.dart'; import 'package:test/test.dart'; void main() { test('render into div', () { var template = '''
The square root of {{ n }} is {{ sqrt(n).toInt() }}.
'''; var html = render(template, {'sqrt': sqrt}); print(html); expect(html, '''
The square root of 16 is 4.
'''.trim()); }); test('render into explicit tag name', () { var template = '''
The square root of {{ n }} is {{ sqrt(n).toInt() }}.
'''; var html = render(template, {'sqrt': sqrt}); print(html); expect(html, '''
The square root of 16 is 4.
'''.trim()); }); test('render without tag name', () { var template = '''
The square root of {{ n }} is {{ sqrt(n).toInt() }}.
'''; var html = render(template, {'sqrt': sqrt}); print(html); expect(html, '''
The square root of 16 is 4.
'''.trim()); }); } String render(String template, [Map values]) { var doc = jael.parseDocument(template, onError: (e) => throw e); var buffer = new CodeBuffer(); const jael.Renderer().render(doc, buffer, new SymbolTable(values: values)); return buffer.toString(); }