From 9174d9b3c33f49e375146e3c5cc9ff405dc7e985 Mon Sep 17 00:00:00 2001 From: "ALI Mohammadiyeh (Max Base)" Date: Wed, 8 Jan 2025 22:24:41 +0100 Subject: [PATCH] start working on build structure --- build/__pycache__/attribute.cpython-312.pyc | Bin 0 -> 2075 bytes build/__pycache__/element.cpython-312.pyc | Bin 0 -> 2040 bytes build/__pycache__/lang.cpython-312.pyc | Bin 0 -> 1354 bytes build/__pycache__/text.cpython-312.pyc | Bin 0 -> 1526 bytes build/__pycache__/type.cpython-312.pyc | Bin 0 -> 468 bytes build/attribute.py | 45 ++++++++++++++++++++ build/element.py | 44 +++++++++++++++++++ build/lang.py | 26 +++++++++++ config/tags/a.py => build/styles/display.py | 0 config/tags/b.py => build/styles/float.py | 0 build/tags/a.py | 30 +++++++++++++ config/tags/div.py => build/tags/b.py | 0 config/tags/form.py => build/tags/div.py | 0 config/tags/li.py => build/tags/form.py | 0 config/tags/ul.py => build/tags/li.py | 0 build/tags/ul.py | 0 build/text.py | 25 +++++++++++ build/type.py | 6 +++ build/value.py | 0 19 files changed, 176 insertions(+) create mode 100644 build/__pycache__/attribute.cpython-312.pyc create mode 100644 build/__pycache__/element.cpython-312.pyc create mode 100644 build/__pycache__/lang.cpython-312.pyc create mode 100644 build/__pycache__/text.cpython-312.pyc create mode 100644 build/__pycache__/type.cpython-312.pyc create mode 100644 build/attribute.py create mode 100644 build/element.py create mode 100644 build/lang.py rename config/tags/a.py => build/styles/display.py (100%) rename config/tags/b.py => build/styles/float.py (100%) create mode 100644 build/tags/a.py rename config/tags/div.py => build/tags/b.py (100%) rename config/tags/form.py => build/tags/div.py (100%) rename config/tags/li.py => build/tags/form.py (100%) rename config/tags/ul.py => build/tags/li.py (100%) create mode 100644 build/tags/ul.py create mode 100644 build/text.py create mode 100644 build/type.py create mode 100644 build/value.py diff --git a/build/__pycache__/attribute.cpython-312.pyc b/build/__pycache__/attribute.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e1735dadd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1h%fgVhZeES#v?*bVQ^t+57^rmIO=Tqj-;;shUpDCQ^F-EO&vN=Q4T}h%{LTV6fHX z&xM>N@+Ttl`3eefgvooJ8Sg})-W7|$!&dY$zSESVD8G|A`1?nDS;?IdAkyq#uwSpj literal 0 HcmV?d00001 diff --git a/build/__pycache__/element.cpython-312.pyc b/build/__pycache__/element.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5a90c5a4992e0cb291aa38a0729b0a8662b52e5e GIT binary patch literal 2040 zcmaJ>&2Jk;6rWkI?X|Jv6ddwVoK8d{*angwph%@k6g3p}&;$`qR?uqe*}5Cn>#)0S zu$7=3a!90BAp&F$9C`$b1pfkOE{#GJv!YU@a^aT72SiW2H@oX3rsYZdcHX>?nfK=R z-mlqgngH!R{=EF7OvqytA_7@Z`vUx$gcD9JQlUjkaV=R=C02}4B9ZqAk8Kbx-Lf8KW2D zTn3)tap1{%LQVR~_bj7g*j_0-Rs_Oz48Hc12)9aCi6#`tJk$ufAO1nx@h%gPIu>=f z`lK6DtU6-1qMJ60?l%Vy zmyPT+v{NPL1&HkQ0t=IMGO+f~xQ3^lGHnb-3H?WfsB@96lY_$fP5GfReL?u z1R%=o%fKKNvIPHbS~}?wDj{hp0wX0N>0yyHyxjBhl$;cJ`#GI+&2x0ywRF#{+Gt`+9F4y$3p_QuK5VkI!%oq#OS1?C}#_=;oJD8aJGB8M1$!w>#Qv1rtt}=4(&7boR zm5V{*9TXI9;nO7P+Hq z^hGc^wT<|7$AGPqKl6nL!*B29FK(twmaucWC^`c?x-=-x zl5JX&%FyDSd;U+19SQGQlGZ4v-^vTHqC#3B(DqYTs`hQe30gnwZ{}5*&bV1ZsOwJs z4QARUtHw>c%yi2-h6eyZ_9YmB*!BYb0tsp&0EBW|w@ePBM9jcrBR}a?H4Gn44PVAr zKRGs>VF=jBMFae$n%|slWqP--Z(YATe;6ZuqlXH4slPe7GubMP z>=!0?3zID{ytZ>~KR>pcAKS~nb}&Bq)ASG1?U;17=lAhT_ul$KZf15eU-x`B{RH=( zq>{bqLy}CT|2a}XcJUd1IoCh)ZhB5ta4h4v(=Y>(vSNXWqiUt0QS^pen;Zq-8q$se$03xS;SM!RcoLqg{8^u0H4zIor% zn?EdT7;wFLxn3)20I!wPUq%mf7=m4(Fb51afsuXM-6;cyWjyuaVw7o2+wbj=Pi5)M zV7cS0wY+2cgH*j+pfiopU1TW}24xyRS>rk*o3P)@E*t360YAsIO(^HrbjL{bTVB29 z>jT6}m#VFE1I;cZG|?D&L=#vZNb19cTtyfksZ1at2^pxGI$Cr3I%BqH*ZEI&h_^Mo z8n@%fj+eL{1~Rszsx2F6%>2trm- zj8m&?sp&E1DyM1PQlY-9c;t6zHlS_7$#boMWJ5s^nChlnBkNX2f85wxjQ<8h`z zHC;BxG9mwqS?a_IG^i#A#qsTXTlb!ur-h39{TV|HN_JNB9R#1M`D62*kmdecQ9QlX zpU&g=f_iE5+rHjtQT-Xa8VMX7xyt>Z8u&-kF;#N3OmnKCn$*DY;R44&mprTr^=PH4 z-R`wv#C0)E4TtMCi&+x}B4aB344MsiRT$r1-&+5>F!7==@%a4S#U~e^PX4O@S-A4t zypr{#9FgrM63~V#G|fzx8a3q>Rh*5+=w4~Qm*iLDPm$2Zx97#zC`m3 zGP>+H3Dwuks9z_)N3#j7;@HOgE2DTwbH+qRgWMNwh1x|#hm;y$_hJf})R^wlDW;Up zl+yf6y@s!ADW$X5)BFM#GVtmR)tP_pxAt1UwSNEi7koh7tFzL+!oA~~-kDds%C3oT ua3d@15`wly2zg7#$@C$hX-@(%ezxvg57^H9!?nM_X@P#^CkHT@QN9Osqb_0q literal 0 HcmV?d00001 diff --git a/build/__pycache__/text.cpython-312.pyc b/build/__pycache__/text.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c5e24653dfc14ed94a150446cad62d4bb1e30023 GIT binary patch literal 1526 zcmZ`(-HRJl6u);elb!BPNUZJJh`W0iSLujm38-LO1=(u5ph2kk5F*2M?re6}NhZ#n z1QSwOWFJ;2_~649MDVrji;w*ueA!qe%V42cU;1V@4?>?jXFfvubr{Z^bI&~=^E>Cv z?}frV0jmA|U9*xSWZLyq@Kf2byehmYeEH{?`vj0Qa^XT4eiVm17I>JlT1zn zJ0LC@5(}h+`jEK>$&E1JZRzpQ_1p3m6eAsPOJW%I=(UXtjgMW=k&Vv+f5)*y*|^3% z-fDc+bv@AtAz`J{k95m&+iqxCg96r2$y9_yB4WGb_?6{-^-sM#!Q?g;l@ZEukpmD8 z$dC@nPG*~V_h?XT!UsIdHl&x}=JRZ2uRvt6e{dYOE=OvrU* zr~v5L{0J#%`E9+YXDzZE)^WS4y|te5yM&Qw{K|qC(RNtqgvdbZ7nx4E0eE_(9eo4X?=P6u#mn zJ>DK2lDjwv=}>2C0aD2Kf$friN@sq`k4tN#(%PNU>-*aM^78)XadFzEKZ@1A7TM9O z7jJLgzIe2H<<8>Oqtexf8hLr;>84DV^#a6(Js>;Nw!lG3SraJQ(|<{3!}m2<>cJZu ze!J%c;VeRug+3Fmja$xxK4RM9VFiZwC2)%|3UrW?#ZLxwF7z#Q85r?krrKG&g-$S# zy76P-hr*5Gz2b}GA{!OikWwm_K^-wk}>zgk35=*dv$zMPg zmw~H#i^LJ)5(1pmm|TOX?C$J)p^yVC&c2?8uPlGY#WsWuS(O=C01mVO26KSn z8<%!W5OE4W*!trPH^oY3WB~{;AqFOgp~+*;6fkdQuwaTfV@i>zNK`PQ33)tUd>uE}sW)X7j zF+qst5E^?pbYh-I=pnS7O-DiqdjlqmI=kE*Qc(-Xed1H8=6MdWUCOI&^a57#cI(sn zxz!vwWNLMM@16{TsioVFJ+}Jc$iY^?cBxJxpJ(0#;y;;I7|g+kaI!2M&zdRh$+Oln vSAMSh`&+N3z;v(_D~Wu-*gAWWKK;@^WMy(h*X& literal 0 HcmV?d00001 diff --git a/build/attribute.py b/build/attribute.py new file mode 100644 index 00000000..35ce6428 --- /dev/null +++ b/build/attribute.py @@ -0,0 +1,45 @@ +from text import Text +from type import Type + +class Attribute: + def __init__(self, generate_name): + self.generate_name = generate_name + self.text = Text() + self.id = "AST_LAYOUT_ATTRIBUTE_" + generate_name.upper() + self.type = Type.String + self.reserved_values = [] + + def set_generate_name(self, generate_name): + """Set the generate name for the main element.""" + self.generate_name = generate_name + return self + + def set_type(self, type): + """Set the type of the attribute.""" + self.type = type + return self + + def add_text(self, language_code, text): + """Set text for the main element.""" + self.text.add_translation(language_code, text) + return self + + def add_reserve_value(self, value): + """Add a reserved value for the attribute.""" + self.reserved_values.append(value) + return self + + def validate(self): + """Check if all languages have a value for the text.""" + self.text.validate() + return self + + def to_dict(self): + """Convert the attribute to a dictionary, including all information.""" + return { + "id": self.id, + "generate_name": self.generate_name, + "type": self.type, + "text": self.text.to_dict(), + "reserved_values": self.reserved_values, + } diff --git a/build/element.py b/build/element.py new file mode 100644 index 00000000..f63f42c2 --- /dev/null +++ b/build/element.py @@ -0,0 +1,44 @@ +from text import Text +from attribute import Attribute + +class Element: + def __init__(self): + self.text = Text() + self.attributes = [] + self.is_mother = False + + def is_mother(self, is_mother): + """Set the mother status for the main element.""" + self.is_mother = is_mother + + def set_generate_name(self, generate_name): + """Set the generate name for the main element.""" + self.generate_name = generate_name + self.id = "AST_LAYOUT_TYPE_" + generate_name.upper() + + def set_text(self, language_code, text): + """Set text for the main element.""" + self.text.add_translation(language_code, text) + + def add_attribute(self, attribute_generate_name): + """Add an attribute with its own text translations.""" + attribute = Attribute(attribute_generate_name) + self.attributes.append(attribute) + + return attribute + + def to_dict(self): + """Convert the element to a dictionary, including all attributes.""" + for attr in self.attributes: + attr.validate() + + return { + "id": self.id, + "is_mother": self.is_mother, + "generate_name": self.generate_name, + "text": self.text.to_dict(), + "attributes": [ + attr.to_dict() for attr in self.attributes + ], + } + diff --git a/build/lang.py b/build/lang.py new file mode 100644 index 00000000..0c3ce0eb --- /dev/null +++ b/build/lang.py @@ -0,0 +1,26 @@ +class Lang: + languages = {} + + @classmethod + def add_lang(cls, name, full_name, international_name): + """Add a new language to the list of supported languages.""" + cls.languages[name] = { + "full_name": full_name, + "international_name": international_name, + } + setattr(cls, name, name) + + @classmethod + def get_languages(cls): + """Get the list of supported languages.""" + return cls.languages + + def __getattr__(self, name): + """Get the object for a specific language.""" + return self.languages.get(name.upper(), None) + +# Add supported languages +Lang.add_lang("EN", "English", "English") +Lang.add_lang("FA", "Persian", "فارسی") +# Lang.add_lang("ES", "Spanish", "Español") +# Lang.add_lang("AR", "Arabic", "العربية") diff --git a/config/tags/a.py b/build/styles/display.py similarity index 100% rename from config/tags/a.py rename to build/styles/display.py diff --git a/config/tags/b.py b/build/styles/float.py similarity index 100% rename from config/tags/b.py rename to build/styles/float.py diff --git a/build/tags/a.py b/build/tags/a.py new file mode 100644 index 00000000..84fed914 --- /dev/null +++ b/build/tags/a.py @@ -0,0 +1,30 @@ +import sys +import json +from pathlib import Path + +parent_dir = Path(__file__).resolve().parent.parent +sys.path.append(str(parent_dir)) + +from element import Element +from lang import Lang +from type import Type + +if __name__ == "__main__": + element = Element() + element.is_mother(True) + element.set_generate_name("a") + element.set_text(Lang.EN, "link") + element.set_text(Lang.FA, "لینک") + + element.add_attribute() \ + .set_generate_name("href") \ + .set_type(Type.String) \ + .add_text(Lang.EN, "url") \ + .add_text(Lang.FA, "آدرس") \ + .add_reserve_value(Value( + + )) + + element_dict = element.to_dict() + + print(json.dumps(element_dict, indent=4, ensure_ascii=False)) diff --git a/config/tags/div.py b/build/tags/b.py similarity index 100% rename from config/tags/div.py rename to build/tags/b.py diff --git a/config/tags/form.py b/build/tags/div.py similarity index 100% rename from config/tags/form.py rename to build/tags/div.py diff --git a/config/tags/li.py b/build/tags/form.py similarity index 100% rename from config/tags/li.py rename to build/tags/form.py diff --git a/config/tags/ul.py b/build/tags/li.py similarity index 100% rename from config/tags/ul.py rename to build/tags/li.py diff --git a/build/tags/ul.py b/build/tags/ul.py new file mode 100644 index 00000000..e69de29b diff --git a/build/text.py b/build/text.py new file mode 100644 index 00000000..f6ca59e6 --- /dev/null +++ b/build/text.py @@ -0,0 +1,25 @@ +from lang import Lang + +class Text: + def __init__(self): + self.translations = {} + + def add_translation(self, language_code, text): + """Add or update a translation for a specific language.""" + if language_code not in self.translations: + self.translations[language_code] = [] + self.translations[language_code].append(text) + + def validate(self): + """Check if all languages have a value for the text.""" + langs = Lang().get_languages() + + for lang_code in langs: + if lang_code not in self.translations: + raise ValueError(f"Missing translation for {lang_code}") + + def to_dict(self): + """Convert translations to dictionary format.""" + self.validate() + + return self.translations diff --git a/build/type.py b/build/type.py new file mode 100644 index 00000000..4657c7d2 --- /dev/null +++ b/build/type.py @@ -0,0 +1,6 @@ +class Type: + """Type of an attribute.""" + String = "AST_TYPE_STRING" + Number = "AST_TYPE_NUMBER" + Boolean = "AST_TYPE_BOOLEAN" + Any = "AST_TYPE_ANY" diff --git a/build/value.py b/build/value.py new file mode 100644 index 00000000..e69de29b