Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1663)

Side by Side Diff: pkg/barback/lib/src/transformer.dart

Issue 223553008: Only pass an AssetId to isPrimary and declareOutputs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: pubspecs and changelogs Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/barback/lib/src/transform_node.dart ('k') | pkg/barback/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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; 5 library barback.transformer;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'asset.dart'; 9 import 'asset_id.dart';
10 import 'transform.dart'; 10 import 'transform.dart';
11 import 'utils.dart'; 11 import 'utils.dart';
12 12
13 /// A [Transformer] represents a processor that takes in one or more input 13 /// A [Transformer] represents a processor that takes in one or more input
14 /// assets and uses them to generate one or more output assets. 14 /// assets and uses them to generate one or more output assets.
15 /// 15 ///
16 /// Dart2js, a SASS->CSS processor, a CSS spriter, and a tool to concatenate 16 /// Dart2js, a SASS->CSS processor, a CSS spriter, and a tool to concatenate
17 /// files are all examples of transformers. To define your own transformation 17 /// files are all examples of transformers. To define your own transformation
18 /// step, extend (or implement) this class. 18 /// step, extend (or implement) this class.
19 /// 19 ///
(...skipping 16 matching lines...) Expand all
36 var invalidExtensions = allowedExtensions.split(" ") 36 var invalidExtensions = allowedExtensions.split(" ")
37 .where((extension) => !extension.startsWith(".")) 37 .where((extension) => !extension.startsWith("."))
38 .map((extension) => '"$extension"'); 38 .map((extension) => '"$extension"');
39 if (invalidExtensions.isEmpty) return; 39 if (invalidExtensions.isEmpty) return;
40 40
41 throw new FormatException('Each extension in $this.allowedExtensions ' 41 throw new FormatException('Each extension in $this.allowedExtensions '
42 'must begin with a ".", but ${toSentence(invalidExtensions)} ' 42 'must begin with a ".", but ${toSentence(invalidExtensions)} '
43 '${pluralize("doesn't", invalidExtensions.length, plural: "don't")}.'); 43 '${pluralize("doesn't", invalidExtensions.length, plural: "don't")}.');
44 } 44 }
45 45
46 /// Returns `true` if [input] can be a primary input for this transformer. 46 /// Returns `true` if [inputId] can be a primary input for this transformer.
47 /// 47 ///
48 /// While a transformer can read from multiple input files, one must be the 48 /// While a transformer can read from multiple input files, one must be the
49 /// "primary" input. This asset determines whether the transformation should 49 /// "primary" input. This asset determines whether the transformation should
50 /// be run at all. If the primary input is removed, the transformer will no 50 /// be run at all. If the primary input is removed, the transformer will no
51 /// longer be run. 51 /// longer be run.
52 /// 52 ///
53 /// A concrete example is dart2js. When you run dart2js, it will traverse 53 /// A concrete example is dart2js. When you run dart2js, it will traverse
54 /// all of the imports in your Dart source files and use the contents of all 54 /// all of the imports in your Dart source files and use the contents of all
55 /// of those to generate the final JS. However you still run dart2js "on" a 55 /// of those to generate the final JS. However you still run dart2js "on" a
56 /// single file: the entrypoint Dart file that has your `main()` method. 56 /// single file: the entrypoint Dart file that has your `main()` method.
57 /// This entrypoint file would be the primary input. 57 /// This entrypoint file would be the primary input.
58 /// 58 ///
59 /// If this is not overridden, defaults to allow any asset whose extension 59 /// If this is not overridden, defaults to allow any asset whose extension
60 /// matches one of the ones returned by [allowedExtensions]. If *that* is 60 /// matches one of the ones returned by [allowedExtensions]. If *that* is
61 /// not overridden, allows all assets. 61 /// not overridden, allows all assets.
62 Future<bool> isPrimary(Asset input) { 62 Future<bool> isPrimary(AssetId id) {
blois 2014/04/03 21:16:36 Make it not return a future pretty please!! (or at
nweiz 2014/04/03 21:34:18 I think we're planning to do the union type thing,
63 // Allow all files if [primaryExtensions] is not overridden. 63 // Allow all files if [primaryExtensions] is not overridden.
64 if (allowedExtensions == null) return new Future.value(true); 64 if (allowedExtensions == null) return new Future.value(true);
65 65
66 for (var extension in allowedExtensions.split(" ")) { 66 for (var extension in allowedExtensions.split(" ")) {
67 if (input.id.path.endsWith(extension)) return new Future.value(true); 67 if (id.path.endsWith(extension)) return new Future.value(true);
68 } 68 }
69 69
70 return new Future.value(false); 70 return new Future.value(false);
71 } 71 }
72 72
73 /// Run this transformer on on the primary input specified by [transform]. 73 /// Run this transformer on on the primary input specified by [transform].
74 /// 74 ///
75 /// The [transform] is used by the [Transformer] for two purposes (in 75 /// The [transform] is used by the [Transformer] for two purposes (in
76 /// addition to accessing the primary input). It can call `getInput()` to 76 /// addition to accessing the primary input). It can call `getInput()` to
77 /// request additional input assets. It also calls `addOutput()` to provide 77 /// request additional input assets. It also calls `addOutput()` to provide
78 /// generated assets back to the system. Either can be called multiple times, 78 /// generated assets back to the system. Either can be called multiple times,
79 /// in any order. 79 /// in any order.
80 /// 80 ///
81 /// In other words, a Transformer's job is to find all inputs for a 81 /// In other words, a Transformer's job is to find all inputs for a
82 /// transform, starting at the primary input, then generate all output assets 82 /// transform, starting at the primary input, then generate all output assets
83 /// and yield them back to the transform. 83 /// and yield them back to the transform.
84 Future apply(Transform transform); 84 Future apply(Transform transform);
85 85
86 String toString() => runtimeType.toString().replaceAll("Transformer", ""); 86 String toString() => runtimeType.toString().replaceAll("Transformer", "");
87 } 87 }
OLDNEW
« no previous file with comments | « pkg/barback/lib/src/transform_node.dart ('k') | pkg/barback/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698