Skip to content

Commit 7b281d4

Browse files
authored
Refactor generator config (#177)
`Highlighting` shouldn't have to include all these extra libraries.
1 parent 3851d7e commit 7b281d4

File tree

6 files changed

+35
-40
lines changed

6 files changed

+35
-40
lines changed

highlighting.hxml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,5 @@
22
-main Highlighting
33
-lib hxnodejs
44
-lib highlighter
5-
-lib markdown
6-
-lib hxtemplo
7-
-lib hxparse
85
-js bin/patch.js
96
-cmd node bin/patch.js

src/Config.hx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import haxe.io.Path;
2+
3+
class Config {
4+
public static final contentPath = "./assets/content/";
5+
public static final outputPath = "./output/";
6+
public static final repositoryUrl = switch (Sys.getEnv("REPO_URL")) {
7+
case null: "https://github.com/HaxeFoundation/code-cookbook/";
8+
case v: v;
9+
};
10+
public static final repositoryBranch = switch (Sys.getEnv("REPO_BRANCH")) {
11+
case null: "master";
12+
case v: v;
13+
};
14+
public static final basePath = switch (Sys.getEnv("BASEPATH")) {
15+
case null: "";
16+
case v: v;
17+
};
18+
public static final titlePostFix = " - Haxe programming language cookbook";
19+
public static final cookbookFolder = Path.addTrailingSlash("cookbook");
20+
public static final assetsFolderName = "assets";
21+
public static final snippetsFolder = Path.addTrailingSlash("snippets");
22+
}

src/Generator.hx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,14 @@ import sys.FileSystem;
1111
import sys.io.File;
1212
import templo.Template;
1313
import util.GitUtil.GitAuthorInfo;
14+
import Config.*;
1415

1516
using StringTools;
1617

1718
/**
1819
* @author Mark Knol
1920
*/
2021
class Generator {
21-
public var contentPath = "./assets/content/";
22-
public var outputPath = "./output/";
23-
public var repositoryUrl = "";
24-
public var repositoryBranch = "";
25-
public var basePath = "";
26-
public var titlePostFix = "";
27-
public var cookbookFolder = Path.addTrailingSlash("cookbook");
28-
public var assetsFolderName = "assets";
29-
public var snippetsFolder = Path.addTrailingSlash("snippets");
30-
3122
private var _pages:Array<Page> = new Array<Page>();
3223
private var _folders:StringMap<Array<Page>> = new StringMap<Array<Page>>();
3324
private var _templates:StringMap<Template> = new StringMap<Template>();

src/Highlighting.hx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ class Highlighting {
66
public static function main() {
77
Sys.println("Applying syntax highlighting ...");
88

9-
var g = new Generator();
10-
119
// Convert CSON grammar to json for vscode-textmate
1210
File.saveContent("bin/javascript.json", Json.stringify(CSON.parse(File.getContent("grammars/language-javascript/grammars/javascript.cson"))));
1311

@@ -25,7 +23,7 @@ class Highlighting {
2523
];
2624

2725
// Go over the generated HTML file and apply syntax highlighting
28-
var missingGrammars = Highlighter.patchFolder(g.outputPath, grammars, function (classList) {
26+
var missingGrammars = Highlighter.patchFolder(Config.outputPath, grammars, function (classList) {
2927
return classList.substr(12);
3028
});
3129

@@ -34,7 +32,7 @@ class Highlighting {
3432
}
3533

3634
// Add CSS rules for highlighting
37-
var path = g.outputPath + "/css/haxe-nav.min.css";
35+
var path = Config.outputPath + "/css/haxe-nav.min.css";
3836
var baseStyle = File.getContent(path);
3937
var syntaxStyle = haxeGrammar.runCss();
4038
File.saveContent(path, baseStyle + syntaxStyle);

src/Main.hx

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,11 @@ class Main {
77
public static function main() {
88
haxe.Timer.measure(function() {
99
var generator = new Generator();
10-
generator.titlePostFix = " - Haxe programming language cookbook";
11-
generator.basePath = switch (Sys.getEnv("BASEPATH")){
12-
case null: "";
13-
case v: v;
14-
};
15-
generator.repositoryUrl = switch (Sys.getEnv("REPO_URL")) {
16-
case null: "https://github.com/HaxeFoundation/code-cookbook/";
17-
case v: v;
18-
}
19-
generator.repositoryBranch = switch (Sys.getEnv("REPO_BRANCH")) {
20-
case null: "master";
21-
case v: v;
22-
}
23-
10+
2411
generator.build();
2512
generator.includeDirectory("assets/includes");
26-
27-
Redirections.generate(generator);
13+
14+
Redirections.generate();
2815
});
2916
}
3017
}

src/Redirections.hx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import sys.io.File;
1111
*/
1212
class Redirections
1313
{
14-
public static function generate(generator:Generator)
14+
public static function generate()
1515
{
1616
var list = [
1717
"category/abstract-types/rounded float.html" => "/category/abstract-types/rounded-float.html",
@@ -30,17 +30,17 @@ class Redirections
3030
];
3131

3232
for (page in list.keys()) {
33-
var template = new Template(File.getContent(generator.contentPath + "redirection.mtt"));
33+
var template = new Template(File.getContent(Config.contentPath + "redirection.mtt"));
3434
var content = template.execute({
3535
redirectionLink: list.get(page)
3636
});
37-
37+
3838
// make sure directory exists
39-
FileSystem.createDirectory(generator.outputPath + Path.directory(page));
40-
39+
FileSystem.createDirectory(Config.outputPath + Path.directory(page));
40+
4141
// save to output
42-
File.saveContent(generator.outputPath + page, content);
43-
42+
File.saveContent(Config.outputPath + page, content);
43+
4444
}
4545
}
4646

0 commit comments

Comments
 (0)