Permalink
Browse files

feature: Accepting images in content-dir

  • Loading branch information...
MikeMitterer committed Apr 23, 2015
1 parent 07c2dcb commit a9c0910f2242adb417fdb6faf6152bc2082c5489
Showing with 23 additions and 1 deletion.
  1. +23 −1 lib/src/Generator.dart
View
@@ -36,8 +36,8 @@ class Generator {
Validate.isTrue(templateDir.existsSync(),"Templatefolder ${templateDir.path} must exist!");
Validate.isTrue(outputDir.existsSync(),"OutputDir ${outputDir.path} must exist!");
// TODO: support directory hierarchies for markdown, templates and output
final List<File> files = _listContentFilesIn(contentDir);
final List<File> images = _listImagesFilesIn(contentDir);
final List<File> templates = _listTemplatesIn(templateDir);
final List<File> dataFiles = dataDir.existsSync() ? _listDataFilesIn(dataDir) : new List<File>();
@@ -100,6 +100,17 @@ class Generator {
outputFile.writeAsStringSync(content);
_logger.info(" ${outputFile.path.replaceFirst(outputDir.path,"")} - done!");
}
for(final File image in images) {
final String relativeFileName = image.path.replaceAll("${contentDir.path}","").replaceFirst("/","");
final String relativePath = path.dirname(relativeFileName).replaceFirst(".","");
final Directory outputPath = _createOutputPath(outputDir,relativePath);
final File outputFile = new File("${outputPath.path}/${path.basename(relativeFileName)}");
image.copySync(outputFile.path);
_logger.info(" ${outputFile.path.replaceFirst(outputDir.path,"")} - copied!");
}
}
@@ -187,6 +198,17 @@ class Generator {
) && !file.path.contains("packages") ).toList();
}
List<File> _listImagesFilesIn(final Directory contentDir) {
return contentDir.listSync(recursive: true)
.where((file) => file is File && (
file.path.endsWith('.png') ||
file.path.endsWith(".jpg") ||
file.path.endsWith(".gif")
) && !file.path.contains("packages") ).toList();
}
List<File> _listTemplatesIn(final Directory templateDir) {
return templateDir.listSync().where((file) => file is File && !file.path.contains("packages")).toList();
}

0 comments on commit a9c0910

Please sign in to comment.