forked from flutter/website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eff887c
commit b4f8963
Showing
7 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
_site | ||
.sass-cache | ||
|
||
# Dart ignores. | ||
.packages | ||
.pub/ | ||
pubspec.lock | ||
packages | ||
example/*.dart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ markdown: kramdown | |
kramdown: | ||
input: GFM | ||
hard_wrap: false | ||
|
||
exclude: [example, packages, tool] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Note: All Dart files in this directory are git ignored. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
name: flutter_github_io | ||
version: 0.0.1 | ||
dev_dependencies: | ||
path: any | ||
sky: any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:path/path.dart' as p; | ||
|
||
/// Extract Dart snippets from the markdown documentation. | ||
void main(List<String> args) { | ||
// Validate our cwd. | ||
File pubspec = new File('pubspec.yaml'); | ||
if (!pubspec.existsSync()) { | ||
fail('This tool must the run from the project root.'); | ||
} | ||
|
||
// Remove any previously generated files. | ||
clean(); | ||
|
||
// Traverse markdown files in the root. | ||
List<File> markdownFiles = Directory.current.listSync().where((entity) { | ||
return entity is File && entity.path.endsWith('.md'); | ||
}).toList(); | ||
|
||
markdownFiles.forEach(_processFile); | ||
} | ||
|
||
void _processFile(File file) { | ||
print(file.path); | ||
|
||
String name = p.basename(file.path); | ||
|
||
// Look for ```dart sections. | ||
String source = file.readAsStringSync(); | ||
List<String> lines = source.split('\n'); | ||
|
||
int index = 1; | ||
int count = 0; | ||
|
||
String lastComment; | ||
|
||
while (index < lines.length) { | ||
// Look for ``` | ||
if (lines[index].startsWith('```dart') && lastComment != 'skip') { | ||
int startIndex = index + 1; | ||
index++; | ||
while (index < lines.length && !lines[index].startsWith('```')) { | ||
index++; | ||
} | ||
_extract(name, ++count, startIndex, lines.sublist(startIndex, index), | ||
includeSource: lastComment); | ||
} else if (lines[index].startsWith('<!--')) { | ||
int startIndex = index; | ||
while (!lines[index].endsWith('-->')) { | ||
index++; | ||
} | ||
|
||
lastComment = lines.sublist(startIndex, index + 1).join('\n'); | ||
lastComment = lastComment.substring(4); | ||
lastComment = lastComment.substring(0, lastComment.length - 3).trim(); | ||
} else { | ||
lastComment = null; | ||
} | ||
|
||
index++; | ||
} | ||
} | ||
|
||
void _extract(String filename, int snippet, int startLine, List<String> lines, | ||
{String includeSource}) { | ||
String first = lines.first.trim(); | ||
bool hasImport = first.startsWith('import '); | ||
// // TODO: Many of these should be analyzed as well. | ||
// print(' skipping ${filename} line ${startLine}, no import statement'); | ||
// return; | ||
|
||
String path = | ||
'example/${filename.replaceAll('-', '_').replaceAll('.', '_')}_${snippet}.dart'; | ||
|
||
String source = | ||
'// Extracted from ${filename} line ${startLine}.\n'; | ||
|
||
int adjust = 1; | ||
|
||
if (!hasImport) { | ||
source += "import 'package:sky/material.dart';\n"; | ||
adjust++; | ||
} | ||
|
||
if (includeSource != null) { | ||
source += "${includeSource}\n"; | ||
adjust += includeSource.split('\n').length; | ||
} | ||
|
||
source += | ||
'${''.padRight(startLine - adjust, '\n')}' | ||
'${lines.join('\n')}\n'; | ||
|
||
print(' extracting ${path} from line ${startLine}'); | ||
new File(path).writeAsStringSync(source); | ||
} | ||
|
||
void clean() { | ||
Iterable<File> files = new Directory('example').listSync().where((entity) { | ||
return entity is File && entity.path.endsWith('.dart'); | ||
}); | ||
files.forEach((file) => file.deleteSync()); | ||
} | ||
|
||
void fail(String message) { | ||
print(message); | ||
exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
# Fast fail the script on failures. | ||
set -e | ||
|
||
# Extract Dart snippets from the markdown documentation. | ||
dart tool/extract.dart | ||
|
||
# Analyze the extracted Dart libraries. | ||
pub global activate tuneup | ||
pub global run tuneup check |
This file was deleted.
Oops, something went wrong.