Permalink
Browse files

feature: Extra Assets-Dir can be defined

  • Loading branch information...
MikeMitterer committed May 26, 2015
1 parent 2d56515 commit f919fa9d8179d285cc87a9724103f8a4e3b362d6
Showing with 91 additions and 31 deletions.
  1. +33 −23 README.md
  2. +7 −2 lib/src/Application.dart
  3. +13 −5 lib/src/Config.dart
  4. +38 −1 lib/src/Generator.dart
View
@@ -14,23 +14,28 @@ Before you read on - check out this video:
```
├── .sitegen
│   ├── refreshChromium-1.0.applescript
│ ├── html
│   │   ├── _assets
│   │   │   └── demo.scss
│   │   │
│ │   ├── _content
│   │   │   ├── about
│   │   │   │   └── index.html
│   │   │   ├── index.html
│   │   │   ├── markdown.md
│   │   │   ├── piratenames.json
│   │   │   └── xtreme.html
│   │ │
│   │   ├── _data
│   │   │   ├── xmen.yaml
│   │   │   └── families.json
│   │ │
│   │ └── _templates
│   │   ├── default.html
│   │   └── info_page.html
│   │  
│   └── site.yaml (Optional!)
├── html
│   ├── _content
│   │   ├── about
│   │   │   └── index.html
│   │   ├── index.html
│   │   ├── markdown.md
│   │   ├── piratenames.json
│   │   └── xtreme.html
│ │
│   ├── _data
│   │   ├── xmen.yaml
│   │   └── families.json
│ │
│ └── _templates
│   ├── default.html
│   └── info_page.html
└── web
├── about
│   ├── index.html
@@ -54,7 +59,7 @@ Before you read on - check out this video:
This folder is also used to store autgenerated scripts - in the case above you can see
the script to refresh Chromium on Mac.
**html/_content**: This is where **SiteGen** will look for your files to generate the site from.
**.sitegen/html/_content**: This is where **SiteGen** will look for your files to generate the site from.
The following file-formats are supported:
- .md
@@ -66,7 +71,7 @@ The following file-formats are supported:
- .scss
- .css
**html/_data**: [optional] This is the place where you can store your data-files.
**.sitegen/html/_data**: [optional] This is the place where you can store your data-files.
The following file-formats are supported:
- .yaml
@@ -82,8 +87,11 @@ Here is a sample how to use such data:
{{/_data.xmen}}
</ul>
```
**html/_templates**: The directory containing your HTML+Mustache templates.
**.sitegen/html/_assets**: [optional] Additional assets that you don't want to have in _content. For example .scss
or .jpg files.
**.sitegen/html/_templates**: The directory containing your HTML+Mustache templates.
**web**: Following Dart conventions - this is your default output directory.
@@ -104,9 +112,11 @@ Can be used in your template (default.html) as
You can also use site.yaml to overwrite your **SiteGen** default configuration.
Supported vars:
- content_dir: html/_content
- template_dir: html/_templates
- partials_dir: html/_partials
- content_dir: .sitegen/html/_content
- template_dir: .sitegen/html/_templates
- data_dir: .sitegen/html/_data
- partials_dir: .sitegen/html/_partials
- assets_dir: .sitegen/html/_assets
- output_dir: web
- workspace: .
- date_format: dd.MM.yyyy
View
@@ -71,6 +71,10 @@ class Application {
watch(config.partialsfolder, config);
}
if(_isFolderAvailable(config.assetsfolder)) {
watch(config.assetsfolder, config);
}
new Generator().generate(config);
}
watchScss(config.outputfolder, config);
@@ -133,9 +137,10 @@ class Application {
_logger.info('Observing $folder...');
final File srcDir = new File(folder);
final Directory srcDir = new Directory(folder);
srcDir.watch(recursive: true).where((final file) => (!file.path.contains("packages"))).listen((final FileSystemEvent event) {
_logger.fine(event.toString());
_logger.info(event.toString());
if(timerWatch == null) {
timerWatch = new Timer(new Duration(milliseconds: 1000), () {
new Generator().generate(config);
View
@@ -7,11 +7,14 @@ part of sitegen;
class Config {
final Logger _logger = new Logger("sitegen.Config");
static const String _CONFIG_FOLDER = ".sitegen";
static const _CONF_CONTENT_DIR = 'content_dir';
static const _CONF_TEMPLATE_DIR = 'template_dir';
static const _CONF_OUTPUT_DIR = 'output_dir';
static const _CONF_DATA_DIR = 'data_dir';
static const _CONF_PARTIALS_DIR = 'partials_dir';
static const _CONF_ASSETS_DIR = 'assets_dir';
static const _CONF_WORKSPACE_DIR = 'workspace';
static const _CONF_DATE_FORMAT = 'date_format';
static const _CONF_YAML_DELIMITER = 'yaml_delimeter';
@@ -30,10 +33,12 @@ class Config {
_settings[Options._ARG_LOGLEVEL] = 'info';
_settings[Config._CONF_CONTENT_DIR] = 'html/_content';
_settings[Config._CONF_TEMPLATE_DIR] = 'html/_templates';
_settings[Config._CONF_DATA_DIR] = 'html/_data';
_settings[Config._CONF_PARTIALS_DIR] = 'html/_partials';
_settings[Config._CONF_CONTENT_DIR] = '${_CONFIG_FOLDER}/html/_content';
_settings[Config._CONF_TEMPLATE_DIR] = '${_CONFIG_FOLDER}/html/_templates';
_settings[Config._CONF_DATA_DIR] = '${_CONFIG_FOLDER}/html/_data';
_settings[Config._CONF_PARTIALS_DIR] = '${_CONFIG_FOLDER}/html/_partials';
_settings[Config._CONF_ASSETS_DIR] = '${_CONFIG_FOLDER}/html/_assets';
_settings[Config._CONF_OUTPUT_DIR] = 'web';
_settings[Config._CONF_WORKSPACE_DIR] = '.';
_settings[Config._CONF_DATE_FORMAT] = 'dd.MM.yyyy';
@@ -58,7 +63,7 @@ class Config {
List<String> get dirstoscan => _argResults.rest;
String get configfolder => ".sitegen";
String get configfolder => _CONFIG_FOLDER;
String get configfile => "site.yaml";
@@ -74,6 +79,8 @@ class Config {
String get partialsfolder => _settings[Config._CONF_PARTIALS_DIR];
String get assetsfolder => _settings[Config._CONF_ASSETS_DIR];
String get workspace => _settings[Config._CONF_WORKSPACE_DIR];
String get dateformat => _settings[Config._CONF_DATE_FORMAT];
@@ -105,6 +112,7 @@ class Config {
settings["Template folder"] = templatefolder;
settings["Data folder"] = datafolder;
settings["Partials folder"] = partialsfolder;
settings["Assets folder"] = assetsfolder;
settings["Default template"] = defaulttemplate;
settings["Output folder"] = outputfolder;
View
@@ -31,13 +31,15 @@ class Generator {
final Directory outputDir = new Directory(path.absolute( config.outputfolder));
final Directory dataDir = new Directory(path.absolute( config.datafolder));
final Directory partialsDir = new Directory(path.absolute( config.partialsfolder));
final Directory assetsDir = new Directory(path.absolute( config.assetsfolder));
Validate.isTrue(contentDir.existsSync(),"ContentDir ${contentDir.path} must exist!");
Validate.isTrue(templateDir.existsSync(),"Templatefolder ${templateDir.path} must exist!");
Validate.isTrue(outputDir.existsSync(),"OutputDir ${outputDir.path} must exist!");
final List<File> files = _listContentFilesIn(contentDir);
final List<File> images = _listImagesFilesIn(contentDir);
final List<File> assets = _listAssetsFilesIn(assetsDir);
final List<File> templates = _listTemplatesIn(templateDir);
final List<File> dataFiles = dataDir.existsSync() ? _listDataFilesIn(dataDir) : new List<File>();
@@ -111,6 +113,18 @@ class Generator {
_logger.info(" ${outputFile.path.replaceFirst(outputDir.path,"")} - copied!");
}
for(final File asset in assets) {
final String relativeFileName = asset.path.replaceAll("${assetsDir.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)}");
asset.copySync(outputFile.path);
_logger.info(" ${outputFile.path.replaceFirst(outputDir.path,"")} - copied!");
}
}
@@ -183,6 +197,10 @@ class Generator {
}
List<File> _listContentFilesIn(final Directory contentDir) {
if(!contentDir.existsSync()) {
return new List<File>();
}
return contentDir.listSync(recursive: true)
.where((file) => file is File && (
@@ -193,7 +211,8 @@ class Generator {
file.path.endsWith(".json") ||
file.path.endsWith(".html") ||
file.path.endsWith(".scss") ||
file.path.endsWith(".css")
file.path.endsWith(".css") ||
file.path.endsWith(".svg")
) && !file.path.contains("packages") ).toList();
}
@@ -209,6 +228,24 @@ class Generator {
) && !file.path.contains("packages") ).toList();
}
List<File> _listAssetsFilesIn(final Directory contentDir) {
if(!contentDir.existsSync()) {
return new List<File>();
}
return contentDir.listSync(recursive: true)
.where((file) => file is File && (
file.path.endsWith(".png") ||
file.path.endsWith(".jpg") ||
file.path.endsWith(".scss") ||
file.path.endsWith(".css") ||
file.path.endsWith(".svg")
) && !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 f919fa9

Please sign in to comment.