Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit 387dd3e

Browse files
authored
Follow the example/* syntax for the new pub site. (#170)
1 parent af23951 commit 387dd3e

File tree

4 files changed

+57
-39
lines changed

4 files changed

+57
-39
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ will be on a best-effort basis.
3232
3333
`code_builder` has a narrow and user-friendly API.
3434
35+
See the `example` and `test` folders for additional examples.
36+
3537
For example creating a class with a method:
3638
3739
```dart

example/animal.dart

Lines changed: 0 additions & 18 deletions
This file was deleted.

example/example.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:code_builder/code_builder.dart';
6+
import 'package:dart_style/dart_style.dart';
7+
8+
final _dartfmt = new DartFormatter();
9+
10+
void main() {
11+
print('animalClass():\n${'=' * 40}\n${animalClass()}');
12+
print('scopedLibrary():\n${'=' * 40}\n${scopedLibrary()}');
13+
}
14+
15+
/// Outputs:
16+
///
17+
/// ```dart
18+
/// class Animal extends Organism {
19+
/// void eat() => print('Yum!');
20+
/// }
21+
/// ```
22+
String animalClass() {
23+
final animal = new Class((b) => b
24+
..name = 'Animal'
25+
..extend = refer('Organism')
26+
..methods.add(new Method.returnsVoid((b) => b
27+
..name = 'eat'
28+
..lambda = null
29+
..body = refer('print').call([literalString('Yum!')]).code)));
30+
return _dartfmt.format('${animal.accept(new DartEmitter())}');
31+
}
32+
33+
/// Outputs:
34+
///
35+
/// ```dart
36+
/// import 'package:a/a.dart' as _i1;
37+
/// import 'package:b/b.dart' as _i2;
38+
///
39+
/// _i1.Thing doThing() {}
40+
/// _i2.Other doOther() {}
41+
/// ```
42+
String scopedLibrary() {
43+
final methods = [
44+
new Method((b) => b
45+
..body = const Code('')
46+
..name = 'doThing'
47+
..returns = refer('Thing', 'package:a/a.dart')),
48+
new Method((b) => b
49+
..body = const Code('')
50+
..name = 'doOther'
51+
..returns = refer('Other', 'package:b/b.dart')),
52+
];
53+
final library = new Library((b) => b.body.addAll(methods));
54+
return _dartfmt.format('${library.accept(new DartEmitter.scoped())}');
55+
}

example/scope.dart

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)