diff --git a/README.md b/README.md index 5107afb..0d3e209 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Before you read on - check out this video: ``` ├── .sitegen │   ├── refreshChromium-1.0.applescript -│   └── site.yaml +│   └── site.yaml (Optional!) ├── html │   ├── _content │   │   ├── about @@ -51,7 +51,7 @@ Before you read on - check out this video: └── xtreme.html ``` -**.sitegen**: This is where your site.yaml lives +**.sitegen**: This is where your (optional) site.yaml lives This folder is also used to store autgenerated scripts - in the case above you can see the script to refresh Chromium on Mac. @@ -114,6 +114,8 @@ Supported vars: - use_markdown: true - default_template: default.html - sasscompiler: sassc +- usesass: true +- useapfx: true ## Markdown **SiteGen** lets you use [markdown][markdown] to write your site content. At the beginning of each markdown file, you @@ -172,7 +174,17 @@ The default template is 'default.html' but you can overwrite this behavior if yo template: info_page ## SASS -If SiteGen finds a .scss file in your output dir (web) it compiles it to the corresponding .css file. +If SiteGen finds a .scss file in your output dir (web) it compiles it to the corresponding .css file. +Install instruction for SASS can be found [here][installsass] +In short it's `gem install sass` and `gem install sassc` + +You can turn off SASS either with `--no-usesass` or with the appropriate setting in site.yaml + +## Autoprefixer +After compiling .SCSS to .CSS SiteGen calls autoprefixer +Install autoprefixer with `npm install --global autoprefixer` + +You can turn off Autoprefixer either with `--no-useapfx` or with the appropriate setting in site.yaml # Install Install @@ -188,31 +200,37 @@ Update Uninstall ```shell - pub global deactivate sitegen + pub global deactivate sitegen ``` ## Usage ```shell Usage: sitegen [options] - -s, --settings Prints settings - -h, --help Shows this message - -g, --generate Generate site - -w, --watch Observes SRC-dir - -i, --init Initializes your site - (not combinable with other options) + -s, --settings Prints settings + -h, --help Shows this message + -g, --generate Generate site + -w, --watch Observes SRC-dir + -i, --init Initializes your site + (not combinable with other options) + + --serve Serves your site + --[no-]usesass Enables / disables SASS to CSS compiler + (defaults to on) + + --[no-]useapfx Enables / disables Autoprefixer + (defaults to on) - --serve Serves your site - --port Sets the port to listen on - (defaults to "8000") + --port Sets the port to listen on + (defaults to "8000") - -v, --loglevel Sets the appropriate loglevel - [info, debug, warning] + -v, --loglevel Sets the appropriate loglevel + [info, debug, warning] Sample: 'Generates all basic files and folders: 'sitegen -i' 'Observes the default dirs and serves the web-folder: 'sitegen -w --serve' - 'Generates the static site in your 'web-folder': 'sitegen -g' + 'Generates the static site in your 'web-folder': 'sitegen -g' ``` Go to your project root (this is where your pubspec.yaml is) and type: @@ -268,4 +286,5 @@ or **star** this repo here on GitHub. [stillshot]: https://pub.dartlang.org/packages/stillshot [promoimage]: https://github.com/MikeMitterer/dart-sitegen/blob/master/assets/screenshot.jpg?raw=true [video]: http://goo.gl/uUTg8s +[installsass]: http://sass-lang.com/install diff --git a/lib/src/Application.dart b/lib/src/Application.dart index d41492b..0fc6dcc 100644 --- a/lib/src/Application.dart +++ b/lib/src/Application.dart @@ -3,9 +3,17 @@ part of sitegen; class Application { final Logger _logger = new Logger("sitegen.Application"); + /// Commandline options final Options options; + + /// {timerForPageRefresh} waits 500ms before refreshing the page + /// If there are more PageRefresh-Requests withing 500ms only the last refresh will be made Timer timerForPageRefresh = null; + /// {timerWatchCss} waits 500ms before it calls it's watch-functions. + /// If there are more watch-events within 500ms only the last event counts + Timer timerWatchCss = null; + Application() : options = new Options(); void run(List args) { @@ -131,6 +139,7 @@ class Application { return; } + // mainScssFile is the one not starting with a _ (underscore) File _mainScssFile(final List scssFiles) { final File mainScss = scssFiles.firstWhere((final File file) { final String pureFilename = path.basename(file.path); @@ -146,8 +155,8 @@ class Application { final String cssFile = "${path.withoutExtension(scssFile)}.css"; _logger.info("Main SCSS: $scssFile"); - _compileScss(config.sasscompiler,scssFile, cssFile); - _autoPrefixer("autoprefixer",cssFile); + _compileScss(scssFile, cssFile,config); + _autoPrefixer("autoprefixer",cssFile,config); scssFiles.forEach((final File file) { _logger.info("Observing: ${file.path}"); @@ -156,8 +165,15 @@ class Application { _logger.fine(event.toString()); //_logger.info("Scss: ${scssFile}, CSS: ${cssFile}"); - _compileScss(config.sasscompiler, scssFile, cssFile); - _autoPrefixer("autoprefixer",cssFile); + if(timerWatchCss == null) { + timerWatchCss = new Timer(new Duration(milliseconds: 500), () { + + _compileScss(scssFile, cssFile,config); + _autoPrefixer("autoprefixer",cssFile,config); + timerWatchCss = null; + }); + } + }); }); @@ -269,10 +285,17 @@ class Application { return dir.existsSync(); } - void _compileScss(final String compiler, final String source, final String target) { - Validate.notBlank(compiler); + void _compileScss(final String source, final String target, final Config config) { Validate.notBlank(source); Validate.notBlank(target); + Validate.notNull(config); + + if(!config.usesass) { + _logger.info("Sass was disabled - so your SCSS won't be compiled to CSS!"); + return; + } + + final String compiler = config.sasscompiler; _logger.info("Compiling $source -> $target"); final ProcessResult result = Process.runSync(compiler, [ source, target ]); @@ -284,9 +307,15 @@ class Application { _logger.info("Done!"); } - void _autoPrefixer(final String prefixer,final String cssFile) { + void _autoPrefixer(final String prefixer,final String cssFile, final Config config) { Validate.notBlank(prefixer); Validate.notBlank(cssFile); + Validate.notNull(config); + + if(!config.useautoprefixer) { + _logger.info("Autoprefixing was disabled - so your CSS won't be prefixed!"); + return; + } _logger.info("Autoprefixing $cssFile"); final ProcessResult result = Process.runSync(prefixer, [ cssFile ]); diff --git a/lib/src/Config.dart b/lib/src/Config.dart index 21af6f4..37a836d 100644 --- a/lib/src/Config.dart +++ b/lib/src/Config.dart @@ -17,7 +17,9 @@ class Config { static const _CONF_USE_MARKDOWN = 'use_markdown'; static const _CONF_DEFAULT_TEMPLATE = 'default_template'; static const _CONF_SITE_OPTIONS = 'site_options'; - static const _CONF_SASS_COMPILER = 'sasscompiler'; + static const _CONF_SASS_COMPILER = 'sasscompiler'; + static const _CONF_USE_SASS = 'usesass'; + static const _CONF_USE_AUTOPREFIXER = 'autoprefixer'; final ArgResults _argResults; final Map _settings = new Map(); @@ -41,6 +43,11 @@ class Config { _settings[Options._ARG_PORT] = "8080"; + _settings[Config._CONF_USE_SASS] = true; + _settings[Config._CONF_USE_AUTOPREFIXER] = true; + + + _overwriteSettingsWithConfigFile(); _overwriteSettingsWithArgResults(); } @@ -77,6 +84,11 @@ class Config { String get port => _settings[Options._ARG_PORT]; + bool get usesass => _settings[Config._CONF_USE_SASS]; + + bool get useautoprefixer => _settings[Config._CONF_USE_AUTOPREFIXER]; + + Map get settings { final Map settings = new Map(); @@ -92,7 +104,10 @@ class Config { settings["Dateformat"] = dateformat; settings["YAML-Delimeter"] = yamldelimeter; + settings["Use markdown"] = usemarkdown ? "yes" : "no"; + settings["Use SASS"] = usesass ? "yes" : "no"; + settings["Use Autoprefixer"] = useautoprefixer ? "yes" : "no"; settings["Site options"] = siteoptions.toString(); @@ -151,6 +166,15 @@ class Config { if(_argResults.wasParsed(Options._ARG_PORT)) { _settings[Options._ARG_PORT] = _argResults[Options._ARG_PORT]; } + + if(_argResults.wasParsed(Options._ARG_USE_SASS)) { + _settings[Config._CONF_USE_SASS] = _argResults[Options._ARG_USE_SASS]; + } + + if(_argResults.wasParsed(Options._ARG_USE_AUTOPREFIXER)) { + _settings[Config._CONF_USE_AUTOPREFIXER] = _argResults[Options._ARG_USE_AUTOPREFIXER]; + } + } void _overwriteSettingsWithConfigFile() { diff --git a/lib/src/Options.dart b/lib/src/Options.dart index 5cd4170..2a6ff6c 100644 --- a/lib/src/Options.dart +++ b/lib/src/Options.dart @@ -1,5 +1,6 @@ part of sitegen; +/// Commandline options class Options { static const APPNAME = 'sitegen'; @@ -12,7 +13,8 @@ class Options { static const _ARG_WATCH = 'watch'; static const _ARG_INIT = 'init'; - static const _ARG_TEST = 'test'; + static const _ARG_USE_SASS = 'usesass'; + static const _ARG_USE_AUTOPREFIXER = 'useapfx'; final ArgParser _parser; @@ -25,7 +27,7 @@ class Options { void showUsage() { print("Usage: $APPNAME [options]"); - _parser.getUsage().split("\n").forEach((final String line) { + _parser.usage.split("\n").forEach((final String line) { print(" $line"); }); @@ -44,9 +46,10 @@ class Options { final ArgParser parser = new ArgParser() ..addFlag(_ARG_SETTINGS, abbr: 's', negatable: false, help: "Prints settings") + ..addFlag(_ARG_HELP, abbr: 'h', negatable: false, help: "Shows this message") + ..addFlag(_ARG_GENERATE, abbr: 'g', negatable: false, help: "Generate site") - //..addFlag(_ARG_TEST, abbr: 't', negatable: false, help: "Test") ..addFlag(_ARG_WATCH, abbr: 'w', negatable: false, help: "Observes SRC-dir") @@ -54,6 +57,10 @@ class Options { ..addFlag(_ARG_SERVE, negatable: false, help: "Serves your site") + ..addFlag(_ARG_USE_SASS, negatable: true, help: "Enables / disables SASS to CSS compiler", defaultsTo: true) + + ..addFlag(_ARG_USE_AUTOPREFIXER, negatable: true, help: "Enables / disables Autoprefixer", defaultsTo: true) + ..addOption(_ARG_PORT, help: "Sets the port to listen on", defaultsTo: "8000") ..addOption(_ARG_LOGLEVEL, abbr: 'v', help: "Sets the appropriate loglevel", allowed: ['info', 'debug', 'warning'])