-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be17d4a
commit 5ac8a26
Showing
8 changed files
with
255 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{ content }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
layout: default | ||
--- | ||
|
||
{{ content }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
layout: default | ||
--- | ||
|
||
{{ content }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:gengen/commands/abstract_command.dart'; | ||
|
||
class New extends AbstractCommand { | ||
@override | ||
String get description => "Create site or theme from template"; | ||
|
||
@override | ||
String get name => "new"; | ||
|
||
@override | ||
FutureOr<void>? run() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:gengen/logging.dart'; | ||
import 'package:gengen/utilities.dart'; | ||
import 'package:path/path.dart'; | ||
|
||
class Configuration { | ||
Configuration.read(Map<String, dynamic> cfg) { | ||
read(cfg); | ||
} | ||
|
||
Configuration(); | ||
|
||
Map<String, dynamic> _config = {..._defaults}; | ||
|
||
static final Map<String, dynamic> _defaults = { | ||
"title": "My GenGen Site", | ||
"url": "http://gengen.local", | ||
"theme": "default", | ||
"source": current, | ||
"destination": joinAll([current, 'public']), | ||
"post_dir": "_posts", | ||
"themes_dir": "_themes", | ||
"layout_dir": "_layouts", | ||
"sass_dir": "_sass", | ||
"data_dir": "_data", | ||
"asset_dir": "assets", | ||
"template_dir": "_templates", | ||
"include_dir": "_includes", | ||
"block_list": <String>[], | ||
"markdown_extensions": <String>[], | ||
'permalink': "date", | ||
'show_drafts': false, | ||
"config": ["config.yaml"], | ||
"output": {"posts_dir": "posts"}, | ||
}; | ||
|
||
static const List<String> defaultExcludes = ['node_modules', '']; | ||
|
||
T? get<T>( | ||
String key, { | ||
Map<String, dynamic> overrides = const {}, | ||
T? defaultValue, | ||
}) { | ||
var entry = | ||
(overrides[key] ?? _config[key] ?? _defaults[key] ?? defaultValue); | ||
|
||
return entry as T?; | ||
} | ||
|
||
Map<String, dynamic> get all => _config; | ||
|
||
String get source => get("source") as String; | ||
|
||
String get destination { | ||
if (_config.containsKey("destination")) { | ||
var theDestination = get<String>("destination") as String; | ||
|
||
if (isRelative(theDestination)) { | ||
return join(source, theDestination); | ||
} | ||
|
||
return theDestination; | ||
} | ||
|
||
return _defaults["destination"] as String; | ||
} | ||
|
||
T? call<T>(String config) { | ||
return get<T>(config); | ||
} | ||
|
||
void checkIncludeExclude(Map<String, dynamic> config) { | ||
for (var option in ['include', 'exclude']) { | ||
if (!config.containsKey(option)) continue; | ||
if (config[option] is List) continue; | ||
|
||
throw FormatException( | ||
"'$option' should be set as an array, but was: ${config[option]}.", | ||
); | ||
} | ||
} | ||
|
||
void addDefaultExcludes() { | ||
_config.putIfAbsent('excludes', () => <String>[]); | ||
} | ||
|
||
void addDefaultIncludes() { | ||
_config.putIfAbsent('includes', () => <String>[]); | ||
} | ||
|
||
Map<String, dynamic> readConfigFile( | ||
String filePath, [ | ||
Map<String, dynamic> overrides = const {}, | ||
]) { | ||
var yamlConfig = parseYaml(readFileSafe(filePath)); | ||
|
||
_config = {..._config, ...yamlConfig, ...overrides}; | ||
|
||
return _config; | ||
} | ||
|
||
void readConfigFiles( | ||
List<String> files, [ | ||
Map<String, dynamic> overrides = const {}, | ||
]) { | ||
for (var file in files) { | ||
readConfigFile(file, overrides); | ||
} | ||
} | ||
|
||
void read([Map<String, dynamic> overrides = const {}]) { | ||
List<String> resolvedFiles = []; | ||
|
||
bool hasConfig = overrides.containsKey("config"); | ||
|
||
String? siteSource = overrides["source"] as String?; | ||
|
||
if (overrides.containsKey('source') && siteSource != null) { | ||
if (isRelative(overrides["source"] as String)) { | ||
_config["source"] = absolute(siteSource); | ||
} else { | ||
_config["source"] = siteSource; | ||
} | ||
overrides.remove("source"); | ||
} | ||
|
||
String? siteDestination = overrides["destination"] as String?; | ||
if (overrides.containsKey('destination') && siteDestination != null) { | ||
if (isRelative(overrides["destination"] as String)) { | ||
_config["destination"] = absolute(siteDestination); | ||
} else { | ||
_config["destination"] = siteDestination; | ||
} | ||
overrides.remove("destination"); | ||
} | ||
|
||
if (hasConfig) { | ||
List<String> configFiles = get<List<String>>("config") ?? []; | ||
|
||
for (var config in configFiles) { | ||
var file = File(join(source, config)); | ||
if ((file.path.endsWith('.yaml') || file.path.endsWith('.yml'))) { | ||
if (file.existsSync()) { | ||
resolvedFiles.add(file.path); | ||
continue; | ||
} | ||
log.severe("Config $config not found"); | ||
exit(-1); | ||
} else { | ||
log.severe("Invalid config $config"); | ||
exit(-1); | ||
} | ||
} | ||
} | ||
|
||
hasConfig ? overrides.remove("config") : (); | ||
readConfigFiles(resolvedFiles); | ||
overrides["config"] = resolvedFiles; | ||
_config.addAll(overrides); | ||
} | ||
} | ||
|
||
Configuration configuration(Map<String, dynamic> overrides) { | ||
var config = Configuration(); | ||
config.read(overrides); | ||
|
||
return config; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import 'package:liquid_engine/src/drop.dart'; | ||
|
||
class SitePayload extends Drop { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:console/console.dart'; | ||
import 'package:logging/logging.dart'; | ||
|
||
final log = Logger('GenGen'); | ||
|
||
void initLog() { | ||
Logger.root.level = Level.ALL; // defaults to Level.INFO | ||
Logger.root.onRecord.listen((LogRecord record) { | ||
Color color; | ||
switch (record.level) { | ||
case Level.INFO: | ||
color = Color.WHITE; | ||
break; | ||
case Level.WARNING: | ||
color = Color.YELLOW; | ||
break; | ||
case Level.FINE: | ||
color = Color.GREEN; | ||
break; | ||
case Level.SEVERE: | ||
color = Color.RED; | ||
break; | ||
default: | ||
color = Color.WHITE; | ||
break; | ||
} | ||
Console.setTextColor(color.id); | ||
print('${record.level.name}: ${record.time}: ${record.message}'); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:gengen/models/base.dart'; | ||
import 'package:gengen/models/theme_asset.dart'; | ||
import 'package:gengen/reader.dart'; | ||
import 'package:gengen/site.dart'; | ||
|
||
class DataReader { | ||
final Site site; | ||
List<Base> unfilteredContent = []; | ||
|
||
DataReader(this.site); | ||
|
||
List<Base> read() { | ||
var files = Reader(site).filterSpecial(site.theme.root); | ||
|
||
for (var file in files) { | ||
if (FileStat.statSync(file).type == FileSystemEntityType.directory) { | ||
continue; | ||
} | ||
unfilteredContent.add(ThemeAsset(file, site)); | ||
} | ||
|
||
return unfilteredContent; | ||
} | ||
} |