csstweaks-client 0.1.0__py3-none-any.whl

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.
File without changes
@@ -0,0 +1,11 @@
1
+ from django.urls import path
2
+
3
+ from . import views
4
+
5
+ app_name = 'csstweaks_client'
6
+
7
+ urlpatterns = [
8
+ path('ping', views.ping, name='ping'),
9
+ path('read', views.read_file, name='read'),
10
+ path('write', views.write_file, name='write'),
11
+ ]
@@ -0,0 +1,85 @@
1
+ """Local-dev helper for the csstweaks browser extension.
2
+
3
+ The extension reads and writes the CSS files Django's static finders resolve.
4
+ Mount this only while debugging:
5
+
6
+ if settings.DEBUG:
7
+ urlpatterns += [path('__csstweaks__/', include('csstweaks_client.urls'))]
8
+
9
+ Each view also refuses to run unless DEBUG is on.
10
+ """
11
+ import json
12
+
13
+ from django.conf import settings
14
+ from django.contrib.staticfiles import finders
15
+ from django.http import (
16
+ Http404,
17
+ HttpResponse,
18
+ HttpResponseBadRequest,
19
+ HttpResponseNotFound,
20
+ JsonResponse,
21
+ )
22
+ from django.views.decorators.csrf import csrf_exempt
23
+ from django.views.decorators.http import require_GET, require_POST
24
+
25
+
26
+ def _debug_only(view):
27
+ def wrapper(request, *args, **kwargs):
28
+ if not settings.DEBUG:
29
+ raise Http404()
30
+ return view(request, *args, **kwargs)
31
+ wrapper.__wrapped__ = view
32
+ return wrapper
33
+
34
+
35
+ def _resolve(path):
36
+ """Map a STATIC_URL-relative path to a file via Django's static finders."""
37
+ if not path.lower().endswith('.css'):
38
+ return None
39
+
40
+ relative = path.lstrip('/')
41
+ static_url = settings.STATIC_URL.strip('/')
42
+ if static_url and relative.startswith(static_url + '/'):
43
+ relative = relative[len(static_url) + 1:]
44
+
45
+ return finders.find(relative)
46
+
47
+
48
+ @_debug_only
49
+ @require_GET
50
+ def ping(request):
51
+ return JsonResponse({'ok': True, 'name': 'csstweaks-client'})
52
+
53
+
54
+ @_debug_only
55
+ @require_GET
56
+ def read_file(request):
57
+ path = request.GET.get('path', '')
58
+ real_path = _resolve(path)
59
+ if not real_path:
60
+ return HttpResponseNotFound(f'no static CSS file resolves to {path!r}')
61
+ with open(real_path, 'r', encoding='utf-8') as handle:
62
+ return HttpResponse(handle.read(), content_type='text/css; charset=utf-8')
63
+
64
+
65
+ @csrf_exempt
66
+ @_debug_only
67
+ @require_POST
68
+ def write_file(request):
69
+ try:
70
+ body = json.loads(request.body)
71
+ except (ValueError, TypeError):
72
+ return HttpResponseBadRequest('invalid JSON body')
73
+
74
+ path = body.get('path', '')
75
+ content = body.get('content')
76
+ if not isinstance(content, str):
77
+ return HttpResponseBadRequest('missing content')
78
+
79
+ real_path = _resolve(path)
80
+ if not real_path:
81
+ return HttpResponseNotFound(f'no static CSS file resolves to {path!r}')
82
+
83
+ with open(real_path, 'w', encoding='utf-8') as handle:
84
+ handle.write(content)
85
+ return JsonResponse({'ok': True})
@@ -0,0 +1,60 @@
1
+ Metadata-Version: 2.4
2
+ Name: csstweaks-client
3
+ Version: 0.1.0
4
+ Summary: Django debug helper for the csstweaks browser extension
5
+ Author: Vasudeva Server
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://vasudevaserver.org
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Framework :: Django
10
+ Classifier: Framework :: Django :: 5.2
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: Django<6.0,>=5.2
16
+ Dynamic: license-file
17
+
18
+ # csstweaks-client
19
+
20
+ `csstweaks-client` is the Django companion to the csstweaks browser extension.
21
+ It shortens the feedback loop for local CSS work: the extension reads the
22
+ stylesheet currently served by Django, lets you adjust it in the browser, and
23
+ writes the result back to the source file that Django's static-file finders
24
+ resolve.
25
+
26
+ This is a development helper, not a production editing API. Every view returns
27
+ 404 unless Django's `DEBUG` setting is enabled, and projects should mount its
28
+ URLs only inside the same `DEBUG` check.
29
+
30
+ ## Install
31
+
32
+ ```sh
33
+ pip install csstweaks-client
34
+ ```
35
+
36
+ Add `csstweaks_client` to `INSTALLED_APPS`, then mount it in the project's root
37
+ URL configuration:
38
+
39
+ ```python
40
+ if settings.DEBUG:
41
+ urlpatterns += [path("__csstweaks__/", include("csstweaks_client.urls"))]
42
+ ```
43
+
44
+ Start Django normally and connect the csstweaks extension to the development
45
+ site. The client works with stylesheets found in a `STATICFILES_DIRS` directory
46
+ or an installed app's `static/` directory.
47
+
48
+ ## Endpoints
49
+
50
+ - `GET /__csstweaks__/ping` — the extension uses this to find the helper.
51
+ - `GET /__csstweaks__/read?path=<STATIC_URL-relative path>` — returns raw CSS.
52
+ - `POST /__csstweaks__/write` — `{"path": "...", "content": "..."}` overwrites the source file.
53
+
54
+ For development of the client itself, install this checkout in editable mode:
55
+
56
+ ```sh
57
+ pip install -e .
58
+ ```
59
+
60
+ [Vasudeva Server](https://vasudevaserver.org)
@@ -0,0 +1,8 @@
1
+ csstweaks_client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ csstweaks_client/urls.py,sha256=BMzxteZK60KeeyCpgFhC36d-ySOngA1Njo1N2w6vZCM,242
3
+ csstweaks_client/views.py,sha256=9qpSaXOsi4Tf9UjATjx3b0olmmRSDLXr8Qy5tn8I4VM,2401
4
+ csstweaks_client-0.1.0.dist-info/licenses/LICENSE,sha256=cjw5dL5wDMy6mDzC1e2pA6_73FVPaDJnoO1Nxmr582Q,1072
5
+ csstweaks_client-0.1.0.dist-info/METADATA,sha256=AkKAEuFXyhWV5iJ-3-uPqqOZHCpvjyBLcKldAVZl9S8,1951
6
+ csstweaks_client-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
7
+ csstweaks_client-0.1.0.dist-info/top_level.txt,sha256=BWBzUkep7UJcRVvU7da7WLcQoiyEp-QUfLXu94QkO6Y,17
8
+ csstweaks_client-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vasudeva Server
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.
@@ -0,0 +1 @@
1
+ csstweaks_client