django-template-simplify


Namedjango-template-simplify JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/rails-inspire-django/django-template-simplify
SummaryA set of tools to help simplify your Django templates.
upload_time2024-08-26 14:33:37
maintainerNone
docs_urlNone
authorMichael Yin
requires_python>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # README

A set of tools to help simplify your Django templates

```shell
$ pip install django-template-simplify
```

Then add the app into `INSTALLED_APPS` in settings.py

```python
INSTALLED_APPS = [
    ...,
    'template_simplify',
]
```

## dom_id

`dom_id` is a helper method that returns a unique DOM ID based on the object's class name and primary key.

```html
{% load template_simplify %}

{% dom_id instance %}               ->  task_1
{% dom_id instance 'detail' %}      ->  detail_task_1
{% dom_id Task %}                   ->  new_task
```

1. `dom_id` first argument can be string, instance or Model class
2. `dom_id` second argument is optional string that will be used as `prefix`.

You can also use it in your Django view code.

```python
from template_simplify import dom_id

target = dom_id(instance, "detail_container")
```

We can say goodbye to `id="task-{{ task.pk }}"` and use `id="{% dom_id task %}"` instead.

The benefit is, **it simplified the DOM ID generation in Python and Django template, and avoid typo error in many cases.**

## class_names

Inspired by JS [classnames](https://www.npmjs.com/package/classnames) and Rails `class_names`

`class_names` can help **conditionally render css classes**

```html
{% load template_simplify %}

<div class="{% class_names test1=True 'test2' ring-slate-900/5=True already-sign-in=request.user.is_authenticated %}"></div>

'<div class="test1 test2 ring-slate-900/5 dark:bg-slate-800 %}"></div>'
```

It can also work well with TailwindCSS's some special char such as `/` and `:`


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rails-inspire-django/django-template-simplify",
    "name": "django-template-simplify",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Michael Yin",
    "author_email": "michaelyin@accordbox.com",
    "download_url": "https://files.pythonhosted.org/packages/a3/72/fc02d8c1bf3bcb3ee31a9ed4effc44d027203efe612c1916f4753135feef/django_template_simplify-1.0.2.tar.gz",
    "platform": null,
    "description": "# README\n\nA set of tools to help simplify your Django templates\n\n```shell\n$ pip install django-template-simplify\n```\n\nThen add the app into `INSTALLED_APPS` in settings.py\n\n```python\nINSTALLED_APPS = [\n    ...,\n    'template_simplify',\n]\n```\n\n## dom_id\n\n`dom_id` is a helper method that returns a unique DOM ID based on the object's class name and primary key.\n\n```html\n{% load template_simplify %}\n\n{% dom_id instance %}               ->  task_1\n{% dom_id instance 'detail' %}      ->  detail_task_1\n{% dom_id Task %}                   ->  new_task\n```\n\n1. `dom_id` first argument can be string, instance or Model class\n2. `dom_id` second argument is optional string that will be used as `prefix`.\n\nYou can also use it in your Django view code.\n\n```python\nfrom template_simplify import dom_id\n\ntarget = dom_id(instance, \"detail_container\")\n```\n\nWe can say goodbye to `id=\"task-{{ task.pk }}\"` and use `id=\"{% dom_id task %}\"` instead.\n\nThe benefit is, **it simplified the DOM ID generation in Python and Django template, and avoid typo error in many cases.**\n\n## class_names\n\nInspired by JS [classnames](https://www.npmjs.com/package/classnames) and Rails `class_names`\n\n`class_names` can help **conditionally render css classes**\n\n```html\n{% load template_simplify %}\n\n<div class=\"{% class_names test1=True 'test2' ring-slate-900/5=True already-sign-in=request.user.is_authenticated %}\"></div>\n\n'<div class=\"test1 test2 ring-slate-900/5 dark:bg-slate-800 %}\"></div>'\n```\n\nIt can also work well with TailwindCSS's some special char such as `/` and `:`\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A set of tools to help simplify your Django templates.",
    "version": "1.0.2",
    "project_urls": {
        "Changelog": "https://github.com/rails-inspire-django/django-template-simplify/releases",
        "Homepage": "https://github.com/rails-inspire-django/django-template-simplify"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a959f1db3a79b86fae4d6c0c83c3ca6b650c0d6d6fe1e662613966cf30e612cc",
                "md5": "33c9288fbcf70463e2e98843c3dbb89f",
                "sha256": "aad1cac2e1c1fdf3aac0689ee1195d12ddbe446c85066b025c1feb43f3888526"
            },
            "downloads": -1,
            "filename": "django_template_simplify-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "33c9288fbcf70463e2e98843c3dbb89f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 4016,
            "upload_time": "2024-08-26T14:33:36",
            "upload_time_iso_8601": "2024-08-26T14:33:36.353224Z",
            "url": "https://files.pythonhosted.org/packages/a9/59/f1db3a79b86fae4d6c0c83c3ca6b650c0d6d6fe1e662613966cf30e612cc/django_template_simplify-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a372fc02d8c1bf3bcb3ee31a9ed4effc44d027203efe612c1916f4753135feef",
                "md5": "122639ac6caa110f5913215c8ec11160",
                "sha256": "116df19d3170ea32ccd1803850804c405f21efa60accb5538ebd535ca0deb5d5"
            },
            "downloads": -1,
            "filename": "django_template_simplify-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "122639ac6caa110f5913215c8ec11160",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 3149,
            "upload_time": "2024-08-26T14:33:37",
            "upload_time_iso_8601": "2024-08-26T14:33:37.805644Z",
            "url": "https://files.pythonhosted.org/packages/a3/72/fc02d8c1bf3bcb3ee31a9ed4effc44d027203efe612c1916f4753135feef/django_template_simplify-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-26 14:33:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rails-inspire-django",
    "github_project": "django-template-simplify",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "django-template-simplify"
}
        
Elapsed time: 0.30515s