Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
## 0.4.0

- Allow to set a master template within a template.
```dart
@template
void _productTemplate(Product product) {
// ... the template

// Call this to automatically wrap productTemplate in the pageTemplate
template.master = (body) => pageTemplate(title: product.name, body: body);
}

@template
void _pageTemplate({required String title, required TrustedHtml body}) {
'''
<html>
<head><title>$title</title></head>
<body>$body</body>
</html>
''';
}

```

## 0.3.1

- Upgrade dependencies
Expand Down
10 changes: 8 additions & 2 deletions example/lib/condition.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion example/lib/css_classes.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions example/lib/loop.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions example/lib/main.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions example/lib/master_details.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'package:html_template/html_template.dart';

part 'master_details.g.dart';

// ignore_for_file: unnecessary_statements

@template
void _productTemplate(Product product) {
'''
<img *if="${product.icon != null}" src="${product.icon}" />
<h1 [class.new]="${product.isNew}">$product</h1>
''';

template.master = (body) => master(title: product.name, body: body);
}

@template
void _master({required String title, required TrustedHtml body}) {
'<!doctype html>';
'''
<html>
<head>
<title>$title</title>
</head>
<body>
$body
</body>
</html>
''';
}

class Product {
bool get isNew => false;
String? get icon => '';
String get name => '';
}
66 changes: 66 additions & 0 deletions example/lib/master_details.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion example/lib/multiple_literals.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions example/lib/nested.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion example/lib/switch.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.3.1"
version: "0.4.0"
http:
dependency: transitive
description:
Expand Down
35 changes: 28 additions & 7 deletions example/test/template_test.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/src/annotation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class TemplateAnnotation {
Iterable<T> nonNullIterable<T>(Iterable<T>? iterable) => iterable ?? const [];

bool nonNullBool(bool? value) => value ?? false;

// ignore: avoid_setters_without_getters
set master(void Function(TrustedHtml body) template) {}
}

/// The annotation to put on a private method to activate the builder on it.
Expand Down
Loading