{"id":17354903,"url":"https://github.com/yididev/utemplates","last_synced_at":"2025-04-14T23:10:54.488Z","repository":{"id":202850149,"uuid":"705113342","full_name":"YidiDev/UTemplates","owner":"YidiDev","description":null,"archived":false,"fork":false,"pushed_at":"2023-11-16T21:55:44.000Z","size":190,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T12:05:05.255Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YidiDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-15T04:00:48.000Z","updated_at":"2024-09-28T15:10:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"130375aa-7dd6-4196-9cbd-f25aa96c1fc4","html_url":"https://github.com/YidiDev/UTemplates","commit_stats":null,"previous_names":["yididev/utemplates"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YidiDev%2FUTemplates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YidiDev%2FUTemplates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YidiDev%2FUTemplates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YidiDev%2FUTemplates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YidiDev","download_url":"https://codeload.github.com/YidiDev/UTemplates/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248975316,"owners_count":21192210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T17:41:30.775Z","updated_at":"2025-04-14T23:10:54.466Z","avatar_url":"https://github.com/YidiDev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UTemplates - Python Templating Engine\n\nUTemplates is a Python templating engine focused on HTML but with the potential to be extended to other languages. It facilitates the creation, manipulation, and rendering of HTML elements programmatically using Python classes and methods.\n\n## Table of Contents\n- [Installation](#installation)\n- [Getting Started](#getting-started)\n- [Usage](#usage)\n  - [Configuration](#configuration)\n  - [Creating Elements](#creating-elements)\n  - [Rendering HTML](#rendering-html)\n  - [Utilities](#utilities)\n  - [Integrations](#integrations)\n- [License](#license)\n\n## Installation\n\n1. Clone the repository or download the source code.\n\n```bash\npip install utemplates\n```\n\n## Getting Started\n\nBefore you start using UTemplates, ensure you have a Python environment set up. UTemplates supports Python 3.7 and newer.\n\n## Usage\n\n### Configuration\n\nTo customize the behavior of UTemplates, you can modify or provide a `utemplates_config.json` configuration file. This file allows you to define conversion functions that will be applied to values before rendering them. The path to the configuration file can be set through an environment variable `UTEMPLATES_CONFIG_PATH`.\n\n#### Config Format\n\nThe configuration file is a JSON file with the following structure:\n\n```json\n{\n  \"conversions\": [\n    \"module1.submodule.function1\",\n    \"module2.submodule.function2\"\n  ]\n}\n```\n\n- Each string in the \"conversions\" list is a dot-path to a conversion function that should be imported and applied during rendering.\n\n### Creating Elements\n\nUTemplates provides classes to structure HTML content. These can be generic or specific HTML elements:\n\n- **GeneralBaseElement**: Abstract base class for all HTML elements.\n- **GroupedBaseElement**: Class for grouping multiple elements.\n- **BaseHTMLElement**: Class for creating standard HTML elements.\n- **SafeHTMLElement**: Class for wrapping pre-processed HTML strings that should not be escaped.\n\nYou can create instances of these classes by calling their constructors and passing the appropriate arguments.\n\n#### Example\n\n```python\nfrom utemplates.html_specific.base import BaseHTMLElement\n\ndiv_element = BaseHTMLElement(\"div\", {\"class\": \"container\"}, \"Hello World\")\n```\n\nThis example creates a `\u003cdiv\u003e` element with the class \"container\" and containing the text \"Hello World\".\n\n### Rendering HTML\n\nTo render HTML content, use the provided `render` method from the `rendering` module. It takes a string, a list of strings or elements, or a single element and generates an HTML string.\n\n#### Example\n\n```python\nfrom utemplates.rendering import render\n\n# For a single element\nrendered_html = render(div_element())\n\n# For multiple elements\nrendered_html = render([div_element(), another_element()])\n\n# You can also save the rendered HTML to a file\nfrom utemplates.rendering import save_to_file\nsave_to_file(rendered_html, 'output.html')\n```\n\n### Utilities\n\nThe `utils.py` module includes utility functions:\n\n- **convert_value**: Applies configured conversion functions to a given value.\n\n### Integrations\n\nUTemplates offers integration support for the Django framework to render responses directly:\n\n#### Django Integration\n\n```python\nfrom utemplates.integrations.django_integrations import render_to_response\n\ndef my_view(request):\n    html_content = create_some_html_content()\n    return render_to_response(html_content)\n```\n\n## License\n\nUTemplates is open-sourced under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyididev%2Futemplates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyididev%2Futemplates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyididev%2Futemplates/lists"}