├── example ├── a.html └── b │ ├── a.html │ └── c │ └── a.html ├── .gitignore ├── CHANGELOG.md ├── AUTHORS ├── pubspec.yaml ├── README.md ├── LICENSE ├── CONTRIBUTING.md └── lib └── transformer.dart /example/a.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /example/b/a.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /example/b/c/a.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | packages 2 | build 3 | pubspec.lock 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 0.1.0 4 | 5 | - Cleanup and remove html dependency 6 | 7 | ## 0.0.1 8 | 9 | - Initial version 10 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # Below is a list of people and organizations that have contributed 2 | # to the project. Names should be added to the list like so: 3 | # 4 | # Name/Organization 5 | 6 | Google Inc. 7 | Jacob MacDonald 8 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: index_page 2 | version: 0.1.0 3 | description: > 4 | Transformer which outputs a simple index.html file in all folders under web 5 | when one is not already present. 6 | author: Jake MacDonald 7 | homepage: https://github.com/dart-lang/index_page 8 | dependencies: 9 | barback: '>=0.14.2 <0.16.0' 10 | path: ^1.0.0 11 | transformers: 12 | - index_page: 13 | $include: example/**.html 14 | environment: 15 | sdk: '>=1.9.0 <2.0.0' 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # index_page 2 | 3 | A transformer which outputs an index.html file in each folder that doesn't 4 | already have one. This file simply lists all the files/folder under that 5 | directory. By default it will only run in debug mode. 6 | 7 | Example usage which will only output links to html files in the web directory: 8 | 9 | ``` 10 | transformers: 11 | - index_page: 12 | $include: web/**.html 13 | ``` 14 | 15 | ## Features and bugs 16 | 17 | Please file feature requests and bugs at the [issue tracker][tracker]. 18 | 19 | [tracker]: https://github.com/dart-lang/index_page/issues 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2015, the Dart project authors. All rights reserved. 2 | Redistribution and use in source and binary forms, with or without 3 | modification, are permitted provided that the following conditions are 4 | met: 5 | 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above 9 | copyright notice, this list of conditions and the following 10 | disclaimer in the documentation and/or other materials provided 11 | with the distribution. 12 | * Neither the name of Google Inc. nor the names of its 13 | contributors may be used to endorse or promote products derived 14 | from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Want to contribute? Great! First, read this page (including the small print at 2 | the end). 3 | 4 | ### Before you contribute 5 | Before we can use your code, you must sign the 6 | [Google Individual Contributor License Agreement](https://cla.developers.google.com/about/google-individual) 7 | (CLA), which you can do online. The CLA is necessary mainly because you own the 8 | copyright to your changes, even after your contribution becomes part of our 9 | codebase, so we need your permission to use and distribute your code. We also 10 | need to be sure of various other things—for instance that you'll tell us if you 11 | know that your code infringes on other people's patents. You don't have to sign 12 | the CLA until after you've submitted your code for review and a member has 13 | approved it, but you must do it before we can put your code into our codebase. 14 | 15 | Before you start working on a larger contribution, you should get in touch with 16 | us first through the issue tracker with your idea so that we can help out and 17 | possibly guide you. Coordinating up front makes it much easier to avoid 18 | frustration later on. 19 | 20 | ### Code reviews 21 | All submissions, including submissions by project members, require review. We 22 | use Github pull requests for this purpose. 23 | 24 | ### File headers 25 | All files in the project must start with the following header. 26 | 27 | // Copyright (c) 2015, Google Inc. Please see the AUTHORS file for details. 28 | // All rights reserved. Use of this source code is governed by a BSD-style 29 | // license that can be found in the LICENSE file. 30 | 31 | ### The small print 32 | Contributions made by corporations are covered by a different agreement than the 33 | one above, the 34 | [Software Grant and Corporate Contributor License Agreement](https://developers.google.com/open-source/cla/corporate). 35 | -------------------------------------------------------------------------------- /lib/transformer.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, 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 | /// Builds an index.html file in each folder containing entry points, if none 6 | /// already exists. This file simply lists all the entry point files. 7 | library index_page.transformer; 8 | 9 | import 'dart:async'; 10 | 11 | import 'package:barback/barback.dart'; 12 | import 'package:path/path.dart' as path; 13 | 14 | /// Builds an index.html file in each folder containing entry points, if none 15 | /// already exists. This file simply lists all the entry point files. 16 | class IndexPageBuilder extends AggregateTransformer 17 | implements DeclaringAggregateTransformer, LazyAggregateTransformer { 18 | final bool shouldRun; 19 | 20 | IndexPageBuilder.asPlugin(BarbackSettings settings) 21 | : shouldRun = settings.mode == BarbackMode.DEBUG; 22 | 23 | /// Group by top level directory. 24 | classifyPrimary(AssetId id) { 25 | if (!shouldRun) return null; 26 | var parts = path.url.split(id.path); 27 | if (parts.length < 2) return null; 28 | return parts[0]; 29 | } 30 | 31 | /// Outputs an index.html file in every folder which doesn't already have an 32 | /// index.html file. 33 | declareOutputs(DeclaringAggregateTransform transform) async { 34 | final ids = await transform.primaryIds.toList(); 35 | final dirFiles = _getDirsAndFiles(ids); 36 | for (var dir in dirFiles.keys) { 37 | if (dirFiles[dir].contains('index.html')) continue; 38 | transform.declareOutput( 39 | new AssetId(transform.package, path.url.join(dir, 'index.html'))); 40 | } 41 | } 42 | 43 | /// Actually run the transformer. 44 | Future apply(AggregateTransform transform) async { 45 | if (!shouldRun) return; 46 | final assets = await transform.primaryInputs.toList(); 47 | var dirFiles = _getDirsAndFiles(assets.map((asset) => asset.id)); 48 | 49 | // Create an output index.html file for each directory, if one doesn't 50 | // exist already 51 | dirFiles.forEach((directory, files) { 52 | if (dirFiles[directory].contains('index.html')) return; 53 | _createOutput(directory, files.toList(), transform); 54 | }); 55 | } 56 | 57 | Map> _getDirsAndFiles(Iterable ids) { 58 | final dirFiles = >{}; 59 | for (var id in ids) { 60 | var dir = path.url.dirname(id.path); 61 | dirFiles.putIfAbsent(dir, () => new Set()); 62 | dirFiles[dir].add(path.url.relative(id.path, from: dir)); 63 | 64 | var parentDir = path.url.dirname(dir); 65 | if (parentDir != '.') { 66 | dirFiles.putIfAbsent(parentDir, () => new Set()); 67 | dirFiles[parentDir].add(path.url.relative(dir, from: parentDir)); 68 | } 69 | } 70 | 71 | return dirFiles; 72 | } 73 | 74 | void _createOutput( 75 | String directory, List files, AggregateTransform transform) { 76 | var indexAsset = 77 | new AssetId(transform.package, path.url.join(directory, 'index.html')); 78 | 79 | // Sort alphabetically by recursive path parts. 80 | files..sort((String a, String b) => a.compareTo(b)); 81 | 82 | // Create the document with a list. 83 | var doc = new StringBuffer(''); 84 | doc.writeln('

'); 85 | var dirParts = path.url.split(directory); 86 | var url = '/'; 87 | for (var part in dirParts) { 88 | // skip first dir in the url 89 | if (part != dirParts.first) url = path.url.join(url, part); 90 | doc.write('$part / '); 91 | } 92 | doc.write('

'); 93 | doc.writeln('
    '); 94 | 95 | // Add all the assets to the list. 96 | for (var file in files) { 97 | doc.writeln('
  • $file
  • '); 98 | } 99 | 100 | doc.writeln('
'); 101 | 102 | // Output the index.html file 103 | transform.addOutput(new Asset.fromString(indexAsset, doc.toString())); 104 | } 105 | } 106 | --------------------------------------------------------------------------------