From f8fd0e0a0ad2f5526c8098137b3f943719bacdf8 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Tue, 3 Apr 2018 11:29:35 -0400 Subject: [PATCH] README, CHANGELOG --- build_jael/.gitignore | 3 ++- build_jael/CHANGELOG.md | 2 ++ build_jael/README.md | 44 ++++++++++++++++++++++++++++++++++ build_jael/build.yaml | 13 ++++------ build_jael/example/hello.jl | 12 ++++++++++ build_jael/lib/build_jael.dart | 28 +++++++++++++++++++--- build_jael/pubspec.yaml | 4 +++- 7 files changed, 92 insertions(+), 14 deletions(-) create mode 100644 build_jael/CHANGELOG.md create mode 100644 build_jael/README.md create mode 100644 build_jael/example/hello.jl diff --git a/build_jael/.gitignore b/build_jael/.gitignore index 9afb070e..69d2288e 100644 --- a/build_jael/.gitignore +++ b/build_jael/.gitignore @@ -12,4 +12,5 @@ pubspec.lock # Directory created by dartdoc # If you don't generate documentation locally you can remove this line. doc/api/ -.dart_tool \ No newline at end of file +.dart_tool +*.html \ No newline at end of file diff --git a/build_jael/CHANGELOG.md b/build_jael/CHANGELOG.md new file mode 100644 index 00000000..92642921 --- /dev/null +++ b/build_jael/CHANGELOG.md @@ -0,0 +1,2 @@ +# 1.0.0 +* Initial version. \ No newline at end of file diff --git a/build_jael/README.md b/build_jael/README.md new file mode 100644 index 00000000..6a22c948 --- /dev/null +++ b/build_jael/README.md @@ -0,0 +1,44 @@ +# build_jael +[![Pub](https://img.shields.io/pub/v/build_jael.svg)](https://pub.dartlang.org/packages/build_jael) +[![build status](https://travis-ci.org/angel-dart/jael.svg)](https://travis-ci.org/angel-dart/jael) + + +Compile Jael files to HTML using the power of `package:build`. + +# Installation +In your `pubspec.yaml`: + +```yaml +dependencies: + build_jael: ^1.0.0 +dev_dependencies: + build_runner: ^0.7.0 +``` + +# Usage +You can run `pub run build_runner serve` to incrementally build Jael templates, +and run an HTTP server. + +For further customization, you'll need to either modify the `build.yaml` or +instantiate a `JaelBuilder` manually. + +## Defining Variables +Pass variables as `config` in `build.yaml`: + +```yaml +targets: + $default: + builders: + build_jael: + config: + foo: bar + baz: quux + one: 1.0 +``` + +## Minifying HTML +Pass `minify: true` in the build configuration to produce "minified" HTML, +without newlines or whitespace (other than where it is required). + +To apply additional transforms to parsed documents, provide a +set of `patch` functions, like in `package:jael_preprocessor`. \ No newline at end of file diff --git a/build_jael/build.yaml b/build_jael/build.yaml index 14c0a3d1..11d18ba1 100644 --- a/build_jael/build.yaml +++ b/build_jael/build.yaml @@ -9,15 +9,10 @@ builders: .jl: - ".html" required_inputs: - - .jl - defaults: - generate_for: - - "**/*.html" - - "*.html" - - "**.html" + - ".jl" targets: $default: sources: - - "**/*.html" - - "*.html" - - "**.html" \ No newline at end of file + - "**.jl" + - "*.jl" + - "**/*.jl" \ No newline at end of file diff --git a/build_jael/example/hello.jl b/build_jael/example/hello.jl new file mode 100644 index 00000000..be935f82 --- /dev/null +++ b/build_jael/example/hello.jl @@ -0,0 +1,12 @@ + + + + Hello, world! + + +

Hello!

+ + + \ No newline at end of file diff --git a/build_jael/lib/build_jael.dart b/build_jael/lib/build_jael.dart index e9f5ebf9..49003625 100644 --- a/build_jael/lib/build_jael.dart +++ b/build_jael/lib/build_jael.dart @@ -3,12 +3,16 @@ import 'package:build/build.dart'; import 'package:code_buffer/code_buffer.dart'; import 'package:file/file.dart'; import 'package:jael/jael.dart' as jael; -import 'package:jael_preprocessor/jael_preprocessor.dart'; +import 'package:jael_preprocessor/jael_preprocessor.dart' as jael; +import 'package:symbol_table/symbol_table.dart'; + +Builder jaelBuilder(BuilderOptions options) => new JaelBuilder(options); class JaelBuilder implements Builder { final BuilderOptions options; + final List patch; - const JaelBuilder(this.options); + const JaelBuilder(this.options, {this.patch: const []}); @override Map> get buildExtensions { @@ -36,6 +40,24 @@ class JaelBuilder implements Builder { onError: errors.add, ); - if (errors.isNotEmpty) {} + doc = await jael.resolve( + doc, + dir, + onError: errors.add, + patch: this.patch, + ); + + if (errors.isNotEmpty) { + jael.Renderer.errorDocument(errors, buf); + return; + } + + var scope = new SymbolTable(values: new Map.from(options.config)); + const jael.Renderer().render(doc, buf, scope); + + buildStep.writeAsString( + buildStep.inputId.changeExtension('.html'), + buf.toString(), + ); } } diff --git a/build_jael/pubspec.yaml b/build_jael/pubspec.yaml index fc73ef43..8bc6a6ef 100644 --- a/build_jael/pubspec.yaml +++ b/build_jael/pubspec.yaml @@ -12,4 +12,6 @@ dependencies: file: ^2.0.0 jael: ^1.0.0-alpha jael_preprocessor: ^1.0.0-alpha - symbol_table: ^1.0.0 \ No newline at end of file + symbol_table: ^1.0.0 +dev_dependencies: + build_runner: ^0.7.0 \ No newline at end of file