Updated jael_preprocessor
This commit is contained in:
parent
bb6fa4bec1
commit
38e38c4a84
6 changed files with 31 additions and 24 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
# 4.0.1
|
||||||
|
* Resolved static analysis warnings
|
||||||
|
|
||||||
# 4.0.0
|
# 4.0.0
|
||||||
* Migrated to support Dart SDK 2.12.x NNBD
|
* Migrated to support Dart SDK 2.12.x NNBD
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# jael3_preprocessor
|
# jael3_preprocessor
|
||||||
[![version](https://img.shields.io/badge/pub-v4.0.0-brightgreen)](https://pub.dartlang.org/packages/jael3_preprocessor)
|
[![version](https://img.shields.io/badge/pub-v4.0.1-brightgreen)](https://pub.dartlang.org/packages/jael3_preprocessor)
|
||||||
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
[![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)
|
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
include: package:pedantic/analysis_options.yaml
|
||||||
analyzer:
|
analyzer:
|
||||||
strong-mode:
|
strong-mode:
|
||||||
implicit-casts: false
|
implicit-casts: false
|
|
@ -5,7 +5,7 @@ import 'package:jael3/jael3.dart' as jael;
|
||||||
import 'package:jael3_preprocessor/jael3_preprocessor.dart' as jael;
|
import 'package:jael3_preprocessor/jael3_preprocessor.dart' as jael;
|
||||||
|
|
||||||
Future<jael.Document?> process(
|
Future<jael.Document?> process(
|
||||||
jael.Document doc, Directory dir, errorHandler(jael.JaelError e)) {
|
jael.Document doc, Directory dir, Function(jael.JaelError e) errorHandler) {
|
||||||
return jael.resolve(doc, dir, onError: errorHandler, patch: [
|
return jael.resolve(doc, dir, onError: errorHandler, patch: [
|
||||||
(doc, dir, onError) {
|
(doc, dir, onError) {
|
||||||
print(doc!.root.children.length);
|
print(doc!.root.children.length);
|
||||||
|
|
|
@ -6,15 +6,15 @@ import 'package:jael3/jael3.dart';
|
||||||
import 'package:angel3_symbol_table/angel3_symbol_table.dart';
|
import 'package:angel3_symbol_table/angel3_symbol_table.dart';
|
||||||
|
|
||||||
/// Modifies a Jael document.
|
/// Modifies a Jael document.
|
||||||
typedef FutureOr<Document>? Patcher(Document? document,
|
typedef Patcher = FutureOr<Document>? Function(Document? document,
|
||||||
Directory currentDirectory, void onError(JaelError error)?);
|
Directory currentDirectory, void Function(JaelError error)? onError);
|
||||||
|
|
||||||
/// Expands all `block[name]` tags within the template, replacing them with the correct content.
|
/// Expands all `block[name]` tags within the template, replacing them with the correct content.
|
||||||
///
|
///
|
||||||
/// To apply additional patches to resolved documents, provide a set of [patch]
|
/// To apply additional patches to resolved documents, provide a set of [patch]
|
||||||
/// functions.
|
/// functions.
|
||||||
Future<Document?> resolve(Document document, Directory currentDirectory,
|
Future<Document?> resolve(Document document, Directory currentDirectory,
|
||||||
{void onError(JaelError error)?, Iterable<Patcher>? patch}) async {
|
{void Function(JaelError error)? onError, Iterable<Patcher>? patch}) async {
|
||||||
onError ?? (e) => throw e;
|
onError ?? (e) => throw e;
|
||||||
|
|
||||||
// Resolve all includes...
|
// Resolve all includes...
|
||||||
|
@ -24,7 +24,9 @@ Future<Document?> resolve(Document document, Directory currentDirectory,
|
||||||
var patched = await applyInheritance(
|
var patched = await applyInheritance(
|
||||||
includesResolved, currentDirectory, onError, patch);
|
includesResolved, currentDirectory, onError, patch);
|
||||||
|
|
||||||
if (patch?.isNotEmpty != true) return patched;
|
if (patch?.isNotEmpty != true) {
|
||||||
|
return patched;
|
||||||
|
}
|
||||||
|
|
||||||
for (var p in patch!) {
|
for (var p in patch!) {
|
||||||
patched = await p(patched, currentDirectory, onError);
|
patched = await p(patched, currentDirectory, onError);
|
||||||
|
@ -37,7 +39,7 @@ Future<Document?> resolve(Document document, Directory currentDirectory,
|
||||||
Future<Document?> applyInheritance(
|
Future<Document?> applyInheritance(
|
||||||
Document? document,
|
Document? document,
|
||||||
Directory currentDirectory,
|
Directory currentDirectory,
|
||||||
void onError(JaelError error)?,
|
void Function(JaelError error)? onError,
|
||||||
Iterable<Patcher>? patch) async {
|
Iterable<Patcher>? patch) async {
|
||||||
if (document == null) {
|
if (document == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -102,7 +104,7 @@ Future<Document?> applyInheritance(
|
||||||
while (hierarchy!.extendsTemplates.isNotEmpty) {
|
while (hierarchy!.extendsTemplates.isNotEmpty) {
|
||||||
var tmpl = hierarchy.extendsTemplates.removeFirst();
|
var tmpl = hierarchy.extendsTemplates.removeFirst();
|
||||||
var definedOverrides = findBlockOverrides(tmpl, onError);
|
var definedOverrides = findBlockOverrides(tmpl, onError);
|
||||||
if (definedOverrides == null) break;
|
//if (definedOverrides == null) break;
|
||||||
out =
|
out =
|
||||||
setOut(out!, definedOverrides, hierarchy.extendsTemplates.isNotEmpty);
|
setOut(out!, definedOverrides, hierarchy.extendsTemplates.isNotEmpty);
|
||||||
}
|
}
|
||||||
|
@ -117,7 +119,7 @@ Future<Document?> applyInheritance(
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, RegularElement> findBlockOverrides(
|
Map<String, RegularElement> findBlockOverrides(
|
||||||
Element tmpl, void onError(JaelError e)?) {
|
Element tmpl, void Function(JaelError e)? onError) {
|
||||||
var out = <String, RegularElement>{};
|
var out = <String, RegularElement>{};
|
||||||
|
|
||||||
for (var child in tmpl.children) {
|
for (var child in tmpl.children) {
|
||||||
|
@ -137,7 +139,7 @@ Map<String, RegularElement> findBlockOverrides(
|
||||||
|
|
||||||
/// Resolves the document hierarchy at a given node in the tree.
|
/// Resolves the document hierarchy at a given node in the tree.
|
||||||
Future<DocumentHierarchy?> resolveHierarchy(Document document,
|
Future<DocumentHierarchy?> resolveHierarchy(Document document,
|
||||||
Directory currentDirectory, void onError(JaelError e)?) async {
|
Directory currentDirectory, void Function(JaelError e)? onError) async {
|
||||||
var extendsTemplates = Queue<Element>();
|
var extendsTemplates = Queue<Element>();
|
||||||
String? parent;
|
String? parent;
|
||||||
|
|
||||||
|
@ -175,7 +177,7 @@ class DocumentHierarchy {
|
||||||
Iterable<ElementChild> replaceBlocks(
|
Iterable<ElementChild> replaceBlocks(
|
||||||
Element element,
|
Element element,
|
||||||
Map<String?, RegularElement> definedOverrides,
|
Map<String?, RegularElement> definedOverrides,
|
||||||
void onError(JaelError e)?,
|
void Function(JaelError e)? onError,
|
||||||
bool replaceWithDefault,
|
bool replaceWithDefault,
|
||||||
bool anyTemplatesRemain) {
|
bool anyTemplatesRemain) {
|
||||||
if (element.tagName.name == 'block') {
|
if (element.tagName.name == 'block') {
|
||||||
|
@ -234,7 +236,7 @@ Iterable<ElementChild> replaceBlocks(
|
||||||
Element replaceChildrenOfElement(
|
Element replaceChildrenOfElement(
|
||||||
Element el,
|
Element el,
|
||||||
Map<String, RegularElement> definedOverrides,
|
Map<String, RegularElement> definedOverrides,
|
||||||
void onError(JaelError e)?,
|
void Function(JaelError e)? onError,
|
||||||
bool replaceWithDefault,
|
bool replaceWithDefault,
|
||||||
bool anyTemplatesRemain) {
|
bool anyTemplatesRemain) {
|
||||||
if (el is RegularElement) {
|
if (el is RegularElement) {
|
||||||
|
@ -248,7 +250,7 @@ Element replaceChildrenOfElement(
|
||||||
RegularElement replaceChildrenOfRegularElement(
|
RegularElement replaceChildrenOfRegularElement(
|
||||||
RegularElement el,
|
RegularElement el,
|
||||||
Map<String?, RegularElement> definedOverrides,
|
Map<String?, RegularElement> definedOverrides,
|
||||||
void onError(JaelError e)?,
|
void Function(JaelError e)? onError,
|
||||||
bool replaceWithDefault,
|
bool replaceWithDefault,
|
||||||
bool anyTemplatesRemain) {
|
bool anyTemplatesRemain) {
|
||||||
var children = allChildrenOfRegularElement(
|
var children = allChildrenOfRegularElement(
|
||||||
|
@ -260,7 +262,7 @@ RegularElement replaceChildrenOfRegularElement(
|
||||||
List<ElementChild> allChildrenOfRegularElement(
|
List<ElementChild> allChildrenOfRegularElement(
|
||||||
RegularElement el,
|
RegularElement el,
|
||||||
Map<String?, RegularElement> definedOverrides,
|
Map<String?, RegularElement> definedOverrides,
|
||||||
void onError(JaelError e)?,
|
void Function(JaelError e)? onError,
|
||||||
bool replaceWithDefault,
|
bool replaceWithDefault,
|
||||||
bool anyTemplatesRemain) {
|
bool anyTemplatesRemain) {
|
||||||
var children = <ElementChild>[];
|
var children = <ElementChild>[];
|
||||||
|
@ -278,7 +280,7 @@ List<ElementChild> allChildrenOfRegularElement(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds the name of the parent template.
|
/// Finds the name of the parent template.
|
||||||
String? getParent(Document document, void onError(JaelError error)?) {
|
String? getParent(Document document, void Function(JaelError error)? onError) {
|
||||||
var element = document.root;
|
var element = document.root;
|
||||||
if (element.tagName.name != 'extend') return null;
|
if (element.tagName.name != 'extend') return null;
|
||||||
|
|
||||||
|
@ -300,11 +302,11 @@ String? getParent(Document document, void onError(JaelError error)?) {
|
||||||
|
|
||||||
/// Expands all `include[src]` tags within the template, and fills in the content of referenced files.
|
/// Expands all `include[src]` tags within the template, and fills in the content of referenced files.
|
||||||
Future<Document?> resolveIncludes(Document? document,
|
Future<Document?> resolveIncludes(Document? document,
|
||||||
Directory currentDirectory, void onError(JaelError error)?) async {
|
Directory currentDirectory, void Function(JaelError error)? onError) async {
|
||||||
if (document == null) {
|
if (document == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Element? rootElement =
|
var rootElement =
|
||||||
await _expandIncludes(document.root, currentDirectory, onError);
|
await _expandIncludes(document.root, currentDirectory, onError);
|
||||||
if (rootElement != null) {
|
if (rootElement != null) {
|
||||||
return Document(document.doctype, rootElement);
|
return Document(document.doctype, rootElement);
|
||||||
|
@ -314,16 +316,16 @@ Future<Document?> resolveIncludes(Document? document,
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Element?> _expandIncludes(Element element, Directory currentDirectory,
|
Future<Element?> _expandIncludes(Element element, Directory currentDirectory,
|
||||||
void onError(JaelError error)?) async {
|
void Function(JaelError error)? onError) async {
|
||||||
if (element.tagName.name != 'include') {
|
if (element.tagName.name != 'include') {
|
||||||
if (element is SelfClosingElement)
|
if (element is SelfClosingElement) {
|
||||||
return element;
|
return element;
|
||||||
else if (element is RegularElement) {
|
} else if (element is RegularElement) {
|
||||||
List<ElementChild> expanded = [];
|
var expanded = <ElementChild>[];
|
||||||
|
|
||||||
for (var child in element.children) {
|
for (var child in element.children) {
|
||||||
if (child is Element) {
|
if (child is Element) {
|
||||||
Element? includeElement =
|
var includeElement =
|
||||||
await _expandIncludes(child, currentDirectory, onError);
|
await _expandIncludes(child, currentDirectory, onError);
|
||||||
if (includeElement != null) {
|
if (includeElement != null) {
|
||||||
expanded.add(includeElement);
|
expanded.add(includeElement);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: jael3_preprocessor
|
name: jael3_preprocessor
|
||||||
version: 4.0.0
|
version: 4.0.1
|
||||||
description: A pre-processor for resolving blocks and includes within Jael templates.
|
description: A pre-processor for resolving blocks and includes within Jael templates.
|
||||||
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/jael/jael_preprocessor
|
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/jael/jael_preprocessor
|
||||||
environment:
|
environment:
|
||||||
|
@ -12,3 +12,4 @@ dependencies:
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
angel3_code_buffer: ^2.0.0
|
angel3_code_buffer: ^2.0.0
|
||||||
test: ^1.17.4
|
test: ^1.17.4
|
||||||
|
pedantic: ^1.11.0
|
||||||
|
|
Loading…
Reference in a new issue