diff --git a/jael/lib/src/ast/conditional.dart b/jael/lib/src/ast/conditional.dart index c3697d84..c54f6358 100644 --- a/jael/lib/src/ast/conditional.dart +++ b/jael/lib/src/ast/conditional.dart @@ -20,8 +20,12 @@ class Conditional extends Expression { @override compute(scope) { - return (condition.compute(scope) == true) - ? ifTrue.compute(scope) - : ifFalse.compute(scope); + var v = condition.compute(scope) as bool; + + if (scope.resolve('!strict!')?.value == false) { + v = v == true; + } + + return v ? ifTrue.compute(scope) : ifFalse.compute(scope); } } diff --git a/jael/lib/src/ast/expression.dart b/jael/lib/src/ast/expression.dart index 24b0e7b4..0e0f8147 100644 --- a/jael/lib/src/ast/expression.dart +++ b/jael/lib/src/ast/expression.dart @@ -22,6 +22,12 @@ class Negation extends Expression { @override compute(SymbolTable scope) { - return !(expression.compute(scope) == true); + var v = expression.compute(scope) as bool; + + if (scope.resolve('!strict!')?.value == false) { + v = v == true; + } + + return !v; } } diff --git a/jael/test/render/custom_element_test.dart b/jael/test/render/custom_element_test.dart new file mode 100644 index 00000000..6b2f6932 --- /dev/null +++ b/jael/test/render/custom_element_test.dart @@ -0,0 +1,25 @@ +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) }}. + + + '''; + + var html = render(template, {'sqrt': sqrt}); + }); +} + +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(); +} \ No newline at end of file