Metadata-Version: 2.4
Name: django-hilo
Version: 0.1.0
Summary: SPA framework for Django — one script tag turns Django templates into a full SPA
Project-URL: Homepage, https://github.com/ERPlora/django-hilo
Project-URL: Repository, https://github.com/ERPlora/django-hilo
Project-URL: Issues, https://github.com/ERPlora/django-hilo/issues
Project-URL: Changelog, https://github.com/ERPlora/django-hilo/blob/main/CHANGELOG.md
Author-email: Ioan Beilic <ioanbeilic@gmail.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.0
Classifier: Framework :: Django :: 5.1
Classifier: Framework :: Django :: 6.0
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: django>=4.2
Description-Content-Type: text/markdown

# django-hilo

SPA framework for Django. One `<script>` tag turns Django templates into a full SPA.

Works with [Hilo.js](https://github.com/ERPlora/hilo) — the client-side library that handles navigation, DOM morphing, signals, and real-time communication.

## Installation

```bash
pip install django-hilo
```

```python
# settings.py
INSTALLED_APPS = [
    ...
    'hilo',
]

MIDDLEWARE = [
    ...
    'hilo.middleware.HiloMiddleware',
]
```

## Quick Start

### 1. Base template

```html
{% load hilo %}
<!DOCTYPE html>
<html>
<head>
    <title>{% block title %}My App{% endblock %}</title>
</head>
<body>
    <nav data-permanent>
        <a href="/">Home</a>
        <a href="/products/">Products</a>
    </nav>

    {% hilo_content %}
        {% block content %}{% endblock %}
    {% endhilo_content %}

    {% hilo_scripts %}
</body>
</html>
```

### 2. Views with `@fragment`

```python
from hilo.decorators import fragment

@fragment('products/list.html')
def product_list(request):
    return {'products': Product.objects.all()}
```

That's it. Links are intercepted automatically. No `hx-get`, no `hx-target`, no attributes needed.

## Features

### Middleware

`HiloMiddleware` handles:
- **Redirect conversion** — Django redirects become `X-Hilo-Redirect` headers (no full page reload)
- **Asset versioning** — `X-Hilo-Version` header for cache busting
- **Request detection** — `request.is_hilo` boolean available in views

### `@fragment` decorator

Renders the appropriate template based on request type:
- **Hilo request** → renders only the partial template (fragment)
- **Normal request** → renders the full page (with base layout)

```python
@fragment('products/list.html', 'products/page.html')
def product_list(request):
    return {'products': Product.objects.all()}
```

### Response helpers

```python
from hilo.response import hilo_redirect, hilo_trigger, hilo_title, hilo_url

# Redirect via Hilo (no full reload)
return hilo_redirect('/products/')

# Trigger client-side events
response = render(request, 'template.html', context)
return hilo_trigger(response, {'showMessage': {'message': 'Saved!', 'type': 'success'}})

# Set page title
return hilo_title(response, 'Products')
```

### Streaming actions (like Turbo Streams)

```python
from hilo.response import HiloStreamResponse

def add_message(request):
    response = HiloStreamResponse()
    response.append('#messages', '<div class="message">New message!</div>')
    response.update('#counter', '<span>42</span>')
    response.remove('#typing-indicator')
    return response
```

### Template tags

```html
{% load hilo %}

{% hilo_scripts %}                              {# Inject hilo.min.js + config #}
{% hilo_content %}...{% endhilo_content %}       {# Main content area #}
{% hilo_permanent %}...{% endhilo_permanent %}   {# Never morphed #}

{# Streaming actions in templates #}
{% hilo_stream "append" "#messages" %}
  <div class="message">{{ message.text }}</div>
{% endhilo_stream %}
```

## Configuration

```python
# settings.py
HILO = {
    'VERSION': 'auto',           # Asset version ('auto', fixed string, or '')
    'JS_PATH': 'js/hilo.min.js', # Path to hilo.min.js in STATIC_URL
    'PREFIX': 'h',               # Behavior prefix (data-h="toggle")
    'DEBUG': False,               # Enable debug logging
    'NAV': True,                  # Enable SPA navigation (True, False, or dict)
}
```

## License

MIT
