Permalink
Browse files

feature: Additional watch-folders added

  • Loading branch information...
MikeMitterer committed Jun 12, 2015
1 parent 3ad2ba0 commit b9523c03c08878e5e2f6484312fa2f1150047ac0
Showing with 67 additions and 3 deletions.
  1. +1 −1 README.md
  2. +49 −0 lib/src/Application.dart
  3. +15 −1 lib/src/Config.dart
  4. +2 −1 lib/src/Generator.dart
View
@@ -286,7 +286,7 @@ Now play with sitegen and watch my screencast...
Check out the [sample!][sample]
## Hints
- Just serve a local dir on port 8080 without generating something:
- Just serve a local dir on port 8000 without generating something:
`sitegen --serve --docroot .`
View
@@ -79,6 +79,10 @@ class Application {
}
watchScss(config.outputfolder, config);
watchToRefresh(config.outputfolder, config);
watchAdditionalFolderScss(config.watchfolder1,config.outputfolder, config);
watchAdditionalFolderScss(config.watchfolder2,config.outputfolder, config);
watchAdditionalFolderScss(config.watchfolder3,config.outputfolder, config);
}
if (argResults.wasParsed(Options._ARG_SERVE) || argResults.wasParsed(Options._ARG_WATCH_AND_SERVE)) {
@@ -191,6 +195,51 @@ class Application {
}
}
void watchAdditionalFolderScss(final String additionalWatchFolder, final String cssFolder, final Config config) {
Validate.notBlank(cssFolder);
Validate.notNull(config);
if(additionalWatchFolder.isEmpty) {
return;
}
_logger.fine('Observing $cssFolder (SCSS)... ');
final Directory dirToCheck = new Directory(additionalWatchFolder);
final Directory dir = new Directory(cssFolder);
final List<File> scssFiles = _listSCSSFilesIn(dir);
if (scssFiles.length == 0) {
_logger.info("No SCSS files found");
return;
}
_compileSCSSFile(cssFolder,config);
try {
_logger.info("Observing: ${dirToCheck.path}");
dirToCheck.watch(events: FileSystemEvent.MODIFY).listen((final FileSystemEvent event) {
_logger.fine(event.toString());
//_logger.info("Scss: ${scssFile}, CSS: ${cssFile}");
if(timerWatchCss == null) {
timerWatchCss = new Timer(new Duration(milliseconds: 500), () {
_compileSCSSFile(cssFolder,config);
timerWatchCss = null;
});
}
});
}
on StateError catch (e) {
_logger.info("Found no SCSS without a _ at the beginning...");
}
}
void watchToRefresh(final String folder, final Config config) {
Validate.notBlank(folder);
Validate.notNull(config);
View
@@ -27,6 +27,10 @@ class Config {
static const _CONF_TALK_TO_ME = 'talktome';
static const _CONF_BROWSER = 'browser';
static const _CONF_ADDITIONAL_WATCH_FOLDER1 = "watchfolder1";
static const _CONF_ADDITIONAL_WATCH_FOLDER2 = "watchfolder2";
static const _CONF_ADDITIONAL_WATCH_FOLDER3 = "watchfolder3";
final ArgResults _argResults;
final Map<String,dynamic> _settings = new Map<String,dynamic>();
@@ -59,7 +63,9 @@ class Config {
_settings[Config._CONF_USE_AUTOPREFIXER] = true;
_settings[Config._CONF_TALK_TO_ME] = _runsOnOSX();
_settings[Config._CONF_ADDITIONAL_WATCH_FOLDER1] = "";
_settings[Config._CONF_ADDITIONAL_WATCH_FOLDER2] = "";
_settings[Config._CONF_ADDITIONAL_WATCH_FOLDER3] = "";
_overwriteSettingsWithConfigFile();
_overwriteSettingsWithArgResults();
@@ -111,6 +117,10 @@ class Config {
String get browser => _settings[Config._CONF_BROWSER];
String get watchfolder1 => _settings[Config._CONF_ADDITIONAL_WATCH_FOLDER1];
String get watchfolder2 => _settings[Config._CONF_ADDITIONAL_WATCH_FOLDER2];
String get watchfolder3 => _settings[Config._CONF_ADDITIONAL_WATCH_FOLDER3];
Map<String,String> get settings {
final Map<String,String> settings = new Map<String,String>();
@@ -145,6 +155,10 @@ class Config {
settings["Port"] = port;
settings["Document root"] = docroot;
settings["Additional watchfolder1"] = watchfolder1.isNotEmpty ? watchfolder1 : "<not set>";
settings["Additional watchfolder2"] = watchfolder1.isNotEmpty ? watchfolder2 : "<not set>";
settings["Additional watchfolder3"] = watchfolder1.isNotEmpty ? watchfolder3 : "<not set>";
if(dirstoscan.length > 0) {
settings["Dirs to scan"] = dirstoscan.join(", ");
}
View
@@ -16,7 +16,8 @@ typedef mustache.Template PartialsResolver(final String name);
* Uses [Mustache templates](https://pub.dartlang.org/packages/mustache) by default.
*/
TemplateRenderer renderTemplate = (final String source,final Map options, final PartialsResolver resolver) {
final mustache.Template template = new mustache.Template(source,htmlEscapeValues: false, partialResolver: resolver);
final mustache.Template template =
new mustache.Template(source,htmlEscapeValues: false, partialResolver: resolver,lenient: true);
return template.renderString(options);
};

0 comments on commit b9523c0

Please sign in to comment.