Skip to content

Commit 9cbf4e1

Browse files
committed
Deprecate IO operations
1 parent 477530a commit 9cbf4e1

File tree

5 files changed

+31
-200
lines changed

5 files changed

+31
-200
lines changed

lib/src/inspector.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:traindown/src/formatter.dart';
12
import 'package:traindown/src/metadata.dart';
23
import 'package:traindown/src/movement.dart';
34
import 'package:traindown/src/performance.dart';
@@ -28,6 +29,22 @@ class Inspector {
2829
TraindownScope.performance: 2
2930
};
3031

32+
/// Export all Sessions as a single Traindown string. Good for dumping
33+
/// and sharing.
34+
///
35+
/// For details on the optional parameters, see Formatter.
36+
String export(
37+
{String indenter = ' ',
38+
String linebreaker = '\r\n',
39+
String spacer = ' '}) {
40+
Formatter formatter =
41+
Formatter(indenter: indenter, linebreaker: linebreaker, spacer: spacer);
42+
StringBuffer buffer = StringBuffer();
43+
sessions.forEach((s) => buffer
44+
.write('${formatter.format(s.tokens)}${formatter.linebreaker * 2}'));
45+
return buffer.toString().trim();
46+
}
47+
3148
/// Map keyed by string that contains all seen values of the given key.
3249
Map<String, Set<String>> metadataByKey(
3350
[TraindownScope scope = TraindownScope.session]) {

lib/src/session_io.dart

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

lib/traindown.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,3 @@ export "src/presenters/html_presenter.dart";
1010
export "src/presenters/json_presenter.dart";
1111
export "src/session.dart";
1212
export "src/token.dart";
13-
14-
/// To enable a JS target, we conditionally add the IO bits here.
15-
export "" if (dart.library.io) "src/session_io.dart";

test/inspector_test.dart

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import 'dart:io';
33
import 'package:test/test.dart';
44

55
import 'package:traindown/src/inspector.dart';
6+
import 'package:traindown/src/parser.dart';
67
import 'package:traindown/src/session.dart';
7-
import 'package:traindown/src/session_io.dart';
88
import 'package:traindown/src/token.dart';
99

1010
void main() {
@@ -23,8 +23,12 @@ void main() {
2323
});
2424

2525
group('metadataByKey', () {
26-
List<File> files = [File('./example/example.traindown')];
27-
Inspector subject = SessionIO.inspectorFromFiles(files);
26+
File file = File("./example/example.traindown");
27+
String src = file.readAsStringSync();
28+
Parser parser = Parser(src);
29+
Session session = Session(parser.tokens());
30+
31+
Inspector subject = Inspector([session]);
2832

2933
Map<String, Set<String>> expected = {
3034
"bw": {"230"},
@@ -62,8 +66,13 @@ void main() {
6266

6367
group('movementNames', () {
6468
test('Basic use', () {
65-
List<File> files = [File('./example/example.traindown')];
66-
Inspector subject = SessionIO.inspectorFromFiles(files);
69+
File file = File("./example/example.traindown");
70+
String src = file.readAsStringSync();
71+
Parser parser = Parser(src);
72+
Session session = Session(parser.tokens());
73+
74+
Inspector subject = Inspector([session]);
75+
6776
List<String> movementNames = subject.movementNames;
6877
expect(movementNames.length, 5);
6978
expect(movementNames[0], equals('movement 1'));

test/session_io_test.dart

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

0 commit comments

Comments
 (0)