Skip to content

Commit 7799ad7

Browse files
authored
Merge pull request #4 from fsecada01/fix/cotton-dir-consumer-conflict
fix: stop hijacking COTTON_DIR — cotton/cf/ template layout
2 parents 5814476 + 78ccd80 commit 7799ad7

24 files changed

Lines changed: 156 additions & 38 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ test-results/
2222
Thumbs.db
2323
.idea/
2424
.vscode/
25+
uv.lock

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
# Changelog
22

3+
## [0.1.1] — 2026-04-28
4+
5+
### Fixed
6+
- **Consumer compatibility regression**: `CfUiConfig.ready()` no longer
7+
overrides `settings.COTTON_DIR`. The previous fix in 0.1.0 set
8+
`COTTON_DIR="cotton/bulma"` globally, which broke any consumer project
9+
whose own cotton templates lived at `templates/cotton/<their-app>/...`
10+
(every `<c-foo.bar>` lookup got rewritten to
11+
`cotton/bulma/foo/bar/index.html` and raised `TemplateDoesNotExist`).
12+
13+
### Changed
14+
- cf-ui's cotton templates moved from `cotton/<theme>/cf/*.html` to
15+
`cotton/cf/*.html`. Theme variation will now happen inside the templates
16+
(or via `_themes/` partials) instead of at the directory level. With the
17+
default `COTTON_DIR="cotton"`, `<c-cf.foo>` continues to resolve and
18+
consumer cotton trees are no longer affected.
19+
20+
### Migration
21+
- Most consumers: no change required. Removing any explicit
22+
`COTTON_DIR="cotton/bulma"` from `settings.py` (added as a workaround
23+
while 0.1.0 was broken) is recommended.
24+
- If you imported `COTTON_TEMPLATES_DIR / "bulma"` directly via the escape
25+
hatch, switch to `COTTON_TEMPLATES_DIR / "cf"`.
26+
327
## [0.1.0] — 2026-04-25
428

529
### Added

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,18 @@ If you need direct access to template directories for custom configuration:
201201
```python
202202
from cf_ui import JINJA_TEMPLATES_DIR, COTTON_TEMPLATES_DIR
203203

204-
# JINJA_TEMPLATES_DIR / "bulma" → Path to Jinja2 templates
205-
# COTTON_TEMPLATES_DIR / "bulma" → Path to Cotton templates
204+
# JINJA_TEMPLATES_DIR / "bulma" → Path to Jinja2 templates (theme-prefixed)
205+
# COTTON_TEMPLATES_DIR / "cf" → Path to Cotton component templates
206206
```
207207

208+
> **Cotton templates are theme-agnostic on disk.** They live at
209+
> `cotton/cf/*.html` (not `cotton/<theme>/cf/*.html`) so cf-ui can sit
210+
> alongside any consumer project's own `templates/cotton/<app>/...` tree
211+
> without colliding on `COTTON_DIR`. The active CSS framework is selected
212+
> via `CF_UI_THEME` (used by the asset tags) — switching themes in a
213+
> future release will happen inside the templates, not via the directory
214+
> layout.
215+
208216
---
209217

210218
## Planned Themes

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "cf-ui"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
description = "CSS framework UI kit for component-framework — Bulma, Bootstrap, Foundation, Fomantic, DaisyUI"
55
readme = "README.md"
66
requires-python = ">=3.11"

src/cf_ui/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.0"
1+
__version__ = "0.1.1"

src/cf_ui/django.py

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,14 @@
1-
from pathlib import Path
2-
31
from django.apps import AppConfig
4-
from django.core.exceptions import ImproperlyConfigured
52

63

74
class CfUiConfig(AppConfig):
85
name = "cf_ui.django"
96
label = "cf_ui"
107
verbose_name = "Component Framework UI"
118

12-
def ready(self) -> None:
13-
from django.conf import settings
14-
15-
theme = getattr(settings, "CF_UI_THEME", "bulma")
16-
cotton_dir = Path(__file__).parent / "templates" / "cotton" / theme
17-
18-
if not cotton_dir.is_dir():
19-
raise ImproperlyConfigured(
20-
f"cf-ui: no templates found for theme {theme!r} at {cotton_dir}. "
21-
f"Check CF_UI_THEME in settings."
22-
)
23-
24-
# django-cotton reads COTTON_DIR (singular). Setting it to
25-
# "cotton/<theme>" makes <c-cf.foo> resolve to
26-
# cotton/<theme>/cf/foo.html, which the cotton loader finds via
27-
# the app-templates walk (cf_ui/templates/cotton/<theme>/cf/foo.html).
28-
# Don't overwrite a value the consumer has already set.
29-
if not getattr(settings, "COTTON_DIR", None):
30-
settings.COTTON_DIR = f"cotton/{theme}"
9+
# cf-ui Cotton templates live at src/cf_ui/templates/cotton/cf/*.html.
10+
# Django's app-templates loader (APP_DIRS=True) picks them up directly
11+
# and django-cotton's default COTTON_DIR ("cotton") resolves
12+
# <c-cf.foo> -> cotton/cf/foo.html. We deliberately do not touch
13+
# COTTON_DIR here: doing so would break consumer projects whose own
14+
# cotton templates live at cotton/<their-app>/*.html.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)