Skip to content

Commit

Permalink
feature: SASS and Autoprefixer can be turned off
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMitterer committed Apr 17, 2015
1 parent 1f7a73a commit 86c2ea6
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 27 deletions.
51 changes: 35 additions & 16 deletions README.md
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 <yourcss>
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
Expand All @@ -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:
Expand Down Expand Up @@ -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
43 changes: 36 additions & 7 deletions lib/src/Application.dart
Expand Up @@ -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<String> args) {
Expand Down Expand Up @@ -131,6 +139,7 @@ class Application {
return;
}

// mainScssFile is the one not starting with a _ (underscore)
File _mainScssFile(final List<File> scssFiles) {
final File mainScss = scssFiles.firstWhere((final File file) {
final String pureFilename = path.basename(file.path);
Expand All @@ -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}");
Expand All @@ -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;
});
}

});
});

Expand Down Expand Up @@ -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 ]);
Expand All @@ -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 ]);
Expand Down
26 changes: 25 additions & 1 deletion lib/src/Config.dart
Expand Up @@ -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<String,dynamic> _settings = new Map<String,dynamic>();
Expand All @@ -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();
}
Expand Down Expand Up @@ -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<String,String> get settings {
final Map<String,String> settings = new Map<String,String>();

Expand All @@ -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();

Expand Down Expand Up @@ -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() {
Expand Down
13 changes: 10 additions & 3 deletions lib/src/Options.dart
@@ -1,5 +1,6 @@
part of sitegen;

/// Commandline options
class Options {
static const APPNAME = 'sitegen';

Expand All @@ -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;

Expand All @@ -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");
});

Expand All @@ -44,16 +46,21 @@ 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")

..addFlag(_ARG_INIT, abbr: 'i', negatable: false, help: "Initializes your site\n(not combinable with other 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'])
Expand Down

0 comments on commit 86c2ea6

Please sign in to comment.