Skip to content

Commit

Permalink
Add include to layout-type, fix sync script, update gitignore, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
BaseMax committed Nov 30, 2024
1 parent be893b2 commit 48ddb4e
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 380 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ src/update.tmp

# src/generated-config/
# config/generated-json/

config/module/__pycache__
8 changes: 8 additions & 0 deletions config/json/layout/type.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"items": [
{
"id": "AST_LAYOUT_TYPE_INCLUDE",
"text": {
"en": "include",
"fa": "بارگیری"
},
"is_mother": false
},
{
"id": "AST_LAYOUT_TYPE_PARAGRAPH_RAW",
"text": {
Expand Down
5 changes: 5 additions & 0 deletions config/layout/type.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
items:
- id: AST_LAYOUT_TYPE_INCLUDE
text:
en: include
fa: بارگیری
is_mother: false
- id: AST_LAYOUT_TYPE_PARAGRAPH_RAW
text:
en: content
Expand Down
24 changes: 20 additions & 4 deletions config/module/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
from typing import Any, Dict, List

import yaml
from typing import Any, Dict, List


def load_yaml(file_path: str) -> List[Dict[str, Any]]:
Expand Down Expand Up @@ -33,7 +31,25 @@ def error(msg: str) -> None:
exit(1)


def command(item: Dict[str, Any], prefix: str, value: str) -> str:
def command_layout_type(item: Dict[str, Any], prefix: str, value: str) -> str:
itemid = item["id"]
idtext = itemid.replace(prefix, "")
idtextlower = idtext.lower()
generate_name = item.get("generate_name", idtext.lower())
is_mother = str(item.get("is_mother", False)).lower()

return (
f"({itemid}, "
+ f'"{idtext}", '
+ f'"{idtextlower}", '
+ f'"{generate_name}", '
+ f'"{value}", '
+ f"{is_mother}"
+ f")\n"
)


def command_layout_style_type(item: Dict[str, Any], prefix: str, value: str) -> str:
"""
Generates a formatted command string based on the item and value provided.
:param item: Dictionary containing item data.
Expand Down
26 changes: 13 additions & 13 deletions config/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any, Dict, List

import yaml
from module.utils import command
from module.utils import command_layout_type, command_layout_style_type

SELECTED_LANGUAGE = "fa"

Expand Down Expand Up @@ -131,31 +131,31 @@ def prettify_layout_attribute_style_type(

if "generate_name" not in item:
if isinstance(values, str):
return key_hide + command(item, "AST_LAYOUT_ATTRIBUTE_STYLE_TYPE_", values)
return key_hide + command_layout_style_type(item, "AST_LAYOUT_ATTRIBUTE_STYLE_TYPE_", values)
else:
result = ""
for index, value in enumerate(values):
if index == 0:
result += key_hide + command(
result += key_hide + command_layout_style_type(
item, "AST_LAYOUT_ATTRIBUTE_STYLE_TYPE_", value
)
else:
result += key_repeat + command(
result += key_repeat + command_layout_style_type(
item, "AST_LAYOUT_ATTRIBUTE_STYLE_TYPE_", value
)
return result
else:
if isinstance(values, str):
return key_main + command(item, "AST_LAYOUT_ATTRIBUTE_STYLE_TYPE_", values)
return key_main + command_layout_style_type(item, "AST_LAYOUT_ATTRIBUTE_STYLE_TYPE_", values)
else:
result = ""
for index, value in enumerate(values):
if index == 0:
result += key_main + command(
result += key_main + command_layout_style_type(
item, "AST_LAYOUT_ATTRIBUTE_STYLE_TYPE_", value
)
else:
result += key_repeat + command(
result += key_repeat + command_layout_style_type(
item, "AST_LAYOUT_ATTRIBUTE_STYLE_TYPE_", value
)
return result
Expand Down Expand Up @@ -245,25 +245,25 @@ def prettify_layout_type(item: Dict[str, Any], group: Dict[str, Any]) -> str:

if "generate_name" not in item:
if isinstance(values, str):
return key_hide + command(item, "AST_LAYOUT_TYPE_", values)
return key_hide + command_layout_type(item, "AST_LAYOUT_TYPE_", values)
else:
result = ""
for index, value in enumerate(values):
if index == 0:
result += key_hide + command(item, "AST_LAYOUT_TYPE_", value)
result += key_hide + command_layout_type(item, "AST_LAYOUT_TYPE_", value)
else:
result += key_repeat + command(item, "AST_LAYOUT_TYPE_", value)
result += key_repeat + command_layout_type(item, "AST_LAYOUT_TYPE_", value)
return result
else:
if isinstance(values, str):
return key_main + command(item, "AST_LAYOUT_TYPE_", values)
return key_main + command_layout_type(item, "AST_LAYOUT_TYPE_", values)
else:
result = ""
for index, value in enumerate(values):
if index == 0:
result += key_main + command(item, "AST_LAYOUT_TYPE_", value)
result += key_main + command_layout_type(item, "AST_LAYOUT_TYPE_", value)
else:
result += key_repeat + command(item, "AST_LAYOUT_TYPE_", value)
result += key_repeat + command_layout_type(item, "AST_LAYOUT_TYPE_", value)
return result


Expand Down
11 changes: 4 additions & 7 deletions example/input.salam
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
صفحه:
برچسب:
محتوا = «نام»
برای=«input»
فرم:
نوع=«GET»
منبع=«https://yourapi.ir»
روش=«»
تمام

ورودی:
شناسه=«input»
تمام
تمام
10 changes: 10 additions & 0 deletions example/test55.salam
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
صفحه:
برچسب:
محتوا = «نام»
برای=«input»
تمام

ورودی:
شناسه=«input»
تمام
تمام
Loading

0 comments on commit 48ddb4e

Please sign in to comment.