Commit 987ce972 authored by Devon Carew's avatar Devon Carew

use mustache4dart

parent b114623b
...@@ -8,6 +8,7 @@ import 'dart:async'; ...@@ -8,6 +8,7 @@ import 'dart:async';
import 'dart:io'; import 'dart:io';
import 'package:args/args.dart'; import 'package:args/args.dart';
import 'package:mustache4dart/mustache4dart.dart' as mustache;
import 'package:path/path.dart' as p; import 'package:path/path.dart' as p;
import 'common.dart'; import 'common.dart';
...@@ -16,12 +17,10 @@ class InitCommandHandler extends CommandHandler { ...@@ -16,12 +17,10 @@ class InitCommandHandler extends CommandHandler {
InitCommandHandler() : super('init', 'Create a new sky project.'); InitCommandHandler() : super('init', 'Create a new sky project.');
ArgParser get parser { ArgParser get parser {
// TODO: Add a --template option for template selection when we have more than one.
ArgParser parser = new ArgParser(); ArgParser parser = new ArgParser();
parser.addFlag('help', parser.addFlag('help',
abbr: 'h', negatable: false, help: 'Display this help message.'); abbr: 'h', negatable: false, help: 'Display this help message.');
// parser.addOption('template',
// abbr: 't',
// help: "The template to generate; either sky-simple or sky-full.");
parser.addOption('out', abbr: 'o', help: 'The output directory.'); parser.addOption('out', abbr: 'o', help: 'The output directory.');
parser.addFlag('pub', defaultsTo: true, parser.addFlag('pub', defaultsTo: true,
help: 'Whether to run pub after the project has been created.'); help: 'Whether to run pub after the project has been created.');
...@@ -39,11 +38,9 @@ class InitCommandHandler extends CommandHandler { ...@@ -39,11 +38,9 @@ class InitCommandHandler extends CommandHandler {
return new Future.value(); return new Future.value();
} }
// TODO: Confirm overwrite of an existing directory with the user.
Directory out = new Directory(results['out']); Directory out = new Directory(results['out']);
// TODO: confirm overwrite with user
//if (out.existsSync())
new SkySimpleTemplate().generateInto(out); new SkySimpleTemplate().generateInto(out);
print(''); print('');
...@@ -81,9 +78,11 @@ abstract class Template { ...@@ -81,9 +78,11 @@ abstract class Template {
dir.createSync(recursive: true); dir.createSync(recursive: true);
files.forEach((String path, String contents) { files.forEach((String path, String contents) {
contents = contents Map m = {
.replaceAll('{{projectName}}', projectName) 'projectName': projectName,
.replaceAll('{{description}}', description); 'description': description
};
contents = mustache.render(contents, m);
File file = new File(p.join(dir.path, path)); File file = new File(p.join(dir.path, path));
file.parent.createSync(); file.parent.createSync();
file.writeAsStringSync(contents); file.writeAsStringSync(contents);
...@@ -147,12 +146,10 @@ import 'package:sky/widgets.dart'; ...@@ -147,12 +146,10 @@ import 'package:sky/widgets.dart';
class HelloWorldApp extends App { class HelloWorldApp extends App {
Widget build() { Widget build() {
return new Scaffold( return new Scaffold(
toolbar: new ToolBar(center: new Text("Demo")), toolbar: new ToolBar(center: new Text("Demo")),
body: new Material(child: new Center(child: new Text("Hello world!"))), body: new Material(child: new Center(child: new Text("Hello world!"))),
floatingActionButton: new FloatingActionButton( floatingActionButton: new FloatingActionButton(
child: new Icon(type: 'content/add', size: 24) child: new Icon(type: 'content/add', size: 24)));
)
);
} }
} }
......
...@@ -9,6 +9,7 @@ environment: ...@@ -9,6 +9,7 @@ environment:
dependencies: dependencies:
args: ^0.13.0 args: ^0.13.0
mustache4dart: ^1.0.0
path: ^1.3.0 path: ^1.3.0
shelf: ^0.6.2 shelf: ^0.6.2
shelf_route: ^0.13.4 shelf_route: ^0.13.4
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment