| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library barback.transformer.transform; | 5 library barback.transformer.transform; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import '../asset/asset.dart'; | 10 import '../asset/asset.dart'; |
| 11 import '../asset/asset_id.dart'; | 11 import '../asset/asset_id.dart'; |
| 12 import '../errors.dart'; | 12 import '../errors.dart'; |
| 13 import 'aggregate_transform.dart'; | 13 import 'aggregate_transform.dart'; |
| 14 import 'transform_logger.dart'; | 14 import 'transform_logger.dart'; |
| 15 | 15 |
| 16 /// Creates a new [Transform] wrapping an [AggregateTransform]. | 16 /// Creates a new [Transform] wrapping an [AggregateTransform]. |
| 17 /// | 17 /// |
| 18 /// Although barback internally works in terms of [AggregateTransformer]s, most | 18 /// Although barback internally works in terms of [AggregateTransformer]s, most |
| 19 /// transformers only work on individual primary inputs in isolation. We want to | 19 /// transformers only work on individual primary inputs in isolation. We want to |
| 20 /// allow those transformers to implement the more user-friendly [Transformer] | 20 /// allow those transformers to implement the more user-friendly [Transformer] |
| 21 /// interface which takes the more user-friendly [Transform] object. This method | 21 /// interface which takes the more user-friendly [Transform] object. This method |
| 22 /// wraps the more general [AggregateTransform] to return a [Transform] instead. | 22 /// wraps the more general [AggregateTransform] to return a [Transform] instead. |
| 23 Future<Transform> newTransform(AggregateTransform aggregate) { | 23 Future<Transform> newTransform(AggregateTransform aggregate) { |
| 24 // A wrapped [Transformer] will assign each primary input a unique transform | 24 // A wrapped [Transformer] will assign each primary input a unique transform |
| 25 // key, so we can safely get the first asset emitted. We don't want to wait | 25 // key, so we can safely get the first asset emitted. We don't want to wait |
| 26 // for the stream to close, since that requires barback to prove that no more | 26 // for the stream to close, since that requires barback to prove that no more |
| 27 // new assets will be generated. | 27 // new assets will be generated. |
| 28 return aggregate.primaryInputs.first.then((primaryInput) => | 28 return aggregate.primaryInputs.first |
| 29 new Transform._(aggregate, primaryInput)); | 29 .then((primaryInput) => new Transform._(aggregate, primaryInput)); |
| 30 } | 30 } |
| 31 | 31 |
| 32 /// While a [Transformer] represents a *kind* of transformation, this defines | 32 /// While a [Transformer] represents a *kind* of transformation, this defines |
| 33 /// one specific usage of it on a set of files. | 33 /// one specific usage of it on a set of files. |
| 34 /// | 34 /// |
| 35 /// This ephemeral object exists only during an actual transform application to | 35 /// This ephemeral object exists only during an actual transform application to |
| 36 /// facilitate communication between the [Transformer] and the code hosting | 36 /// facilitate communication between the [Transformer] and the code hosting |
| 37 /// the transformation. It lets the [Transformer] access inputs and generate | 37 /// the transformation. It lets the [Transformer] access inputs and generate |
| 38 /// outputs. | 38 /// outputs. |
| 39 class Transform { | 39 class Transform { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 95 |
| 96 /// Consume the primary input so that it doesn't get processed by future | 96 /// Consume the primary input so that it doesn't get processed by future |
| 97 /// phases or emitted once processing has finished. | 97 /// phases or emitted once processing has finished. |
| 98 /// | 98 /// |
| 99 /// Normally the primary input will automatically be forwarded unless the | 99 /// Normally the primary input will automatically be forwarded unless the |
| 100 /// transformer overwrites it by emitting an input with the same id. This | 100 /// transformer overwrites it by emitting an input with the same id. This |
| 101 /// allows the transformer to tell barback not to forward the primary input | 101 /// allows the transformer to tell barback not to forward the primary input |
| 102 /// even if it's not overwritten. | 102 /// even if it's not overwritten. |
| 103 void consumePrimary() => _aggregate.consumePrimary(primaryInput.id); | 103 void consumePrimary() => _aggregate.consumePrimary(primaryInput.id); |
| 104 } | 104 } |
| OLD | NEW |