From 0e600a1e59f0278044421f949cf8d2a6fd99c41d Mon Sep 17 00:00:00 2001 From: Tobe O Date: Tue, 26 Jun 2018 10:44:40 -0400 Subject: [PATCH] Add dsx,dsx_generator --- .idea/vcs.xml | 6 +++++ dsx/.gitignore | 16 ++++++++++++ dsx/dsx.iml | 15 +++++++++++ dsx/lib/dsx.dart | 7 +++++ dsx/pubspec.yaml | 1 + dsx_generator/.gitignore | 16 ++++++++++++ dsx_generator/dsx_generator.iml | 15 +++++++++++ dsx_generator/lib/src/generator.dart | 38 ++++++++++++++++++++++++++++ dsx_generator/lib/src/parser.dart | 0 dsx_generator/pubspec.yaml | 10 ++++++++ jael.iml | 2 ++ 11 files changed, 126 insertions(+) create mode 100644 .idea/vcs.xml create mode 100644 dsx/.gitignore create mode 100644 dsx/dsx.iml create mode 100644 dsx/lib/dsx.dart create mode 100644 dsx/pubspec.yaml create mode 100644 dsx_generator/.gitignore create mode 100644 dsx_generator/dsx_generator.iml create mode 100644 dsx_generator/lib/src/generator.dart create mode 100644 dsx_generator/lib/src/parser.dart create mode 100644 dsx_generator/pubspec.yaml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/dsx/.gitignore b/dsx/.gitignore new file mode 100644 index 00000000..76fd6986 --- /dev/null +++ b/dsx/.gitignore @@ -0,0 +1,16 @@ +# Created by .ignore support plugin (hsz.mobi) +### Dart template +# See https://www.dartlang.org/guides/libraries/private-files + +# Files and directories created by pub +.dart_tool/ +.packages +.pub/ +build/ +# If you're building an application, you may want to check-in your pubspec.lock +pubspec.lock + +# Directory created by dartdoc +# If you don't generate documentation locally you can remove this line. +doc/api/ + diff --git a/dsx/dsx.iml b/dsx/dsx.iml new file mode 100644 index 00000000..0854fb6e --- /dev/null +++ b/dsx/dsx.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dsx/lib/dsx.dart b/dsx/lib/dsx.dart new file mode 100644 index 00000000..bdf0126d --- /dev/null +++ b/dsx/lib/dsx.dart @@ -0,0 +1,7 @@ +class DSX { + final String template; + final String templateUrl; + final bool asDSX; + + DSX({this.template, this.templateUrl, this.asDSX: true}); +} diff --git a/dsx/pubspec.yaml b/dsx/pubspec.yaml new file mode 100644 index 00000000..42820096 --- /dev/null +++ b/dsx/pubspec.yaml @@ -0,0 +1 @@ +name: dsx \ No newline at end of file diff --git a/dsx_generator/.gitignore b/dsx_generator/.gitignore new file mode 100644 index 00000000..76fd6986 --- /dev/null +++ b/dsx_generator/.gitignore @@ -0,0 +1,16 @@ +# Created by .ignore support plugin (hsz.mobi) +### Dart template +# See https://www.dartlang.org/guides/libraries/private-files + +# Files and directories created by pub +.dart_tool/ +.packages +.pub/ +build/ +# If you're building an application, you may want to check-in your pubspec.lock +pubspec.lock + +# Directory created by dartdoc +# If you don't generate documentation locally you can remove this line. +doc/api/ + diff --git a/dsx_generator/dsx_generator.iml b/dsx_generator/dsx_generator.iml new file mode 100644 index 00000000..ae9af975 --- /dev/null +++ b/dsx_generator/dsx_generator.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dsx_generator/lib/src/generator.dart b/dsx_generator/lib/src/generator.dart new file mode 100644 index 00000000..bd3fc518 --- /dev/null +++ b/dsx_generator/lib/src/generator.dart @@ -0,0 +1,38 @@ +import 'dart:async'; +import 'package:analyzer/dart/element/element.dart'; +import 'package:build/build.dart'; +import 'package:build/src/builder/build_step.dart'; +import 'package:code_builder/code_builder.dart'; +import 'package:dsx/dsx.dart'; +import 'package:jael/jael.dart' as jael; +import 'package:path/path.dart' as p; +import 'package:source_gen/source_gen.dart'; + +class DSXGenerator extends GeneratorForAnnotation { + @override + FutureOr generateForAnnotatedElement( + Element element, ConstantReader annotation, BuildStep buildStep) async { + var asset = buildStep.inputId; + var template = annotation.peek('template')?.stringValue, + templateUrl = annotation.peek('templateUrl')?.stringValue; + Library lib; + + if (template != null) { + lib = generateForDocument( + jael.parseDocument(template, sourceUrl: asset.uri), element); + } else if (templateUrl != null) { + var id = + new AssetId(asset.package, p.relative(templateUrl, from: asset.path)); + lib = generateForDocument( + jael.parseDocument(await buildStep.readAsString(id), + sourceUrl: asset.uri), + element); + } else { + throw '@DSX() cannot be called without a `template` or `templateUrl`.'; + } + + return lib.accept(new DartEmitter()).toString(); + } + + Library generateForDocument(jael.Document document, ClassElement clazz) {} +} diff --git a/dsx_generator/lib/src/parser.dart b/dsx_generator/lib/src/parser.dart new file mode 100644 index 00000000..e69de29b diff --git a/dsx_generator/pubspec.yaml b/dsx_generator/pubspec.yaml new file mode 100644 index 00000000..b4913554 --- /dev/null +++ b/dsx_generator/pubspec.yaml @@ -0,0 +1,10 @@ +name: dsx_generator +dependencies: + build_config: ^0.3.0 + code_builder: ^3.0.0 + dsx: + path: ../dsx + jael: ^1.0.0 + recase: ^1.0.0 + string_scanner: ^1.0.0 + source_gen: ^0.8.0 \ No newline at end of file diff --git a/jael.iml b/jael.iml index a6e113de..cef8c4b3 100644 --- a/jael.iml +++ b/jael.iml @@ -10,6 +10,8 @@ + +