From 0a3515a8d6a231930fedd3240e9df3e423929d9e Mon Sep 17 00:00:00 2001 From: "ALI Mohammadiyeh (Max Base)" Date: Fri, 10 Jan 2025 19:39:38 +0100 Subject: [PATCH] Adding save functionality to scripts inside build/data/tags and build/data/styles --- build/data/styles/baseline_positions.json | 62 ++++++++++++++++ build/data/styles/baseline_positions.py | 34 +++------ build/data/styles/overflow_positions.json | 26 +++++++ build/data/styles/overflow_positions.py | 12 +++- build/data/styles/self_positions.json | 86 +++++++++++++++++++++++ build/data/styles/self_positions.py | 12 +++- build/data/tags/countries.py | 17 +++-- build/data/tags/crossorigins.py | 14 ++++ build/data/tags/dirs.py | 14 ++++ build/data/tags/languages.py | 17 +++-- build/data/tags/mediatypes.py | 17 +++-- build/data/tags/methods.py | 14 ++++ build/data/tags/referrerpolicies.py | 14 ++++ build/data/tags/rels.py | 14 ++++ build/data/tags/targets.py | 14 ++++ build/styles/align-items.py | 35 ++++++--- build/value.py | 4 ++ build/values.py | 22 +++--- 18 files changed, 364 insertions(+), 64 deletions(-) create mode 100644 build/data/styles/baseline_positions.json create mode 100644 build/data/styles/overflow_positions.json create mode 100644 build/data/styles/self_positions.json diff --git a/build/data/styles/baseline_positions.json b/build/data/styles/baseline_positions.json new file mode 100644 index 00000000..d6f72460 --- /dev/null +++ b/build/data/styles/baseline_positions.json @@ -0,0 +1,62 @@ +[ + { + "id": "AST_LAYOUT_ATTRIBUTE_VALUE_TYPE_FIRST_BASELINE", + "generate_name": "first baseline", + "text": { + "EN": [ + "first baseline" + ], + "FA": [ + "اول خط پایه" + ] + } + }, + { + "id": "AST_LAYOUT_ATTRIBUTE_VALUE_TYPE_BASELINE_FIRST", + "generate_name": "baseline first", + "text": { + "EN": [ + "baseline first" + ], + "FA": [ + "خط پایه اول" + ] + } + }, + { + "id": "AST_LAYOUT_ATTRIBUTE_VALUE_TYPE_LAST_BASELINE", + "generate_name": "last baseline", + "text": { + "EN": [ + "last baseline" + ], + "FA": [ + "آخر خط پایه" + ] + } + }, + { + "id": "AST_LAYOUT_ATTRIBUTE_VALUE_TYPE_BASELINE_LAST", + "generate_name": "baseline last", + "text": { + "EN": [ + "baseline last" + ], + "FA": [ + "خط پایه آخر" + ] + } + }, + { + "id": "AST_LAYOUT_ATTRIBUTE_VALUE_TYPE_BASELINE", + "generate_name": "baseline", + "text": { + "EN": [ + "baseline" + ], + "FA": [ + "خط پایه" + ] + } + } +] diff --git a/build/data/styles/baseline_positions.py b/build/data/styles/baseline_positions.py index 853eed09..7e87ee78 100644 --- a/build/data/styles/baseline_positions.py +++ b/build/data/styles/baseline_positions.py @@ -1,17 +1,15 @@ -import itertools -import os import sys from pathlib import Path parent_dir = Path(__file__).resolve().parent.parent.parent sys.path.append(str(parent_dir)) -sys.path.append(os.path.join(parent_dir)) from lang import Lang from value import Value from values import Values +from prebuild import Prebuild -overflow_positions = Values.And( +baseline_positions = Values.And( [ Value().set_generate_name("first").add_text(Lang.EN, "first").add_text(Lang.FA, "اول"), Value().set_generate_name("last").add_text(Lang.EN, "last").add_text(Lang.FA, "آخر"), @@ -20,32 +18,18 @@ Value().set_generate_name("baseline").add_text(Lang.EN, "baseline").add_text(Lang.FA, "خط پایه"), ], ) -overflow_positions += [ +baseline_positions += [ Value().set_generate_name("baseline").add_text(Lang.EN, "baseline").add_text(Lang.FA, "خط پایه"), ] -print(overflow_positions) - # https://developer.mozilla.org/en-US/docs/Web/CSS/align-items # = # [ first | last ]? && # baseline - -# data = { -# 'EN': [['baseline'], ['last']], -# 'FA': [['خط پایه'], ['آخر']] -# } - -# def generate_ordered_strings(data): -# result = {} -# for lang, text_groups in data.items(): -# combinations = itertools.product(*text_groups) -# result[lang] = [' '.join(' '.join(item) for item in combo) for combo in combinations] -# return result - -# output = generate_ordered_strings(data) - -# # Print the results -# for lang, strings in output.items(): -# print(f"{lang}: {strings}") +if __name__ == '__main__': + strings = Prebuild.to_string( + [value.to_dict() for value in baseline_positions] + ) + Prebuild.print(strings) + Prebuild.save(strings, __file__) diff --git a/build/data/styles/overflow_positions.json b/build/data/styles/overflow_positions.json new file mode 100644 index 00000000..e7867dd6 --- /dev/null +++ b/build/data/styles/overflow_positions.json @@ -0,0 +1,26 @@ +[ + { + "id": "AST_LAYOUT_ATTRIBUTE_VALUE_TYPE_SAFE", + "generate_name": "safe", + "text": { + "EN": [ + "safe" + ], + "FA": [ + "امن" + ] + } + }, + { + "id": "AST_LAYOUT_ATTRIBUTE_VALUE_TYPE_UNSAFE", + "generate_name": "unsafe", + "text": { + "EN": [ + "unsafe" + ], + "FA": [ + "نامناسب" + ] + } + } +] diff --git a/build/data/styles/overflow_positions.py b/build/data/styles/overflow_positions.py index 0999edb7..8e13220f 100644 --- a/build/data/styles/overflow_positions.py +++ b/build/data/styles/overflow_positions.py @@ -1,13 +1,12 @@ -import os import sys from pathlib import Path -parent_dir = Path(__file__).resolve().parent.parent +parent_dir = Path(__file__).resolve().parent.parent.parent sys.path.append(str(parent_dir)) -sys.path.append(os.path.join(parent_dir, "data", "styles")) from lang import Lang from value import Value +from prebuild import Prebuild overflow_positions = [ Value().set_generate_name("safe").add_text(Lang.EN, "safe").add_text(Lang.FA, "امن"), @@ -18,3 +17,10 @@ # = # unsafe | # safe + +if __name__ == '__main__': + strings = Prebuild.to_string( + [value.to_dict() for value in overflow_positions] + ) + Prebuild.print(strings) + Prebuild.save(strings, __file__) diff --git a/build/data/styles/self_positions.json b/build/data/styles/self_positions.json new file mode 100644 index 00000000..610cdeee --- /dev/null +++ b/build/data/styles/self_positions.json @@ -0,0 +1,86 @@ +[ + { + "id": "AST_LAYOUT_ATTRIBUTE_VALUE_TYPE_CENTER", + "generate_name": "center", + "text": { + "EN": [ + "center" + ], + "FA": [ + "وسط" + ] + } + }, + { + "id": "AST_LAYOUT_ATTRIBUTE_VALUE_TYPE_START", + "generate_name": "start", + "text": { + "EN": [ + "start" + ], + "FA": [ + "شروع" + ] + } + }, + { + "id": "AST_LAYOUT_ATTRIBUTE_VALUE_TYPE_END", + "generate_name": "end", + "text": { + "EN": [ + "end" + ], + "FA": [ + "پایان" + ] + } + }, + { + "id": "AST_LAYOUT_ATTRIBUTE_VALUE_TYPE_SELF_START", + "generate_name": "self-start", + "text": { + "EN": [ + "self-start" + ], + "FA": [ + "شروع خود" + ] + } + }, + { + "id": "AST_LAYOUT_ATTRIBUTE_VALUE_TYPE_SELF_END", + "generate_name": "self-end", + "text": { + "EN": [ + "self-end" + ], + "FA": [ + "پایان خود" + ] + } + }, + { + "id": "AST_LAYOUT_ATTRIBUTE_VALUE_TYPE_FLEX_START", + "generate_name": "flex-start", + "text": { + "EN": [ + "flex-start" + ], + "FA": [ + "شروع فلکس" + ] + } + }, + { + "id": "AST_LAYOUT_ATTRIBUTE_VALUE_TYPE_FLEX_END", + "generate_name": "flex-end", + "text": { + "EN": [ + "flex-end" + ], + "FA": [ + "پایان فلکس" + ] + } + } +] diff --git a/build/data/styles/self_positions.py b/build/data/styles/self_positions.py index 3d370504..3ca23685 100644 --- a/build/data/styles/self_positions.py +++ b/build/data/styles/self_positions.py @@ -1,13 +1,12 @@ -import os import sys from pathlib import Path -parent_dir = Path(__file__).resolve().parent.parent +parent_dir = Path(__file__).resolve().parent.parent.parent sys.path.append(str(parent_dir)) -sys.path.append(os.path.join(parent_dir, "data", "styles")) from lang import Lang from value import Value +from prebuild import Prebuild self_positions = [ Value().set_generate_name("center").add_text(Lang.EN, "center").add_text(Lang.FA, "وسط"), @@ -28,3 +27,10 @@ # self-end | # flex-start | # flex-end + +if __name__ == '__main__': + strings = Prebuild.to_string( + [value.to_dict() for value in self_positions] + ) + Prebuild.print(strings) + Prebuild.save(strings, __file__) diff --git a/build/data/tags/countries.py b/build/data/tags/countries.py index ab1a403b..36420990 100644 --- a/build/data/tags/countries.py +++ b/build/data/tags/countries.py @@ -1,6 +1,11 @@ -import json +import sys from pathlib import Path +parent_dir = Path(__file__).resolve().parent.parent.parent +sys.path.append(str(parent_dir)) + +from prebuild import Prebuild + countries = [ {"name": "AFGHANISTAN", "code": "AF"}, {"name": "ALBANIA", "code": "AL"}, @@ -248,7 +253,9 @@ country["name"] = country["name"].lower().strip() country["code"] = country["code"].lower().strip() -if __name__ == "__main__": - j = json.dumps(countries, indent=4, ensure_ascii=False) - print(j) - open(Path(__file__).stem + ".json", "w", encoding="utf-8").write(j + "\n") +if __name__ == '__main__': + strings = Prebuild.to_string( + [value.to_dict() for value in countries] + ) + Prebuild.print(strings) + Prebuild.save(strings, __file__) diff --git a/build/data/tags/crossorigins.py b/build/data/tags/crossorigins.py index c520f25a..09a81770 100644 --- a/build/data/tags/crossorigins.py +++ b/build/data/tags/crossorigins.py @@ -1,7 +1,21 @@ +import sys +from pathlib import Path + +parent_dir = Path(__file__).resolve().parent.parent.parent +sys.path.append(str(parent_dir)) + from lang import Lang from value import Value +from prebuild import Prebuild crossorigins = [ Value().set_generate_name("anonymous").add_text(Lang.EN, "anonymous").add_text(Lang.FA, "ناشناس"), Value().set_generate_name("use-credentials").add_text(Lang.EN, "use credentials").add_text(Lang.FA, "یوز کرید"), ] + +if __name__ == '__main__': + strings = Prebuild.to_string( + [value.to_dict() for value in crossorigins] + ) + Prebuild.print(strings) + Prebuild.save(strings, __file__) diff --git a/build/data/tags/dirs.py b/build/data/tags/dirs.py index 2b1a73ca..69d5ed28 100644 --- a/build/data/tags/dirs.py +++ b/build/data/tags/dirs.py @@ -1,7 +1,21 @@ +import sys +from pathlib import Path + +parent_dir = Path(__file__).resolve().parent.parent.parent +sys.path.append(str(parent_dir)) + from lang import Lang from value import Value +from prebuild import Prebuild dirs = [ Value().set_generate_name("ltr").add_text(Lang.EN, "ltr").add_text(Lang.EN, "left").add_text(Lang.FA, "چپ به راست").add_text(Lang.FA, "چپ"), Value().set_generate_name("rtl").add_text(Lang.EN, "rtl").add_text(Lang.EN, "right").add_text(Lang.FA, "راست به چپ").add_text(Lang.FA, "راست"), ] + +if __name__ == '__main__': + strings = Prebuild.to_string( + [value.to_dict() for value in dirs] + ) + Prebuild.print(strings) + Prebuild.save(strings, __file__) diff --git a/build/data/tags/languages.py b/build/data/tags/languages.py index 2f4c95e2..db4c61bc 100644 --- a/build/data/tags/languages.py +++ b/build/data/tags/languages.py @@ -1,6 +1,11 @@ -import json +import sys from pathlib import Path +parent_dir = Path(__file__).resolve().parent.parent.parent +sys.path.append(str(parent_dir)) + +from prebuild import Prebuild + languages = [ {"name": "Abkhazian", "code": "ab"}, {"name": "Afar", "code": "aa"}, @@ -208,7 +213,9 @@ language["name"] = language["name"].lower().strip() language["code"] = language["code"].lower().strip() -if __name__ == "__main__": - j = json.dumps(languages, indent=4, ensure_ascii=False) - print(j) - open(Path(__file__).stem + ".json", "w", encoding="utf-8").write(j + "\n") +if __name__ == '__main__': + strings = Prebuild.to_string( + [value.to_dict() for value in languages] + ) + Prebuild.print(strings) + Prebuild.save(strings, __file__) diff --git a/build/data/tags/mediatypes.py b/build/data/tags/mediatypes.py index 11e6e115..8d7c63ab 100644 --- a/build/data/tags/mediatypes.py +++ b/build/data/tags/mediatypes.py @@ -1,6 +1,11 @@ -import json +import sys from pathlib import Path +parent_dir = Path(__file__).resolve().parent.parent.parent +sys.path.append(str(parent_dir)) + +from prebuild import Prebuild + mediatypes = [ {"name": "3gpdash-qoe-report+xml", "code": "application/3gpdash-qoe-report+xml"}, {"name": "3gppHalForms+json", "code": "application/3gppHalForms+json"}, @@ -1099,7 +1104,9 @@ mediatype["name"] = mediatype["name"].lower().strip() mediatype["code"] = mediatype["code"].lower().strip() -if __name__ == "__main__": - j = json.dumps(mediatypes, indent=4, ensure_ascii=False) - print(j) - open(Path(__file__).stem + ".json", "w", encoding="utf-8").write(j + "\n") +if __name__ == '__main__': + strings = Prebuild.to_string( + [value.to_dict() for value in mediatypes] + ) + Prebuild.print(strings) + Prebuild.save(strings, __file__) diff --git a/build/data/tags/methods.py b/build/data/tags/methods.py index 03c127d4..907f7481 100644 --- a/build/data/tags/methods.py +++ b/build/data/tags/methods.py @@ -1,7 +1,21 @@ +import sys +from pathlib import Path + +parent_dir = Path(__file__).resolve().parent.parent.parent +sys.path.append(str(parent_dir)) + from lang import Lang from value import Value +from prebuild import Prebuild methods = [ Value().set_generate_name("get").add_text(Lang.EN, "get").add_text(Lang.FA, "گت"), Value().set_generate_name("post").add_text(Lang.EN, "post").add_text(Lang.FA, "پست"), ] + +if __name__ == '__main__': + strings = Prebuild.to_string( + [value.to_dict() for value in methods] + ) + Prebuild.print(strings) + Prebuild.save(strings, __file__) diff --git a/build/data/tags/referrerpolicies.py b/build/data/tags/referrerpolicies.py index 1b4d00a1..8771c0a6 100644 --- a/build/data/tags/referrerpolicies.py +++ b/build/data/tags/referrerpolicies.py @@ -1,5 +1,12 @@ +import sys +from pathlib import Path + +parent_dir = Path(__file__).resolve().parent.parent.parent +sys.path.append(str(parent_dir)) + from lang import Lang from value import Value +from prebuild import Prebuild referrerpolicies = [ Value().set_generate_name("no-referrer").add_text(Lang.EN, "no-referrer").add_text(Lang.FA, "بدون ارجاع"), @@ -10,3 +17,10 @@ Value().set_generate_name("strict-origin-when-cross-origin").add_text(Lang.EN, "strict-origin-when-cross-origin").add_text(Lang.FA, "حساس به منبع"), Value().set_generate_name("unsafe-url").add_text(Lang.EN, "unsafe-url").add_text(Lang.FA, "آدرس ناامن"), ] + +if __name__ == '__main__': + strings = Prebuild.to_string( + [value.to_dict() for value in referrerpolicies] + ) + Prebuild.print(strings) + Prebuild.save(strings, __file__) diff --git a/build/data/tags/rels.py b/build/data/tags/rels.py index 85c87126..7cfa5547 100644 --- a/build/data/tags/rels.py +++ b/build/data/tags/rels.py @@ -1,5 +1,12 @@ +import sys +from pathlib import Path + +parent_dir = Path(__file__).resolve().parent.parent.parent +sys.path.append(str(parent_dir)) + from lang import Lang from value import Value +from prebuild import Prebuild rels = [ Value().set_generate_name("alternate").add_text(Lang.EN, "alternate").add_text(Lang.FA, "متناوب"), @@ -16,3 +23,10 @@ Value().set_generate_name("search").add_text(Lang.EN, "search").add_text(Lang.FA, "جستجو"), Value().set_generate_name("tag").add_text(Lang.EN, "tag").add_text(Lang.FA, "برچسب") ] + +if __name__ == '__main__': + strings = Prebuild.to_string( + [value.to_dict() for value in rels] + ) + Prebuild.print(strings) + Prebuild.save(strings, __file__) diff --git a/build/data/tags/targets.py b/build/data/tags/targets.py index 21f7a405..e8a32304 100644 --- a/build/data/tags/targets.py +++ b/build/data/tags/targets.py @@ -1,5 +1,12 @@ +import sys +from pathlib import Path + +parent_dir = Path(__file__).resolve().parent.parent.parent +sys.path.append(str(parent_dir)) + from lang import Lang from value import Value +from prebuild import Prebuild targets = [ Value().set_generate_name("_blank").add_text(Lang.EN, "blank").add_text(Lang.FA, "جدید"), @@ -7,3 +14,10 @@ Value().set_generate_name("_parent").add_text(Lang.EN, "parent").add_text(Lang.FA, "والدین"), Value().set_generate_name("_top").add_text(Lang.EN, "top").add_text(Lang.FA, "بالا"), ] + +if __name__ == '__main__': + strings = Prebuild.to_string( + [value.to_dict() for value in targets] + ) + Prebuild.print(strings) + Prebuild.save(strings, __file__) diff --git a/build/styles/align-items.py b/build/styles/align-items.py index 24dff7b0..994638d0 100644 --- a/build/styles/align-items.py +++ b/build/styles/align-items.py @@ -20,15 +20,9 @@ property.set_text(Lang.FA, "الاین-آیتمز") property.set_type(Type.String) property.add_reserve_values([ - Value().set_generate_name("stretch").add_text(Lang.EN, "stretch").add_text(Lang.FA, "کشیدن"), + Value().set_generate_name("normal").add_text(Lang.EN, "normal").add_text(Lang.FA, "نرمال"), + Value().set_generate_name("stretch").add_text(Lang.EN, "stretch").add_text(Lang.FA, "کشیده"), Value().set_generate_name("center").add_text(Lang.EN, "center").add_text(Lang.FA, "وسط"), - Value().set_generate_name("flex-start").add_text(Lang.EN, "flex-start").add_text(Lang.FA, "شروع-فلکس"), - Value().set_generate_name("flex-end").add_text(Lang.EN, "flex-end").add_text(Lang.FA, "پایان-فلکس"), - Value().set_generate_name("space-between").add_text(Lang.EN, "space-between").add_text(Lang.FA, "فضا-بین"), - Value().set_generate_name("space-around").add_text(Lang.EN, "space-around").add_text(Lang.FA, "فضا-دور"), - Value().set_generate_name("space-evenly").add_text(Lang.EN, "space-evenly").add_text(Lang.FA, "فضا-یکسان"), - Value().set_generate_name("initial").add_text(Lang.EN, "initial").add_text(Lang.FA, "اولیه"), - Value().set_generate_name("inherit").add_text(Lang.EN, "inherit").add_text(Lang.FA, "ارث بری"), ]) property_dict = property.to_dict() @@ -36,3 +30,28 @@ property_str = Prebuild.to_string(property_dict) Prebuild.print(property_str) Prebuild.save(property_str, __file__) + +# https://developer.mozilla.org/en-US/docs/Web/CSS/align-items +# align-items = +# normal | +# stretch | +# | +# [ ? ] | +# anchor-center + +# = +# [ first | last ]? && +# baseline + +# = +# unsafe | +# safe + +# = +# center | +# start | +# end | +# self-start | +# self-end | +# flex-start | +# flex-end diff --git a/build/value.py b/build/value.py index 58c537cf..942b24e4 100644 --- a/build/value.py +++ b/build/value.py @@ -44,3 +44,7 @@ def to_dict(self): "generate_name": self.generate_name, "text": self.text.to_dict(), } + + def to_string(self): + """Convert the attribute value to a string, including all information.""" + return Prebuild.to_string(self.to_dict()) diff --git a/build/values.py b/build/values.py index aeaaa934..620f684b 100644 --- a/build/values.py +++ b/build/values.py @@ -2,6 +2,15 @@ from value import Value class Values: + @staticmethod + def generate_ordered_strings(data): + result = {} + for lang, text_groups in data.items(): + combinations = itertools.product(*text_groups) + result[lang] = [' '.join(''.join(item) for item in combo) for combo in combinations] + + return result + @staticmethod def And(*value_groups): """ @@ -13,13 +22,6 @@ def And(*value_groups): Returns: A list of Value objects representing all combinations. """ - def generate_ordered_strings(data): - result = {} - for lang, text_groups in data.items(): - combinations = itertools.product(*text_groups) - result[lang] = [' '.join(' '.join(item) for item in combo) for combo in combinations] - - return result combinations = itertools.product(*value_groups) @@ -29,7 +31,7 @@ def generate_ordered_strings(data): for perm in permutations: combined_name = [] - combined_text = {} # key are language codes, values are array of text + combined_text = {} for value in perm: combined_name.append(value.generate_name) for lang, text in value.text.translations.items(): @@ -40,9 +42,9 @@ def generate_ordered_strings(data): combined_value = Value() combined_value.set_generate_name(" ".join(combined_name)) - output = generate_ordered_strings(combined_text) + output = Values.generate_ordered_strings(combined_text) for lang, strings in output.items(): - value.add_text(lang, strings) + combined_value.add_text(lang, strings[0]) result.append(combined_value)