platform/packages/jael/jael2/README.md

54 lines
1.5 KiB
Markdown
Raw Normal View History

2021-05-15 09:38:15 +00:00
# angel3_jael_engine
[![version](https://img.shields.io/badge/pub-v4.0.0-brightgreen)](https://pub.dartlang.org/packages/jael3)
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/jael/jael/LICENSE)
2017-09-29 22:39:37 +00:00
A simple server-side HTML templating engine for Dart.
2019-07-29 22:01:24 +00:00
[See documentation.](https://docs.angel-dart.dev/packages/front-end/jael)
2017-09-29 22:39:37 +00:00
# Installation
In your `pubspec.yaml`:
```yaml
dependencies:
2021-05-15 09:38:15 +00:00
jael3: ^4.0.0
2017-09-29 22:39:37 +00:00
```
# API
The core `jael` package exports classes for parsing Jael templates,
an AST library, and a `Renderer` class that generates HTML on-the-fly.
```dart
2021-05-15 09:38:15 +00:00
import 'package:angel3_code_buffer/code_buffer.dart';
import 'package:jael3/jael.dart' as jael;
import 'package:angel3_symbol_table/symbol_table.dart';
2017-09-29 22:39:37 +00:00
void myFunction() {
const template = '''
<html>
<body>
<h1>Hello</h1>
<img src=profile['avatar']>
</body>
</html>
''';
2019-07-29 22:12:52 +00:00
var buf = CodeBuffer();
2019-07-29 22:01:24 +00:00
var document = jael.parseDocument(template, sourceUrl: 'test.jael', asDSX: false);
2019-07-29 22:12:52 +00:00
var scope = SymbolTable(values: {
2017-09-29 22:39:37 +00:00
'profile': {
'avatar': 'thosakwe.png',
}
});
const jael.Renderer().render(document, buf, scope);
print(buf);
}
```
Pre-processing (i.e. handling of blocks and includes) is handled
2018-11-11 01:54:14 +00:00
by `package:jael_preprocessor.`.