Permalink
Browse files

feature: Support for SASS_PATH

  • Loading branch information...
MikeMitterer committed Oct 20, 2016
1 parent 7a0ca46 commit 014b7e8ec5d830608dd9f16b3e15100a5cd601e7
Showing with 122 additions and 11 deletions.
  1. +27 −5 README.md
  2. +2 −0 lib/sitegen.dart
  3. +14 −1 lib/src/Application.dart
  4. +74 −3 lib/src/Config.dart
  5. +3 −0 pubspec.yaml
  6. +2 −2 tool/scripts/analyze-sample.sh
View
@@ -2,13 +2,35 @@
Static site generator. Includes a webserver, sass + autoprefix support
### New
**--v debug** - shows you all the vars available for your page
Support for SASS_PATH added!
[Understanding and Using Sass Load Paths](http://technology.customink.com/blog/2014/10/09/understanding-and-using-sass-load-paths/)
**--ip** option - now you can set the IP the server listens to. (Defaults to 127.0.0.1)
Helps to test your site from within a VM for example.
These settings in your .sitegen/site.yaml ()
```yaml
sasscompiler: sass
sass_path:
- "package:zengen"
- "package:mdl"
```
```bash
sitegen -s
Settings:
Loglevel: info
...
SASS compiler: sass
SASS_PATH (only for sass): /Users/mikemitterer/.pub-cache/hosted/pub.dartlang.org/zengen-0.3.2/lib
/Volumes/Daten/DevLocal/DevDart/MaterialDesignLite/lib
...
```
As you can see the first path is resolved to .pub-cache, the second path
is resolve to my local working dir where the mdl-library resides
With extra assets-folder and partials-support. A static site generator in [Dart](https://www.dartlang.org/), webserver included.
### What it does
SiteGen is a static site generator in [Dart](https://www.dartlang.org/), webserver included.
With extra assets-folder and partials-support.
You can write your pages in HTML or [Markdown](http://daringfireball.net/projects/markdown/syntax).
For Templates [Mustache](http://mustache.github.io/mustache.5.html) is supported.
View
@@ -3,6 +3,7 @@ library sitegen;
import 'dart:io';
import 'dart:async';
import 'dart:convert';
import 'dart:isolate';
import 'dart:math';
import 'package:intl/intl.dart';
@@ -20,6 +21,7 @@ import "package:yaml/yaml.dart" as yaml;
import 'package:http_server/http_server.dart';
import 'package:system_info/system_info.dart';
import 'package:packages/packages.dart';
part "src/Application.dart";
part "src/Options.dart";
View
@@ -386,9 +386,22 @@ class Application {
}
final String compiler = config.sasscompiler;
final Map<String,String> environment = new Map<String,String>();
if(config.sasspath.isNotEmpty) {
// only sass supports SASS_PATH (not sassc)
if(!compiler.endsWith("c")) {
environment["SASS_PATH"] = config.sasspath;
_logger.info("Using SASS_PATH: ${config.sasspath}");
} else {
_logger.warning("SASS_PATH ist not supported by your compiler!");
}
}
_logger.info("Compiling $source -> $target");
final ProcessResult result = Process.runSync(compiler, [ source, target ]);
final ProcessResult result = Process.runSync(compiler, [ source, target ], environment: environment);
if (result.exitCode != 0) {
_logger.info("sassc faild with: ${(result.stderr as String).trim()}!");
_vickiSay("got a sassc error",config);
View
@@ -22,6 +22,7 @@ class Config {
static const _CONF_DEFAULT_TEMPLATE = 'default_template';
static const _CONF_SITE_OPTIONS = 'site_options';
static const _CONF_SASS_COMPILER = 'sasscompiler';
static const _CONF_SASS_PATH = 'sass_path';
static const _CONF_USE_SASS = 'usesass';
static const _CONF_USE_AUTOPREFIXER = 'autoprefixer';
static const _CONF_TALK_TO_ME = 'talktome';
@@ -32,8 +33,11 @@ class Config {
static const _CONF_ADDITIONAL_WATCH_FOLDER2 = "watchfolder2";
static const _CONF_ADDITIONAL_WATCH_FOLDER3 = "watchfolder3";
static final String _SEARCH_PATH_SEPARATOR = Platform.isWindows ? ";" : ":";
final ArgResults _argResults;
final Map<String,dynamic> _settings = new Map<String,dynamic>();
final Packages _packages = new Packages();
Config(this._argResults) {
@@ -52,6 +56,7 @@ class Config {
_settings[Config._CONF_USE_MARKDOWN] = true;
_settings[Config._CONF_DEFAULT_TEMPLATE] = "default.html";
_settings[Config._CONF_SASS_COMPILER] = "sassc";
_settings[Config._CONF_SASS_PATH] = "";
_settings[Config._CONF_BROWSER] = "Chromium";
_settings[Config._CONF_SITE_OPTIONS] = {};
@@ -105,6 +110,8 @@ class Config {
String get sasscompiler => _settings[Config._CONF_SASS_COMPILER];
String get sasspath => _sasspath;
Map<String,String> get siteoptions => _settings[Config._CONF_SITE_OPTIONS];
String get ip => _settings[Options._ARG_IP];
@@ -154,6 +161,7 @@ class Config {
settings["Config file"] = configfile;
settings["SASS compiler"] = sasscompiler;
settings["SASS_PATH (only for sass)"] = sasspath.isNotEmpty ? _sasspath : "<not set>";
settings["Browser"] = browser;
settings["IP-Address"] = ip;
@@ -183,12 +191,27 @@ class Config {
final int maxKeyLeght = getMaxKeyLength();
String prepareKey(final String key) {
return "${key[0].toUpperCase()}${key.substring(1)}:".padRight(maxKeyLeght + 1);
if(!key.isEmpty) {
return "${key[0].toUpperCase()}${key.substring(1)}:".padRight(maxKeyLeght + 1);
} else {
// this is only the case if setting is "sass_path..."
return key.padRight(maxKeyLeght + 1);
}
}
print("Settings:");
settings.forEach((final String key,final String value) {
print(" ${prepareKey(key)} $value");
settings.forEach((final String key,final value) {
if(key.toLowerCase().startsWith("sass_path") && sasspath.isNotEmpty) {
final List<String> segments = value.split(_SEARCH_PATH_SEPARATOR);
print(" ${prepareKey(key)} ${segments.first}");
segments.skip(1).forEach((final String path) {
print(" ${prepareKey('')} $path");
});
} else {
print(" ${prepareKey(key)} $value");
}
});
}
@@ -242,4 +265,52 @@ class Config {
}
});
}
/// Interprets the "sass_path" settings in .sitegen/site.yaml
String get _sasspath {
// Can be a String or a YamlList
final pathInSettings = _settings[Config._CONF_SASS_PATH];
// Nothing to do here - return an empty string
if(pathInSettings.isEmpty) { return pathInSettings; }
final List<String> tempPathList = new List<String>();
if(pathInSettings is String) {
// Config-Path can be separated by a |
tempPathList.addAll(pathInSettings.split("|"));
} else if(pathInSettings is yaml.YamlList) {
pathInSettings.toList().forEach((final element) => tempPathList.add(element.toString()));
} else {
_logger.warning("sass_path must be either a String or a YamlList but was ${pathInSettings.runtimeType}...");
}
final List<String> sasspath = new List<String>();
tempPathList.forEach((final String pathEntry) {
if(pathEntry.startsWith("package:")) {
final Uri uri = Uri.parse(pathEntry);
try {
final Package package = _packages.resolvePackageUri(uri);
final String packageUri = package.uri.toString().replaceFirst("file://","");
sasspath.add(path.normalize(path.absolute(packageUri)));
} catch( error) {
_logger.shout(error.toString());
}
} else {
sasspath.add(path.normalize(pathEntry));
}
});
if(sasspath.isEmpty) {
return '';
}
return sasspath.join(_SEARCH_PATH_SEPARATOR);
}
}
View
@@ -34,6 +34,9 @@ dependencies:
system_info: 0.0.16
packages: ^0.1.0
#path: /Volumes/Daten/DevLocal/DevDart/Packages
dev_dependencies:
test: any
grinder: any
@@ -1,8 +1,8 @@
#!/usr/bin/env bash
#------------------------------------------------------------------------------
# This script is needed because Grinder or Analyzer is not able todo its
# work in subdirs - at least I could not figure out how...
# This script is needed because Grinder or Analyzer is not
# able handle subdirs - at least I could not figure out how...
#
cd $1

0 comments on commit 014b7e8

Please sign in to comment.