Permalink
Browse files

feature: -i creates a basic file-structure for you

  • Loading branch information...
MikeMitterer committed Mar 30, 2015
1 parent 593f367 commit 35c3d4e4a73a00a8c2b8a690f270963364b3a8bc
Showing with 164 additions and 24 deletions.
  1. +28 −16 README.md
  2. +1 −0 lib/sitegen.dart
  3. +7 −7 lib/src/Application.dart
  4. +1 −1 lib/src/Generator.dart
  5. +123 −0 lib/src/Init.dart
  6. +4 −0 lib/src/Options.dart
View
@@ -168,27 +168,39 @@ Uninstall
## Usage
```shell
Usage: sitegen [options]
-s, --settings Prints settings
-h, --help Shows this message
-g, --generate Generate site
-w, --watch Observes SRC-dir
--serve Serves your site
--port Sets the port to listen on
(defaults to "8000")
-v, --loglevel Sets the appropriate loglevel
[info, debug, warning]
Sample:
'Observes the default dirs and serves the web-folder: 'sitegen -w --serve'
'Generates the static site in your 'web-folder': 'sitegen -g'
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)
--serve Serves your site
--port Sets the port to listen on
(defaults to "8000")
-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'
```
Go to your project root (this is where your pubspec.yaml is) and type:
sitegen -i
This creates a basic file structure for you.
Now type
sitegen -w --serve
This servers your files under http://localhost:8000/
If you are using Chromium on Mac you will get a automatic page refresh for free!
View
@@ -24,6 +24,7 @@ import 'package:http_server/http_server.dart';
part "src/Application.dart";
part "src/Options.dart";
part "src/Config.dart";
part "src/Init.dart";
part "src/Generator.dart";
View
@@ -26,15 +26,15 @@ class Application {
return;
}
// if (argResults.wasParsed(Options._ARG_TEST)) {
// _testPWD(config.outputfolder);
// _testPWD2();
//
// return;
// }
bool foundOptionToWorkWith = false;
if (argResults.wasParsed(Options._ARG_INIT)) {
foundOptionToWorkWith = true;
final Init init = new Init();
init.createDirs(config).then((_) => init.createFiles(config));
return;
}
if (argResults.wasParsed(Options._ARG_GENERATE)) {
foundOptionToWorkWith = true;
new Generator().generate(config);
View
@@ -214,7 +214,7 @@ class Generator {
backPath = backPath + "../";
}
}
backPath = backPath.replaceFirst(new RegExp(r"/$"),"");
//backPath = backPath.replaceFirst(new RegExp(r"/$"),"");
pageOptions["_page"] = {
"relative_to_root" : backPath,
"nesting_level" : nestingLevel
View
@@ -0,0 +1,123 @@
part of sitegen;
/**
* Initializes your site directory.
* This means - creates _templates folder, _content folder aso.
*/
class Init {
final Logger _logger = new Logger("sitegen.Init");
static const String _STYLES_FOLDER = "styles";
static const String _STYLES_FILE = "main.scss";
Future createDirs(final Config config) {
Validate.notNull(config);
return Future.wait([
_createDir(config.templatefolder),
_createDir(config.contentfolder),
_createDir("${config.contentfolder}/$_STYLES_FOLDER"),
_createDir(config.outputfolder),
_createDir(config.configfolder)
]);
}
/// Creates files like site.yaml and adds a default Template and a default content file
Future createFiles(final Config config) {
Validate.notNull(config);
return Future.wait([
_createSiteYaml(config),
_createDefaultTemplate(config),
_createIndexHTML(config),
_createScssFile(config)
]);
}
//- private -----------------------------------------------------------------------------------
Future _createDir(final String dirname) async {
Validate.notBlank(dirname);
final Directory dir = new Directory(dirname);
if(! await dir.exists()) {
await dir.create(recursive: true);
_logger.info("${dir.path} created...");
}
}
Future _createSiteYaml(final Config config) async {
Validate.notNull(config);
final File file = new File("${config.configfolder}/${config.configfile}");
if(! await file.exists()) {
final String content = "site_options:\n generator: SiteGen\n site_name: Sample";
await file.writeAsString(content);
_logger.info("${file.path} created...");
}
}
Future _createDefaultTemplate(final Config config) async {
Validate.notNull(config);
final File file = new File(("${config.templatefolder}/${config.defaulttemplate}"));
if(! await file.exists()) {
final String content = """
<!DOCTYPE html>
<html>
<head>
<title>{{title}} | {{_site.site_name}}</title>
<meta charset="utf-8">
<link rel="stylesheet" href="{{_page.relative_to_root}}styles/main.css">
</head>
<body>
<h1>{{title}}</h1>
{{_content}}
<!--
<script type="application/dart" src="{{_page.relative_to_root}}main.dart"></script>
<script src="packages/browser/dart.js"></script>
-->
</body>
</html>
""".trim().replaceAll(new RegExp(r"^\s{16}",multiLine: true),""); // 16 is the number of spaces for the first indention
await file.writeAsString(content);
_logger.info("${file.path} created...");
}
}
Future _createIndexHTML(final Config config) async {
Validate.notNull(config);
final File file = new File("${config.contentfolder}/index.html");
if(! await file.exists()) {
final String content = """
title: My index page
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<section class="main">
My content
</section>
""".trim().replaceAll(new RegExp(r"^\s{16}",multiLine: true),"");
await file.writeAsString(content);
_logger.info("${file.path} created...");
}
}
Future _createScssFile(final Config config) async {
Validate.notNull(config);
final File file = new File("${config.contentfolder}/$_STYLES_FOLDER/$_STYLES_FILE");
if(! await file.exists()) {
final String content = """
body {
background-color: #eeeeee;
.main {
background-color: red;
}
}
""".trim().replaceAll(new RegExp(r"^\s{16}",multiLine: true),"");
await file.writeAsString(content);
_logger.info("${file.path} created...");
}
}
}
View
@@ -10,6 +10,7 @@ class Options {
static const _ARG_SERVE = 'serve';
static const _ARG_PORT = 'port';
static const _ARG_WATCH = 'watch';
static const _ARG_INIT = 'init';
static const _ARG_TEST = 'test';
@@ -31,6 +32,7 @@ class Options {
print("");
print("Sample:");
print("");
print(" 'Generates all basic files and folders: '$APPNAME -i'");
print(" 'Observes the default dirs and serves the web-folder: '$APPNAME -w --serve'");
print(" 'Generates the static site in your 'web-folder': '$APPNAME -g'");
print("");
@@ -48,6 +50,8 @@ class Options {
..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")
..addOption(_ARG_PORT, help: "Sets the port to listen on", defaultsTo: "8000")

0 comments on commit 35c3d4e

Please sign in to comment.