Skip to content

Commit

Permalink
feature: Works with Dart 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMitterer committed Jan 10, 2019
1 parent 9b1b423 commit 59b65c2
Show file tree
Hide file tree
Showing 20 changed files with 162 additions and 152 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ Before you read on - check out this [video](https://www.youtube.com/watch?v=smf1

[![ScreenShot](https://github.com/MikeMitterer/dart-sitegen/blob/master/assets/screenshot.jpg?raw=true)](https://www.youtube.com/watch?v=smf1uvy0yNQ)

### New
## Example

- Install SiteGen `pub global activate sitegen`
- Clone the example from `https://github.com/MikeMitterer/dart-sitegen/tree/master/samples/simple`
- run `sitegen -w`
- open another console window and run `pub run build_runner serve --delete-conflicting-outputs --live-reload`

Play with the sample files...

#### Support for https-connection!
This is absolutely mandatory if your REST-Server
uses [HTTP Strict Transport Security (HSTS)](https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security)
Expand Down Expand Up @@ -385,7 +393,7 @@ package that I used as basis for **SiteGen**.

### License

Copyright 2015 Michael Mitterer (office@mikemitterer.at),
Copyright 2019 Michael Mitterer (office@mikemitterer.at),
IT-Consulting and Development Limited, Austrian Branch

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
7 changes: 3 additions & 4 deletions lib/sitegen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import 'dart:math';

import 'package:intl/intl.dart';
import 'package:args/args.dart';
import 'package:command_wrapper/command_wrapper.dart';
import 'package:which/which.dart';
import 'package:where/where.dart';

import 'package:logging/logging.dart';
import 'package:logging_handlers/logging_handlers_shared.dart';
import 'package:console_log_handler/print_log_handler.dart';

import 'package:validate/validate.dart';

Expand All @@ -34,7 +33,7 @@ part "src/Generator.dart";

bool _runsOnOSX() => (SysInfo.operatingSystemName == "Mac OS X");

final _commands = new List<CommandWrapper>();
// final _commands = new List<CommandWrapper>();

Future main(List<String> arguments) async {
final Application application = new Application();
Expand Down
16 changes: 12 additions & 4 deletions lib/src/Application.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Application {
new Generator().generate(config);
}
watchScss(config.outputfolder, config);
watchToRefresh(config.outputfolder, config);
// watchToRefresh(config.outputfolder, config);

watchAdditionalFolderScss(config.watchfolder1,config.outputfolder, config);
watchAdditionalFolderScss(config.watchfolder2,config.outputfolder, config);
Expand Down Expand Up @@ -294,6 +294,7 @@ class Application {
}
}

/*
void watchToRefresh(final String folder, final Config config) {
Validate.notBlank(folder);
Validate.notNull(config);
Expand All @@ -315,6 +316,7 @@ class Application {
_schedulePageRefresh();
});
}
*/

// -- private -------------------------------------------------------------

Expand Down Expand Up @@ -359,6 +361,9 @@ class Application {
_autoPrefixer(cssFile,config);
}

/*
REMINDER!
/**
* Weitere Infos:
* https://github.com/guard/guard-livereload
Expand Down Expand Up @@ -421,6 +426,7 @@ class Application {
_logger.info("$executable ${script.path} successful!");
}
*/

bool _isFolderAvailable(final String folder) {
Validate.notBlank(folder);
Expand Down Expand Up @@ -486,7 +492,9 @@ class Application {
Validate.notNull(dir);
return dir.listSync(recursive: true).where((final file) {
return file is File && file.path.endsWith(".scss") && !file.path.contains("packages");
}).toList();
})
.map((final FileSystemEntity entity) => entity as File)
.toList();
}

void _vickiSay(final String sentence,final Config config) {
Expand All @@ -497,7 +505,7 @@ class Application {
return;
}

final ProcessResult result = Process.runSync("say", [ '-v', "Vicki", '-r', '200', sentence.replaceFirst("wsk_", "") ]);
final ProcessResult result = Process.runSync("say", [ '-r', '200', sentence.replaceFirst("wsk_", "") ]);
if (result.exitCode != 0) {
_logger.severe("run faild with: ${(result.stderr as String).trim()}!");
}
Expand All @@ -524,6 +532,6 @@ class Application {
Logger.root.level = Level.INFO;
}

Logger.root.onRecord.listen(new LogPrintHandler(messageFormat: "%m"));
Logger.root.onRecord.listen(new LogPrintHandler(transformer: transformerMessageOnly));
}
}
14 changes: 7 additions & 7 deletions lib/src/CommandManager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ part of sitegen;
class CommandManager {
static String SASS = "sass";
static String SASSC = "sassc";
static String OSASCRIPT = "osascript";
static String AUTOPREFIXER = "autoprefixer-cli";
static String SAY = "say";
// static String OSASCRIPT = "osascript";

static CommandManager _commandmanager;

Expand All @@ -31,9 +31,9 @@ class CommandManager {
class Command {
final String name;
final String exe;
final CommandWrapper wrapper;
//final CommandWrapper wrapper;

Command(this.name, this.exe, this.wrapper);
Command(this.name, this.exe);

}

Expand All @@ -45,15 +45,15 @@ Future<Map<String,Command>> _getAvailableCommands() async {

CommandManager.SASS,
CommandManager.SASSC,
CommandManager.OSASCRIPT,
CommandManager.AUTOPREFIXER,
CommandManager.SAY
CommandManager.SAY,
//CommandManager.OSASCRIPT,
];

await Future.forEach(names, (final String binName) async {
try {
final String exe = await which(binName);
commands[binName] = new Command(binName,exe,new CommandWrapper(binName));
final String exe = await where(binName);
commands[binName] = new Command(binName,exe);
} catch(_) { }

});
Expand Down
19 changes: 17 additions & 2 deletions lib/src/Config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Config {

_settings[Options._ARG_DOCROOT] = _settings[Config._CONF_OUTPUT_DIR]; // web

_settings[Config._CONF_USE_SASS] = true;
_settings[Config._CONF_USE_SASS] = false;
_settings[Config._CONF_USE_AUTOPREFIXER] = true;

_settings[Config._CONF_USE_SECURE_CONNECTION] = false;
Expand Down Expand Up @@ -124,7 +124,7 @@ class Config {

String get sasspath => _sasspath;

Map<String,String> get siteoptions => _settings[Config._CONF_SITE_OPTIONS] as Map<String,String>;
Map<String,String> get siteoptions => _toMap(_settings[Config._CONF_SITE_OPTIONS]);

String get ip => _settings[Options._ARG_IP];

Expand Down Expand Up @@ -350,4 +350,19 @@ class Config {

return sasspath.join(_SEARCH_PATH_SEPARATOR);
}

Map<String,String> _toMap(final configOption) {
if(configOption is Map<String,String>) {
return configOption;
}

if(configOption is yaml.YamlMap) {
return configOption
.map((key,value) => MapEntry<String,String>(key.toString(),value.toString()));

} else {
return configOption;
}

}
}
52 changes: 33 additions & 19 deletions lib/src/Generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ class Generator {
if (hasYamlBlock) {
List<String> yamlBlock = _extractYamlBlockFrom(config.yamldelimeter,lines,extension);
if(yamlBlock.length > 0) {
pageOptions.addAll(yaml.loadYaml(yamlBlock.join('\n')) as Map<String,String>);
final String block = yamlBlock.join('\n');
final yaml.YamlMap ym = yaml.loadYaml(block);

pageOptions.addAll(ym.map((key,value)
=> MapEntry<String,String>(key.toString(),value.toString())));

_resolvePartialsInYamlBlock(partialsDir,pageOptions,config.usemarkdown);

// +1 for the YAML-Block-Delimiter ("~~~") line
Expand Down Expand Up @@ -212,19 +217,20 @@ class Generator {
}

return contentDir.listSync(recursive: true)
.where((file) => file is File && (

file.path.endsWith('.md') ||
file.path.endsWith(".markdown") ||
file.path.endsWith(".dart") ||
file.path.endsWith(".js") ||
file.path.endsWith(".json") ||
file.path.endsWith(".html") ||
file.path.endsWith(".scss") ||
file.path.endsWith(".css") ||
file.path.endsWith(".svg")

) && !file.path.contains("packages") ).toList();
.where((final FileSystemEntity entity) => entity is File && (

entity.path.endsWith('.md') ||
entity.path.endsWith(".markdown") ||
entity.path.endsWith(".dart") ||
entity.path.endsWith(".js") ||
entity.path.endsWith(".json") ||
entity.path.endsWith(".html") ||
entity.path.endsWith(".scss") ||
entity.path.endsWith(".css") ||
entity.path.endsWith(".svg"))
&& !entity.path.contains("packages") )
.map((final FileSystemEntity entity) => entity as File)
.toList();
}

List<File> _listImagesFilesIn(final Directory contentDir) {
Expand All @@ -235,7 +241,9 @@ class Generator {
file.path.endsWith(".jpg") ||
file.path.endsWith(".gif")

) && !file.path.contains("packages") ).toList();
) && !file.path.contains("packages") )
.map((final FileSystemEntity entity) => entity as File)
.toList();
}

List<File> _listAssetsFilesIn(final Directory contentDir) {
Expand All @@ -252,12 +260,16 @@ class Generator {
file.path.endsWith(".css") ||
file.path.endsWith(".svg")

) && !file.path.contains("packages") ).toList();
) && !file.path.contains("packages") )
.map((final FileSystemEntity entity) => entity as File)
.toList();
}


List<File> _listTemplatesIn(final Directory templateDir) {
return templateDir.listSync().where((file) => file is File && !file.path.contains("packages")).toList();
return templateDir.listSync().where((file) => file is File && !file.path.contains("packages"))
.map((final FileSystemEntity entity) => entity as File)
.toList();
}

List<File> _listDataFilesIn(final Directory contentDir) {
Expand All @@ -267,7 +279,9 @@ class Generator {
file.path.endsWith('.yaml') ||
file.path.endsWith(".json")

) && !file.path.contains("packages")).toList();
) && !file.path.contains("packages"))
.map((final FileSystemEntity entity) => entity as File)
.toList();
}

bool _isMarkdownSupported(final bool markdownForSite, final Map page_options) {
Expand Down Expand Up @@ -355,7 +369,7 @@ class Generator {

} else {

data = JSON.decode(file.readAsStringSync());
data = json.decode(file.readAsStringSync());
}

final String filename = path.basenameWithoutExtension(file.path).toLowerCase();
Expand Down
34 changes: 17 additions & 17 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ homepage: https://github.com/MikeMitterer/dart-sitegen
version: 1.7.0

environment:
sdk: ">=1.8.0 <2.0.0"
sdk: ">=2.0.0 <3.0.0"

# Add the bin/sitegen.dart script to the scripts pub installs.
# Activate local repo:
Expand All @@ -16,29 +16,29 @@ executables:
sitegen:

dependencies:
browser: ^0.10.0

logging: ^0.11.0
logging_handlers: ^0.8.0
console_log_handler: ^0.1.0
logging: '>=0.11.3 <1.0.0'
console_log_handler: ^1.0.0
# path: /Volumes/Daten/DevLocal/DevDart/ConsoleLogHandler

validate: ^1.0.0

args: ^0.13.0
path: ^1.3.0
args: ^1.4.0
yaml: ^2.1.0
markdown: ^0.9.0
mustache: ^0.2.0
intl: ^0.12.0
path: ^1.0.0
markdown: ^2.0.0
mustache: ^1.0.0
intl: ^0.15.0
http_server: ^0.9.0

system_info: 0.0.16

packages: ^0.1.0
system_info: ^0.1.0
where: ^6.0.0

packages: ^0.4.0
#path: /Volumes/Daten/DevLocal/DevDart/Packages

command_wrapper: "^0.2.0"

dev_dependencies:
test: any
grinder: any
grinder: any

build_runner: any
build_test: any
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ----------------------------------------------------------------------------
// Copyright (c) 2015, Michael Mitterer (office@mikemitterer.at),
// Copyright (c) 2019, Michael Mitterer (office@mikemitterer.at),
// IT-Consulting and Development Limited.
//
// All Rights Reserved.
Expand All @@ -17,12 +17,19 @@
// limitations under the License.
//

@import "package:m4d_components/assets/styles/material-design-lite";
@import "package:m4d_components/assets/styles/splashscreen/dots";

html, body {
font-family : 'Roboto', 'Helvetica', sans-serif;
margin : 0;
padding : 0;
}

//.mdl-layout {
// background-color: green !important;
//}

// ----------------------------------------------------------------------------
// ---- Application specific part
// -
Expand Down
2 changes: 1 addition & 1 deletion samples/simple/.sitegen/html/_content/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
title: Welcome
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<div class="mdl-panel mdl-shadow--2dp">
Hi, I am content
Hi, I am content!
</div>
<div class="mdl-panel mdl-shadow--2dp">
<a href="special/xtreme.html">XTREME</a> is for testing minimal content!<br>
Expand Down
Loading

0 comments on commit 59b65c2

Please sign in to comment.