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

Unified Diff: observatory_pub_packages/polymer/src/build/index_page_builder.dart

Issue 816693004: Add observatory_pub_packages snapshot to third_party (Closed) Base URL: http://dart.googlecode.com/svn/third_party/
Patch Set: Created 6 years 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 side-by-side diff with in-line comments
Download patch
Index: observatory_pub_packages/polymer/src/build/index_page_builder.dart
===================================================================
--- observatory_pub_packages/polymer/src/build/index_page_builder.dart (revision 0)
+++ observatory_pub_packages/polymer/src/build/index_page_builder.dart (working copy)
@@ -0,0 +1,104 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/// Builds an index.html file in each folder containing entry points, if none
+/// already exists. This file simply lists all the entry point files.
+library polymer.src.build.index_page_builder;
+
+import 'dart:async';
+import 'dart:math';
+
+import 'package:barback/barback.dart';
+import 'package:path/path.dart' as path;
+
+import 'common.dart';
+
+/// Builds an index.html file in each folder containing entry points, if none
+/// already exists. This file simply lists all the entry point files.
+class IndexPageBuilder extends AggregateTransformer {
+ final TransformOptions options;
+
+ IndexPageBuilder(this.options);
+
+ classifyPrimary(AssetId id) {
+ if (!options.isHtmlEntryPoint(id)) return null;
+ // Group all entry points together.
+ return 'all_entry_points';
+ }
+
+ Future apply(AggregateTransform transform) {
+ Map<String, List<String>> dirFilesMap = {};
+
+ return transform.primaryInputs.toList().then((assets) {
+ // Add the asset to its directory, and make sure its directory is included
+ // in all its parents.
+ for (var asset in assets) {
+ var dir = path.url.dirname(asset.id.path);
+ while (dir != '.') {
+ dirFilesMap.putIfAbsent(dir, () => []);
+
+ var relativePath = path.url.relative(asset.id.path, from: dir);
+ var relativeDir = path.url.dirname(relativePath);
+ dirFilesMap[dir].add(relativePath);
+ dir = path.url.dirname(dir);
+ }
+ }
+
+ // Create an output index.html file for each directory, if one doesn't
+ // exist already
+ var futures = [];
+ dirFilesMap.forEach((directory, files) {
+ futures.add(_createOutput(directory, files, transform));
+ });
+ return Future.wait(futures);
+ });
+ }
+
+ Future _createOutput(
+ String directory, List<String> files, AggregateTransform transform) {
+ var indexAsset = new AssetId(
+ transform.package, path.join(directory, 'index.html'));
+
+ return transform.hasInput(indexAsset).then((exists) {
+ // Don't overwrite existing outputs!
+ if (exists) return;
+
+ // Sort alphabetically by recursive path parts.
+ files.sort((String a, String b) {
+ var aParts = path.split(a);
+ var bParts = path.split(b);
+ int diff = 0;
+ int minLength = min(aParts.length, bParts.length);
+ for (int i = 0; i < minLength; i++) {
+ // Directories are sorted below files.
+ var aIsDir = i < aParts.length - 1;
+ var bIsDir = i < bParts.length - 1;
+ if (aIsDir && !bIsDir) return 1;
+ if (!aIsDir && bIsDir) return -1;
+
+ // Raw string comparison, if not identical we return.
+ diff = aParts[i].compareTo(bParts[i]);
+ if (diff != 0) return diff;
+ }
+ // Identical files, shouldn't happen in practice.
+ return 0;
+ });
+
+ // Create the document with a list.
+ var doc = new StringBuffer(
+ '<!DOCTYPE html><html><body><h1>Entry points</h1><ul>');
+
+ // Add all the assets to the list.
+ for (var file in files) {
+ doc.write('<li><a href="$file">$file</a></li>');
+ };
+
+ doc.write('</ul></body></html>');
+
+ // Output the index.html file
+ transform.addOutput(new Asset.fromString(indexAsset , doc.toString()));
+ });
+ }
+
+}
« no previous file with comments | « observatory_pub_packages/polymer/src/build/import_inliner.dart ('k') | observatory_pub_packages/polymer/src/build/linter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698