Skip to content

Commit

Permalink
Merge pull request #6 from symmetryinvestments/new_source_repo
Browse files Browse the repository at this point in the history
make fa, ur, and ar work
  • Loading branch information
burner authored Nov 30, 2022
2 parents 494438f + 26f14d1 commit 63955f6
Show file tree
Hide file tree
Showing 8 changed files with 6,374 additions and 85 deletions.
48 changes: 29 additions & 19 deletions fakerjsgenerator/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import std.file : dirEntries, SpanMode, isDir, readText, isFile, exists,
mkdirRecurse, read;
import std.algorithm;
import std.string;
import std.typecons : Nullable, nullable;
import std.regex;

import jssplitter;
Expand All @@ -24,26 +25,24 @@ void main() {
FakerData[] locales = scrapeFakers();
mkdirRecurse(outputDir);

/+
auto list = [
/*"az",*/ /*"ar",*/ /*"cz",*/ "de", "de_AT", "de_CH", "en_AU", "en_AU_ocker",
"en_BORK", "en_CA", "en_GB", "en_IE", "en_IND", "en_US", "en_ZA", "es",
/*"es_MX",*/ /*"fa",*/ "fi", "fr", "fr_CA", "fr_CH", "ge", "hy", "hr", "id_ID",
"it", "ja", "ko", "nb_NO", "ne", "nl", "nl_BE", "pl", "pt_BR", "pt_PT",
"ro", "ru", /*"sk",*/ "sv", "tr", "uk", "vi", "zh_CN", "zh_TW", "af_ZA",
"el", "lv", "zu_ZA"
].sort.array;
+/

auto list =
[ "af_ZA", "de_AT", "en_AU_ocker", "en_IE", "es", "fr_BE", "hr", "it"
, "nb_NO", "pt_BR", "sv", "zh_CN" , /*"ar",*/ "de_CH", "en_BORK", "en_IND"
[ "af_ZA", "de_CH", "en_CA", "en_US", "fr", "hr", "ja", "nl"
, "ru", "vi", "ar", "el", "en_GB", "en_ZA", "fr_BE", "hu", "ko"
, "nl_BE", "sk", "zh_CN", "az", "en_GH", "es", "fr_CA"
, "hy", "lv", "pl", "sv", "zh_TW", "cz", "en_AU", "en_IE"
, "es_MX", "fr_CH", "id_ID", "mk", "pt_BR", "tr", "zu_ZA", "de"
, "en_AU_ocker", "en_IND", "fa", "ge", "pt_PT"
, "uk", "de_AT", "en_BORK", "en_NG", "fi", "he", "it", "ne"
, "ro", "ur"
, "af_ZA", "de_AT", "en_AU_ocker", "en_IE", "es", "fr_BE", "hr", "it"
, "nb_NO", "pt_BR", "sv", "zh_CN" , "ar", "de_CH", "en_BORK", "en_IND"
, "es_MX", "fr_CA", "hu", "ja", "ne", "pt_PT", "tr", "zh_TW", "az"
, "el", "en_CA", "en_NG", /*"fa",*/ "fr_CH", "hy", "ko", "nl", "ro", "uk"
, "el", "en_CA", "en_NG", "fa", "fr_CH", "hy", "ko", "nl", "ro", "uk"
, "zu_ZA", "cz", /*"en",*/ "en_GB", "en_US", "fi", "ge", "id_ID", "lv"
, "nl_BE", "ru", /*"ur",*/ "de", "en_AU", "en_GH", "en_ZA", "fr", "he"
, "mk", "pl", "sk", "vi"].sort.array;
, "nl_BE", "ru", "ur", "de", "en_AU", "en_GH", "en_ZA", "fr", "he"
, "mk", "pl", "sk", "vi"
].sort.uniq.array;


auto en = locales.find!(a => a.locale == "en").front;
string[] methods = buildFile("en", en, []);
Expand Down Expand Up @@ -166,6 +165,13 @@ string[] buildFile(string ll, FakerData entry, string[] toOverride) {
foreach(string sub, Data svalue; value.subs) {
Direct d = cast(Direct)svalue;
if(d !is null) {
if(ll == "ur" && key == "address" && sub == "city_name") {
continue;
}
if(ll == "fa" && key == "finance" && sub == "credit_card") {
continue;
}

if(key == "name" && sub == "title") {
methods ~= gen.buildNameTitle(d.data);
continue;
Expand All @@ -188,7 +194,11 @@ string[] buildFile(string ll, FakerData entry, string[] toOverride) {
}
//write(key, ".", sub, " ");
//writefln("%s %s %s %s", __LINE__, ll, key, sub);
TypeLines tl = jssplit(d.data, ll ~ " " ~ key ~ " " ~ sub);
Nullable!TypeLines tlN = jssplit(d.data, ll ~ " " ~ key ~ " " ~ sub);
if(tlN.isNull()) {
continue;
}
TypeLines tl = tlN.get();
//writeln(tl.type);
if(tl.type == Type.strings) {
methods ~= gen.buildString(key, sub, tl.lines);
Expand Down Expand Up @@ -243,7 +253,7 @@ string[] buildFile(string ll, FakerData entry, string[] toOverride) {

const fakerFolder = "faker";

const string[] ignoreListLocals = ["fa"];
const string[] ignoreListLocals = [];
const string[] ignoreEntries = ["system"];

class Data {
Expand Down
28 changes: 17 additions & 11 deletions fakerjsgenerator/source/generator.d
Original file line number Diff line number Diff line change
Expand Up @@ -763,20 +763,21 @@ class Faker_%1$s : Faker%2$s {
return ret;
}
`, locale != "en" ? "override " : "");
tmp ~= format(`
if(sub.subs.length > 2) {
tmp ~= format(`
///
%sstring financeCreditCard() {
switch(uniform(0, %s, this.rnd)) {
`, locale != "en" ? "override " : "", sub.subs.length - 2);
int cnt = 0;
foreach(key, value; sub.subs) {
if(key == "laser" || key == "maestro") {
continue;
}
tmp ~= format("\t\t\tcase " ~ to!string(cnt++)
~ ": \n\t\t\t\treturn financeCreditCard%s();\n",
to!string(toUpper(key[0])) ~ key[1 .. $].camelCase());
}
int cnt = 0;
foreach(key, value; sub.subs) {
if(key == "laser" || key == "maestro") {
continue;
}
tmp ~= format("\t\t\tcase " ~ to!string(cnt++)
~ ": \n\t\t\t\treturn financeCreditCard%s();\n",
to!string(toUpper(key[0])) ~ key[1 .. $].camelCase());
}
tmp ~= `
default:
assert(false);
Expand All @@ -785,10 +786,15 @@ class Faker_%1$s : Faker%2$s {
}
`;
}
this.output ~= tmp;

foreach(key, value; sub.subs) {
TypeLines tl = jssplit(value.data, format("financeCreditCart %s", key));
Nullable!TypeLines tlN = jssplit(value.data, format("financeCreditCart %s", key));
if(tlN.isNull()) {
continue;
}
TypeLines tl = tlN.get();
if(tl.type == Type.digit) {
string fname = "financeCreditCard" ~ to!string(toUpper(key[0]))
~ key[1 .. $].camelCase();
Expand Down
9 changes: 7 additions & 2 deletions fakerjsgenerator/source/jssplitter.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import std.algorithm;
import std.stdio;
import std.string;
import std.json;
import std.typecons : Nullable, nullable;

enum Type {
undefined,
Expand Down Expand Up @@ -78,7 +79,7 @@ private string[] singleLineSplit(string s) {
return ret2;
}

TypeLines jssplit(string input, const string path) {
Nullable!TypeLines jssplit(string input, const string path) {
//string[] lines = split(input.removeLicense(), "\n")
string[] lines = singleLineSplit(input.removeLicense())
.map!(a => a.strip("\", \t\n\r"))
Expand All @@ -97,6 +98,10 @@ TypeLines jssplit(string input, const string path) {
, "export default {"
];
auto pf = prefixes.find!((a,b) => b.startsWith(a))(lines.front);
if(pf.empty) {
writefln("Failed to work file %s", path);
return Nullable!(TypeLines).init;
}
assert(!pf.empty, lines.front ~ "\n\n" ~ path);
lines[0] = lines[0][pf.front.length .. $].strip();
lines = lines[0 .. $]
Expand All @@ -120,5 +125,5 @@ TypeLines jssplit(string input, const string path) {
writefln("unknown %s", path);
}

return TypeLines(type, lines);
return nullable(TypeLines(type, lines));
}
Loading

0 comments on commit 63955f6

Please sign in to comment.