-
- Notifications
You must be signed in to change notification settings - Fork 23
Make django_idom an installable app #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
36 commits Select commit Hold shift + click to select a range
30a481f
create barebones templatetags
Archmonger 8b0b363
styling fix
Archmonger 4bcd9bf
idom_view
Archmonger f8f094e
skeleton of django installable app
rmorshea 937da20
get test_app runserver to work
rmorshea e76408b
fix MANIFEST.in to include static/templates
rmorshea f008f6b
fix style
rmorshea b4f256b
require a my_app.idom.components attribute
rmorshea a0b75e0
parametrized components + serve web modules
rmorshea cd12a7c
add IDOM_IGNORED_DJANGO_APPS option
rmorshea 9f4412d
add basic docs to README
rmorshea 34452e4
minor doc improvements
rmorshea 3e07d5a
more doc updates
rmorshea 0ff84ec
make logger private
rmorshea fbb0037
use string path to template
rmorshea 407b506
rename URL resolver functions
rmorshea fa95bb1
fix flake8
rmorshea 9da3de8
correct template tag description
rmorshea a05d0ef
update app organization in README
rmorshea 937244c
switch to decorator collection method
rmorshea af6601d
load components using template names
rmorshea 60384af
minor README tweaks
rmorshea f72b2d6
remove unused config option
rmorshea 4bcdeb5
use different param name in README ex
rmorshea 536968a
cache and asyncify web module loading
rmorshea aee70a7
rename idom_view to idom_component
rmorshea 7093252
README rename your_template to your_view
rmorshea 66b7cb3
fix README typo
rmorshea 4a4fa74
make websocket and web module paths consts
rmorshea b209995
correct terminology
rmorshea b9934de
slim down README asgi.py description
rmorshea fa70766
better summarize what IDOM is
rmorshea a15c334
bump copyright year
rmorshea aed7fc7
fix template formatting
rmorshea 68aa643
rename your_app to your_project
rmorshea 83e3f7c
add CODEOWNERS
rmorshea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
get test_app runserver to work
- Loading branch information
commit 937da205da8f8555a232fd5a4b486dbdfc40d15e
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include src/django_idom/static/js/idom.js | ||
include src/django_idom/templates/head_content.html | ||
include src/django_idom/templates/view.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
from .websocket_consumer import IdomAsyncWebSocketConsumer | ||
from .websocket_consumer import ( | ||
IdomAsyncWebSocketConsumer, | ||
django_idom_websocket_consumer_url, | ||
) | ||
| ||
| ||
__version__ = "0.0.1" | ||
__all__ = ["IdomAsyncWebSocketConsumer"] | ||
__all__ = ["IdomAsyncWebSocketConsumer", "django_idom_websocket_consumer_url"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import logging | ||
rmorshea marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
from importlib import import_module | ||
from typing import Dict | ||
| ||
from django.conf import settings | ||
from idom.core.proto import ComponentConstructor | ||
| ||
| ||
logger = logging.getLogger(__name__) | ||
_LOADED_COMPONENTS: Dict[str, ComponentConstructor] = {} | ||
| ||
| ||
def get_component(name: str) -> ComponentConstructor: | ||
return _LOADED_COMPONENTS[name] | ||
| ||
| ||
def has_component(name: str) -> bool: | ||
return name in _LOADED_COMPONENTS | ||
| ||
| ||
for app_mod_name in settings.INSTALLED_APPS: | ||
idom_mod_name = f"{app_mod_name}.idom" | ||
| ||
try: | ||
idom_mod = import_module(idom_mod_name) | ||
except ImportError: | ||
logger.debug(f"Skipping {idom_mod_name!r} - does not exist") | ||
continue | ||
| ||
if not hasattr(idom_mod, "__all__"): | ||
logger.warning( | ||
f"'django_idom' expected module {idom_mod_name!r} to have an " | ||
"'__all__' attribute that lists its publically available components." | ||
) | ||
continue | ||
| ||
for component_name in idom_mod.__all__: | ||
try: | ||
component_constructor = getattr(idom_mod, component_name) | ||
except AttributeError: | ||
logger.warning( | ||
f"Module {idom_mod_name!r} has no attribute {component_name!r}" | ||
) | ||
continue | ||
| ||
if not callable(component_constructor): | ||
logger.warning(f"'{idom_mod_name}.{component_name}' is not a component") | ||
continue | ||
| ||
_LOADED_COMPONENTS[f"{app_mod_name}.{component_name}"] = component_constructor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
from django.conf import settings | ||
| ||
| ||
IDOM_WEBSOCKET_URL = getattr(settings, "IDOM_WEBSOCKET_URL", "_idom/") | ||
if not IDOM_WEBSOCKET_URL.endswith("/"): | ||
IDOM_WEBSOCKET_URL += "/" |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
<div id="{{ idom_view_id }}"></div> | ||
{% load static %} | ||
<div id="{{ idom_mount_uuid }}"></div> | ||
<script type="module" crossorigin="anonymous"> | ||
import { mountToElement } from "{% static 'js/idom.js' %}"; | ||
mountViewToElement("{{ idom_websocket_url }}", "{{ idom_view_id }}"); | ||
import { mountViewToElement } from "{% static 'js/idom.js' %}"; | ||
const mountPoint = document.getElementById("{{ idom_mount_uuid }}"); | ||
mountViewToElement( | ||
mountPoint, | ||
"{{ idom_websocket_url }}", | ||
"{{ idom_view_id }}", | ||
"{{ idom_view_params }}" | ||
); | ||
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
test_app/static/build.js | ||
*.sqlite3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import idom | ||
| ||
| ||
__all__ = "HelloWorld", "Button" | ||
| ||
| ||
@idom.component | ||
def HelloWorld(): | ||
return idom.html.h1({"id": "hello-world"}, "Hello World!") | ||
| ||
| ||
@idom.component | ||
def Button(): | ||
count, set_count = idom.hooks.use_state(0) | ||
return idom.html.div( | ||
idom.html.button( | ||
{"id": "counter-inc", "onClick": lambda event: set_count(count + 1)}, | ||
"Click me!", | ||
), | ||
idom.html.p( | ||
{"id": "counter-num", "data-count": count}, | ||
f"Current count is: {count}", | ||
), | ||
) |
Empty file.
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.