From 7b281d40f4bce122479eb1a7fb14d1dab7f35eba Mon Sep 17 00:00:00 2001 From: tobil4sk Date: Sat, 27 Jul 2024 16:09:32 +0100 Subject: [PATCH] Refactor generator config (#177) `Highlighting` shouldn't have to include all these extra libraries. --- highlighting.hxml | 3 --- src/Config.hx | 22 ++++++++++++++++++++++ src/Generator.hx | 11 +---------- src/Highlighting.hx | 6 ++---- src/Main.hx | 19 +++---------------- src/Redirections.hx | 14 +++++++------- 6 files changed, 35 insertions(+), 40 deletions(-) create mode 100644 src/Config.hx diff --git a/highlighting.hxml b/highlighting.hxml index 8b5a35df7..6ccce7b82 100644 --- a/highlighting.hxml +++ b/highlighting.hxml @@ -2,8 +2,5 @@ -main Highlighting -lib hxnodejs -lib highlighter --lib markdown --lib hxtemplo --lib hxparse -js bin/patch.js -cmd node bin/patch.js diff --git a/src/Config.hx b/src/Config.hx new file mode 100644 index 000000000..0cf91f45e --- /dev/null +++ b/src/Config.hx @@ -0,0 +1,22 @@ +import haxe.io.Path; + +class Config { + public static final contentPath = "./assets/content/"; + public static final outputPath = "./output/"; + public static final repositoryUrl = switch (Sys.getEnv("REPO_URL")) { + case null: "https://github.com/HaxeFoundation/code-cookbook/"; + case v: v; + }; + public static final repositoryBranch = switch (Sys.getEnv("REPO_BRANCH")) { + case null: "master"; + case v: v; + }; + public static final basePath = switch (Sys.getEnv("BASEPATH")) { + case null: ""; + case v: v; + }; + public static final titlePostFix = " - Haxe programming language cookbook"; + public static final cookbookFolder = Path.addTrailingSlash("cookbook"); + public static final assetsFolderName = "assets"; + public static final snippetsFolder = Path.addTrailingSlash("snippets"); +} diff --git a/src/Generator.hx b/src/Generator.hx index 7ef0f68e2..ea0c8ad99 100644 --- a/src/Generator.hx +++ b/src/Generator.hx @@ -11,6 +11,7 @@ import sys.FileSystem; import sys.io.File; import templo.Template; import util.GitUtil.GitAuthorInfo; +import Config.*; using StringTools; @@ -18,16 +19,6 @@ using StringTools; * @author Mark Knol */ class Generator { - public var contentPath = "./assets/content/"; - public var outputPath = "./output/"; - public var repositoryUrl = ""; - public var repositoryBranch = ""; - public var basePath = ""; - public var titlePostFix = ""; - public var cookbookFolder = Path.addTrailingSlash("cookbook"); - public var assetsFolderName = "assets"; - public var snippetsFolder = Path.addTrailingSlash("snippets"); - private var _pages:Array = new Array(); private var _folders:StringMap> = new StringMap>(); private var _templates:StringMap