@@ -45,7 +45,6 @@ your_app/
45
45
├── urls.py
46
46
└── sub_app/
47
47
├── __init__.py
48
- ├── components.py
49
48
├── idom.py
50
49
├── templates/
51
50
│ └── your-template.html
@@ -58,7 +57,7 @@ To start, we'll need to use [`channels`](https://channels.readthedocs.io/en/stab
58
57
create a ` ProtocolTypeRouter ` that will become the top of our ASGI application stack.
59
58
Under the ` "websocket" ` protocol, we'll then add a path for IDOM's websocket consumer
60
59
using ` idom_websocket_path ` . If you wish to change the route where this
61
- websocket is served from see the available [ settings] ( #settings.py ) .
60
+ websocket is served from, see the available [ settings] ( #settings.py ) .
62
61
63
62
``` python
64
63
@@ -104,15 +103,13 @@ You may configure additional options as well:
104
103
``` python
105
104
# the base URL for all IDOM-releated resources
106
105
IDOM_BASE_URL : str = " _idom/"
107
-
108
- # ignore these INSTALLED_APPS during component collection
109
- IDOM_IGNORE_INSTALLED_APPS : list[str ] = [" some_app" , " some_other_app" ]
110
106
```
111
107
112
108
## ` urls.py `
113
109
114
110
You'll need to include IDOM's static web modules path using ` idom_web_modules_path ` .
115
- Similarly to the ` idom_websocket_path() ` , these resources will be used globally.
111
+ Similarly to the ` idom_websocket_path() ` . If you wish to change the route where this
112
+ websocket is served from, see the available [ settings] ( #settings.py ) .
116
113
117
114
``` python
118
115
from django_idom import idom_web_modules_path
@@ -128,54 +125,26 @@ urlpatterns = [
128
125
This is where, by a convention similar to that of
129
126
[ ` views.py ` ] ( https://docs.djangoproject.com/en/3.2/topics/http/views/ ) , you'll define
130
127
your [ IDOM] ( https://github.com/idom-team/idom ) components. Ultimately though, you should
131
- feel free to organize your component modules you wish.
128
+ feel free to organize your component modules you wish. The components created here will
129
+ ultimately be referenced by name in ` your-template.html ` . ` your-template.html ` .
132
130
133
131
``` python
134
132
import idom
135
133
136
134
@idom.component
137
135
def Hello (name ): # component names are camelcase by convention
138
- return idom.html.h1(f " Hello { name} ! " )
139
- ```
140
-
141
- ## ` sub_app/idom.py `
142
-
143
- This file is automatically discovered by ` django-idom ` when scanning the list of
144
- [ ` INSTALLED_APPS ` ] ( https://docs.djangoproject.com/en/3.2/ref/settings/#std:setting-INSTALLED_APPS ) .
145
- All apps that export components will contain this module.
146
-
147
- Inside this module must be a ` components ` list that is imported from
148
- [ ` components.py ` ] ( #sub_appcomponents.py ) :
149
-
150
- ``` python
151
- from .components import Hello
152
-
153
- components = [
154
- Hello,
155
- ...
156
- ]
157
- ```
158
-
159
- You may alternately reference the components with strings for the purpose of renaming:
160
-
161
- ``` python
162
- from .components import Hello as SomeOtherName
163
-
164
- components = [
165
- " SomeOtherName" ,
166
- ...
167
- ]
136
+ return Header(f " Hello { name} ! " )
168
137
```
169
138
170
139
## ` sub_app/templates/your-template.html `
171
140
172
141
In your templates, you may inject a view of an IDOM component into your templated HTML
173
142
by using the ` idom_view ` template tag. This tag which requires the name of a component
174
- to render (of the form ` app_name .ComponentName` ) and keyword arguments you'd like to
143
+ to render (of the form ` module_name .ComponentName` ) and keyword arguments you'd like to
175
144
pass it from the template.
176
145
177
146
``` python
178
- idom_view app_name .ComponentName param_1= " something" param_2= " something-else"
147
+ idom_view module_name .ComponentName param_1= " something" param_2= " something-else"
179
148
```
180
149
181
150
In context this will look a bit like the following...
@@ -189,7 +158,7 @@ In context this will look a bit like the following...
189
158
<html >
190
159
<body >
191
160
...
192
- {% idom_view "your_app.sub_app.Hello" name="World" %}
161
+ {% idom_view "your_app.sub_app.components. Hello" name="World" %}
193
162
</body >
194
163
</html >
195
164
```
0 commit comments