Add dsx,dsx_generator
This commit is contained in:
parent
314c972cb0
commit
0e600a1e59
11 changed files with 126 additions and 0 deletions
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
16
dsx/.gitignore
vendored
Normal file
16
dsx/.gitignore
vendored
Normal file
|
@ -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/
|
||||
|
15
dsx/dsx.iml
Normal file
15
dsx/dsx.iml
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Dart SDK" level="project" />
|
||||
<orderEntry type="library" name="Dart Packages" level="project" />
|
||||
</component>
|
||||
</module>
|
7
dsx/lib/dsx.dart
Normal file
7
dsx/lib/dsx.dart
Normal file
|
@ -0,0 +1,7 @@
|
|||
class DSX {
|
||||
final String template;
|
||||
final String templateUrl;
|
||||
final bool asDSX;
|
||||
|
||||
DSX({this.template, this.templateUrl, this.asDSX: true});
|
||||
}
|
1
dsx/pubspec.yaml
Normal file
1
dsx/pubspec.yaml
Normal file
|
@ -0,0 +1 @@
|
|||
name: dsx
|
16
dsx_generator/.gitignore
vendored
Normal file
16
dsx_generator/.gitignore
vendored
Normal file
|
@ -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/
|
||||
|
15
dsx_generator/dsx_generator.iml
Normal file
15
dsx_generator/dsx_generator.iml
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Dart SDK" level="project" />
|
||||
<orderEntry type="library" name="Dart Packages" level="project" />
|
||||
</component>
|
||||
</module>
|
38
dsx_generator/lib/src/generator.dart
Normal file
38
dsx_generator/lib/src/generator.dart
Normal file
|
@ -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<DSX> {
|
||||
@override
|
||||
FutureOr<String> 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) {}
|
||||
}
|
0
dsx_generator/lib/src/parser.dart
Normal file
0
dsx_generator/lib/src/parser.dart
Normal file
10
dsx_generator/pubspec.yaml
Normal file
10
dsx_generator/pubspec.yaml
Normal file
|
@ -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
|
2
jael.iml
2
jael.iml
|
@ -10,6 +10,8 @@
|
|||
<excludeFolder url="file://$MODULE_DIR$/build_jael/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build_jael/build" />
|
||||
</content>
|
||||
<content url="file://$MODULE_DIR$/dsx" />
|
||||
<content url="file://$MODULE_DIR$/dsx_generator" />
|
||||
<content url="file://$MODULE_DIR$/jael">
|
||||
<excludeFolder url="file://$MODULE_DIR$/jael/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/jael/build" />
|
||||
|
|
Loading…
Reference in a new issue