shrd 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. shrd-0.3.0/LICENSE +21 -0
  2. shrd-0.3.0/PKG-INFO +129 -0
  3. shrd-0.3.0/README.md +96 -0
  4. shrd-0.3.0/pyproject.toml +82 -0
  5. shrd-0.3.0/setup.cfg +4 -0
  6. shrd-0.3.0/shard/__init__.py +35 -0
  7. shrd-0.3.0/shard/actions.py +21 -0
  8. shrd-0.3.0/shard/apps.py +12 -0
  9. shrd-0.3.0/shard/component.py +342 -0
  10. shrd-0.3.0/shard/conf.py +16 -0
  11. shrd-0.3.0/shard/context_processors.py +28 -0
  12. shrd-0.3.0/shard/css_minify.py +53 -0
  13. shrd-0.3.0/shard/exceptions.py +22 -0
  14. shrd-0.3.0/shard/htmx.py +53 -0
  15. shrd-0.3.0/shard/management/commands/shard_list.py +26 -0
  16. shrd-0.3.0/shard/management/commands/shard_report.py +43 -0
  17. shrd-0.3.0/shard/props.py +81 -0
  18. shrd-0.3.0/shard/py.typed +0 -0
  19. shrd-0.3.0/shard/registry.py +60 -0
  20. shrd-0.3.0/shard/render.py +60 -0
  21. shrd-0.3.0/shard/scoping.py +87 -0
  22. shrd-0.3.0/shard/slots.py +25 -0
  23. shrd-0.3.0/shard/state.py +69 -0
  24. shrd-0.3.0/shard/static/shard/js/alpine.min.js +5 -0
  25. shrd-0.3.0/shard/static/shard/js/htmx.min.js +1 -0
  26. shrd-0.3.0/shard/static/shard/js/shard.js +13 -0
  27. shrd-0.3.0/shard/styles.py +79 -0
  28. shrd-0.3.0/shard/templates/shard/component_shell.html +1 -0
  29. shrd-0.3.0/shard/templates/shard/scripts.html +13 -0
  30. shrd-0.3.0/shard/templatetags/shard.py +180 -0
  31. shrd-0.3.0/shard/urls.py +14 -0
  32. shrd-0.3.0/shard/view_data.py +233 -0
  33. shrd-0.3.0/shard/view_tree.py +89 -0
  34. shrd-0.3.0/shard/views.py +68 -0
  35. shrd-0.3.0/shard/weight.py +218 -0
  36. shrd-0.3.0/shrd.egg-info/PKG-INFO +129 -0
  37. shrd-0.3.0/shrd.egg-info/SOURCES.txt +53 -0
  38. shrd-0.3.0/shrd.egg-info/dependency_links.txt +1 -0
  39. shrd-0.3.0/shrd.egg-info/requires.txt +11 -0
  40. shrd-0.3.0/shrd.egg-info/top_level.txt +1 -0
  41. shrd-0.3.0/tests/test_component.py +64 -0
  42. shrd-0.3.0/tests/test_css_minify.py +26 -0
  43. shrd-0.3.0/tests/test_htmx.py +47 -0
  44. shrd-0.3.0/tests/test_integration.py +81 -0
  45. shrd-0.3.0/tests/test_props.py +76 -0
  46. shrd-0.3.0/tests/test_registry.py +21 -0
  47. shrd-0.3.0/tests/test_scoping.py +37 -0
  48. shrd-0.3.0/tests/test_state.py +49 -0
  49. shrd-0.3.0/tests/test_styles.py +9 -0
  50. shrd-0.3.0/tests/test_styles_minify.py +18 -0
  51. shrd-0.3.0/tests/test_templatetags.py +69 -0
  52. shrd-0.3.0/tests/test_view_data.py +148 -0
  53. shrd-0.3.0/tests/test_view_data_integration.py +146 -0
  54. shrd-0.3.0/tests/test_views.py +85 -0
  55. shrd-0.3.0/tests/test_weight.py +133 -0
shrd-0.3.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shard Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
shrd-0.3.0/PKG-INFO ADDED
@@ -0,0 +1,129 @@
1
+ Metadata-Version: 2.4
2
+ Name: shrd
3
+ Version: 0.3.0
4
+ Summary: A Django-native component framework with props, state, HTMX, and Alpine.js
5
+ Author: Shard Contributors
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/kurtisrogers/Shard
8
+ Project-URL: Documentation, https://kurtisrogers.github.io/Shard/
9
+ Keywords: django,components,htmx,alpine,shard
10
+ Classifier: Framework :: Django
11
+ Classifier: Framework :: Django :: 4.2
12
+ Classifier: Framework :: Django :: 5.0
13
+ Classifier: Framework :: Django :: 5.1
14
+ Classifier: Framework :: Django :: 6.0
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: Django>=4.2
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=8.0; extra == "dev"
26
+ Requires-Dist: pytest-django>=4.8; extra == "dev"
27
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
28
+ Requires-Dist: ruff>=0.9.0; extra == "dev"
29
+ Requires-Dist: pre-commit>=4.0; extra == "dev"
30
+ Provides-Extra: docs
31
+ Requires-Dist: mkdocs-material>=9.5; extra == "docs"
32
+ Dynamic: license-file
33
+
34
+ # Shard
35
+
36
+ A Django-native component framework for building UI with **props**, **server state**, **slots**, and **scoped styles** — using only the Django ecosystem plus bundled HTMX and Alpine.js.
37
+
38
+ 📖 **[Full documentation](https://kurtisrogers.github.io/Shard/)**
39
+
40
+ Shard is a framework, not a drop-in library. Your Django project adopts its conventions: components live in your apps, templates sit beside scoped CSS, and HTMX carries server actions.
41
+
42
+ ## Philosophy
43
+
44
+ Shard does not ship a widget catalog. It gives you a small, familiar model — closer to React/Vue than to Django templates alone — without a build step or SPA complexity:
45
+
46
+ - **Props** — typed inputs declared on a Python class
47
+ - **State** — server-owned data updated via `@action` methods
48
+ - **Slots** — wrap and compose markup like `children` / default slots
49
+ - **Scoped styles** — co-located `.css` files, automatically prefixed to the component
50
+ - **Computed** — derived values via `@computed` methods
51
+ - **Events** — HTMX custom events via `@emits` and `ActionResult`
52
+ - **HTMX** — partial re-renders after actions
53
+ - **Alpine.js** — optional client-side behavior inside templates
54
+ - **View data** — optional structured layouts, mutable via `ViewTreeComponent`
55
+
56
+ ## Quick start
57
+
58
+ ```python
59
+ # myapp/components.py
60
+ from shard import Component, Prop, action
61
+
62
+ class Card(Component):
63
+ title = Prop(str, default="")
64
+ template_name = "components/card.html"
65
+ ```
66
+
67
+ ```django
68
+ {% load shard %}
69
+ {% shard_scripts %}
70
+
71
+ {% component Card title="Profile" %}
72
+ <p>Anything here is passed through the default slot.</p>
73
+ {% endcomponent %}
74
+ ```
75
+
76
+ See the [quickstart guide](https://kurtisrogers.github.io/Shard/getting-started/quickstart/) for a full walkthrough.
77
+
78
+ ## Documentation
79
+
80
+ | Topic | Link |
81
+ | -------------- | -------------------------------------------------------------------------------------------------- |
82
+ | Installation | [getting-started/installation](https://kurtisrogers.github.io/Shard/getting-started/installation/) |
83
+ | Components | [concepts/components](https://kurtisrogers.github.io/Shard/concepts/components/) |
84
+ | Slots | [concepts/slots](https://kurtisrogers.github.io/Shard/concepts/slots/) |
85
+ | Scoped styles | [concepts/styles](https://kurtisrogers.github.io/Shard/concepts/styles/) |
86
+ | Actions & HTMX | [interactivity/actions](https://kurtisrogers.github.io/Shard/interactivity/actions/) |
87
+ | HTMX & Alpine | [guides/htmx-and-alpine](https://kurtisrogers.github.io/Shard/guides/htmx-and-alpine/) |
88
+ | View data | [guides/view-data](https://kurtisrogers.github.io/Shard/guides/view-data/) |
89
+ | API reference | [reference/api](https://kurtisrogers.github.io/Shard/reference/api/) |
90
+ | Examples | [examples](https://kurtisrogers.github.io/Shard/examples/) |
91
+
92
+ ## Example app
93
+
94
+ ```bash
95
+ pip install shrd[dev]
96
+ cd example
97
+ python manage.py migrate
98
+ python manage.py runserver
99
+ ```
100
+
101
+ Or install from source:
102
+
103
+ ```bash
104
+ pip install -e ".[dev]"
105
+ cd example
106
+ python manage.py migrate
107
+ python manage.py runserver
108
+ ```
109
+
110
+ ## Development
111
+
112
+ ```bash
113
+ pip install -e ".[dev]"
114
+ pre-commit install
115
+ python -m pytest tests/ -q
116
+ python manage.py shard_report # framework size / page-load weight
117
+ ```
118
+
119
+ **96 tests** with **≥90% coverage**. CI runs pre-commit, Ruff, tests (Python 3.10–3.12), and docs build on every PR.
120
+
121
+ ```bash
122
+ pre-commit run --all-files # lint + format locally
123
+ pip install -e ".[docs]"
124
+ python -m mkdocs serve
125
+ ```
126
+
127
+ ## License
128
+
129
+ MIT
shrd-0.3.0/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # Shard
2
+
3
+ A Django-native component framework for building UI with **props**, **server state**, **slots**, and **scoped styles** — using only the Django ecosystem plus bundled HTMX and Alpine.js.
4
+
5
+ 📖 **[Full documentation](https://kurtisrogers.github.io/Shard/)**
6
+
7
+ Shard is a framework, not a drop-in library. Your Django project adopts its conventions: components live in your apps, templates sit beside scoped CSS, and HTMX carries server actions.
8
+
9
+ ## Philosophy
10
+
11
+ Shard does not ship a widget catalog. It gives you a small, familiar model — closer to React/Vue than to Django templates alone — without a build step or SPA complexity:
12
+
13
+ - **Props** — typed inputs declared on a Python class
14
+ - **State** — server-owned data updated via `@action` methods
15
+ - **Slots** — wrap and compose markup like `children` / default slots
16
+ - **Scoped styles** — co-located `.css` files, automatically prefixed to the component
17
+ - **Computed** — derived values via `@computed` methods
18
+ - **Events** — HTMX custom events via `@emits` and `ActionResult`
19
+ - **HTMX** — partial re-renders after actions
20
+ - **Alpine.js** — optional client-side behavior inside templates
21
+ - **View data** — optional structured layouts, mutable via `ViewTreeComponent`
22
+
23
+ ## Quick start
24
+
25
+ ```python
26
+ # myapp/components.py
27
+ from shard import Component, Prop, action
28
+
29
+ class Card(Component):
30
+ title = Prop(str, default="")
31
+ template_name = "components/card.html"
32
+ ```
33
+
34
+ ```django
35
+ {% load shard %}
36
+ {% shard_scripts %}
37
+
38
+ {% component Card title="Profile" %}
39
+ <p>Anything here is passed through the default slot.</p>
40
+ {% endcomponent %}
41
+ ```
42
+
43
+ See the [quickstart guide](https://kurtisrogers.github.io/Shard/getting-started/quickstart/) for a full walkthrough.
44
+
45
+ ## Documentation
46
+
47
+ | Topic | Link |
48
+ | -------------- | -------------------------------------------------------------------------------------------------- |
49
+ | Installation | [getting-started/installation](https://kurtisrogers.github.io/Shard/getting-started/installation/) |
50
+ | Components | [concepts/components](https://kurtisrogers.github.io/Shard/concepts/components/) |
51
+ | Slots | [concepts/slots](https://kurtisrogers.github.io/Shard/concepts/slots/) |
52
+ | Scoped styles | [concepts/styles](https://kurtisrogers.github.io/Shard/concepts/styles/) |
53
+ | Actions & HTMX | [interactivity/actions](https://kurtisrogers.github.io/Shard/interactivity/actions/) |
54
+ | HTMX & Alpine | [guides/htmx-and-alpine](https://kurtisrogers.github.io/Shard/guides/htmx-and-alpine/) |
55
+ | View data | [guides/view-data](https://kurtisrogers.github.io/Shard/guides/view-data/) |
56
+ | API reference | [reference/api](https://kurtisrogers.github.io/Shard/reference/api/) |
57
+ | Examples | [examples](https://kurtisrogers.github.io/Shard/examples/) |
58
+
59
+ ## Example app
60
+
61
+ ```bash
62
+ pip install shrd[dev]
63
+ cd example
64
+ python manage.py migrate
65
+ python manage.py runserver
66
+ ```
67
+
68
+ Or install from source:
69
+
70
+ ```bash
71
+ pip install -e ".[dev]"
72
+ cd example
73
+ python manage.py migrate
74
+ python manage.py runserver
75
+ ```
76
+
77
+ ## Development
78
+
79
+ ```bash
80
+ pip install -e ".[dev]"
81
+ pre-commit install
82
+ python -m pytest tests/ -q
83
+ python manage.py shard_report # framework size / page-load weight
84
+ ```
85
+
86
+ **96 tests** with **≥90% coverage**. CI runs pre-commit, Ruff, tests (Python 3.10–3.12), and docs build on every PR.
87
+
88
+ ```bash
89
+ pre-commit run --all-files # lint + format locally
90
+ pip install -e ".[docs]"
91
+ python -m mkdocs serve
92
+ ```
93
+
94
+ ## License
95
+
96
+ MIT
@@ -0,0 +1,82 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "shrd"
7
+ version = "0.3.0"
8
+ description = "A Django-native component framework with props, state, HTMX, and Alpine.js"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Shard Contributors" }]
14
+ keywords = ["django", "components", "htmx", "alpine", "shard"]
15
+ classifiers = [
16
+ "Framework :: Django",
17
+ "Framework :: Django :: 4.2",
18
+ "Framework :: Django :: 5.0",
19
+ "Framework :: Django :: 5.1",
20
+ "Framework :: Django :: 6.0",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Topic :: Internet :: WWW/HTTP :: Dynamic Content",
26
+ ]
27
+ dependencies = [
28
+ "Django>=4.2",
29
+ ]
30
+
31
+ [project.urls]
32
+ Homepage = "https://github.com/kurtisrogers/Shard"
33
+ Documentation = "https://kurtisrogers.github.io/Shard/"
34
+
35
+ [project.optional-dependencies]
36
+ dev = [
37
+ "pytest>=8.0",
38
+ "pytest-django>=4.8",
39
+ "pytest-cov>=5.0",
40
+ "ruff>=0.9.0",
41
+ "pre-commit>=4.0",
42
+ ]
43
+ docs = [
44
+ "mkdocs-material>=9.5",
45
+ ]
46
+
47
+ [tool.setuptools.packages.find]
48
+ where = ["."]
49
+ include = ["shard*"]
50
+
51
+ [tool.setuptools.package-data]
52
+ shard = [
53
+ "static/**/*",
54
+ "templates/**/*",
55
+ ]
56
+
57
+ [tool.pytest.ini_options]
58
+ DJANGO_SETTINGS_MODULE = "tests.settings"
59
+ pythonpath = ["."]
60
+ testpaths = ["tests"]
61
+ addopts = "--cov=shard --cov-report=term-missing"
62
+
63
+ [tool.ruff]
64
+ target-version = "py310"
65
+ line-length = 100
66
+ src = ["shard", "tests", "example"]
67
+
68
+ [tool.ruff.lint]
69
+ select = [
70
+ "E", # pycodestyle errors
71
+ "W", # pycodestyle warnings
72
+ "F", # pyflakes
73
+ "I", # isort
74
+ "UP", # pyupgrade
75
+ "B", # flake8-bugbear
76
+ ]
77
+ ignore = [
78
+ "E501", # line length handled by formatter
79
+ ]
80
+
81
+ [tool.ruff.lint.isort]
82
+ known-first-party = ["shard", "example", "tests"]
shrd-0.3.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,35 @@
1
+ """Shard — a Django-native component framework."""
2
+
3
+ from shard.actions import ActionResult
4
+ from shard.component import Component, action, computed, emits
5
+ from shard.props import Prop
6
+ from shard.render import mount, render_component
7
+ from shard.view_data import (
8
+ ViewNode,
9
+ commit_view_tree,
10
+ ensure_node_ids,
11
+ get_slot_nodes,
12
+ render_view_data,
13
+ set_slot_nodes,
14
+ )
15
+ from shard.view_tree import ViewTreeComponent
16
+
17
+ __all__ = [
18
+ "ActionResult",
19
+ "Component",
20
+ "Prop",
21
+ "ViewNode",
22
+ "ViewTreeComponent",
23
+ "action",
24
+ "commit_view_tree",
25
+ "computed",
26
+ "emits",
27
+ "ensure_node_ids",
28
+ "get_slot_nodes",
29
+ "mount",
30
+ "render_component",
31
+ "render_view_data",
32
+ "set_slot_nodes",
33
+ ]
34
+
35
+ __version__ = "0.3.0"
@@ -0,0 +1,21 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass, field
4
+ from typing import Any
5
+
6
+
7
+ @dataclass
8
+ class ActionResult:
9
+ """Optional return value from an ``@action`` method.
10
+
11
+ Use when an action needs to emit HTMX events or trigger a redirect in
12
+ addition to updating server state.
13
+ """
14
+
15
+ state: dict[str, Any] | None = None
16
+ events: dict[str, Any] = field(default_factory=dict)
17
+ redirect: str | None = None
18
+
19
+ @classmethod
20
+ def with_events(cls, state: dict[str, Any], **events: Any) -> ActionResult:
21
+ return cls(state=state, events=events)
@@ -0,0 +1,12 @@
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class ShardConfig(AppConfig):
5
+ default_auto_field = "django.db.models.BigAutoField"
6
+ name = "shard"
7
+ verbose_name = "Shard Component Framework"
8
+
9
+ def ready(self) -> None:
10
+ from shard.registry import autodiscover_components
11
+
12
+ autodiscover_components()