Skip to content

Commit a3dcd0d

Browse files
committed
Switch to template data to use pythonic words over inertia words
1 parent d689d87 commit a3dcd0d

File tree

7 files changed

+29
-29
lines changed

7 files changed

+29
-29
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ You can also check out the official Inertia docs at https://inertiajs.com/.
4747

4848
### Responses
4949

50-
Render Inertia responses is simple, you can either use the provided inertia render function or, for the most common use case, the inertia decorator. The render function accepts four arguments, the first is your request object. The second is the name of the component you want to render from within your pages directory (without extension). The third argument is a dict of `props` that should be provided to your components. The final argument is `view_data`, for any variables you want to provide to your template, but this is much less common.
50+
Render Inertia responses is simple, you can either use the provided inertia render function or, for the most common use case, the inertia decorator. The render function accepts four arguments, the first is your request object. The second is the name of the component you want to render from within your pages directory (without extension). The third argument is a dict of `props` that should be provided to your components. The final argument is `template_data`, for any variables you want to provide to your template, but this is much less common.
5151

5252
```python
5353
from inertia import render
@@ -161,12 +161,12 @@ class ExampleTestCase(InertiaTestCase):
161161
# access props
162162
self.assertEquals(self.props()['name'], 'Brandon')
163163

164-
# view data
165-
self.assertHasExactViewData({name: 'Brian', sport: 'basketball'})
166-
self.assertIncludesViewData({sport: 'basketball'})
164+
# template data
165+
self.assertHasExactTemplateData({name: 'Brian', sport: 'basketball'})
166+
self.assertIncludesTemplateData({sport: 'basketball'})
167167

168-
# access view data
169-
self.assertEquals(self.view_data()['name'], 'Brian')
168+
# access template data
169+
self.assertEquals(self.template_data()['name'], 'Brian')
170170
```
171171

172172
The inertia test helper also includes a special `inertia` client that pre-sets the inertia headers

inertia/http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import requests
77
from .utils import LazyProp
88

9-
def render(request, component, props={}, view_data={}):
9+
def render(request, component, props={}, template_data={}):
1010
def is_a_partial_render():
1111
return 'X-Inertia-Partial-Data' in request.headers and request.headers.get('X-Inertia-Partial-Component', '') == component
1212

@@ -73,7 +73,7 @@ def page_data():
7373
return base_render(request, 'inertia.html', {
7474
'inertia_layout': settings.INERTIA_LAYOUT,
7575
'page': json_encode(page_data(), cls=settings.INERTIA_JSON_ENCODER),
76-
**view_data,
76+
**template_data,
7777
})
7878

7979
def inertia(component):

inertia/test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def page(self):
3030
def props(self):
3131
return self.page()['props']
3232

33-
def view_data(self):
33+
def template_data(self):
3434
context = self.mock_render.call_args.args[2]
3535

3636
return {key: context[key] for key in context if key not in ['page', 'inertia_layout']}
@@ -44,16 +44,16 @@ def assertIncludesProps(self, props):
4444
def assertHasExactProps(self, props):
4545
self.assertDictEqual(self.props(), props)
4646

47-
def assertIncludesViewData(self, view_data):
48-
self.assertDictEqual(self.view_data(), {**self.view_data(), **view_data})
47+
def assertIncludesTemplateData(self, template_data):
48+
self.assertDictEqual(self.template_data(), {**self.template_data(), **template_data})
4949

50-
def assertHasExactViewData(self, view_data):
51-
self.assertDictEqual(self.view_data(), view_data)
50+
def assertHasExactTemplateData(self, template_data):
51+
self.assertDictEqual(self.template_data(), template_data)
5252

5353
def assertComponentUsed(self, component_name):
5454
self.assertEqual(component_name, self.component())
5555

56-
def inertia_page(url, component='TestComponent', props={}, view_data={}):
56+
def inertia_page(url, component='TestComponent', props={}, template_data={}):
5757
return {
5858
'component': 'TestComponent',
5959
'props': props,

inertia/tests/test_rendering.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ def test_with_props(self):
1010
})
1111
)
1212

13-
def test_with_view_data(self):
13+
def test_with_template_data(self):
1414
self.assertContains(
15-
self.client.get('/view_data/'),
16-
inertia_div('view_data', view_data={
15+
self.client.get('/template_data/'),
16+
inertia_div('template_data', template_data={
1717
'name': 'Brian',
1818
'sport': 'Basketball',
1919
})
@@ -45,10 +45,10 @@ def test_with_props(self):
4545
})
4646
)
4747

48-
def test_with_view_data(self):
48+
def test_with_template_data(self):
4949
self.assertJSONResponse(
50-
self.inertia.get('/view_data/'),
51-
inertia_page('view_data', view_data={
50+
self.inertia.get('/template_data/'),
51+
inertia_page('template_data', template_data={
5252
'name': 'Brian',
5353
'sport': 'Basketball',
5454
})

inertia/tests/test_tests.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ def test_has_exact_props(self):
1212

1313
self.assertHasExactProps({'name': 'Brandon', 'sport': 'Hockey'})
1414

15-
def test_has_view_data(self):
16-
response = self.client.get('/view_data/')
15+
def test_has_template_data(self):
16+
response = self.client.get('/template_data/')
1717

18-
self.assertIncludesViewData({'name': 'Brian'})
18+
self.assertIncludesTemplateData({'name': 'Brian'})
1919

20-
def test_has_exact_view_data(self):
21-
response = self.client.get('/view_data/')
20+
def test_has_exact_template_data(self):
21+
response = self.client.get('/template_data/')
2222

23-
self.assertHasExactViewData({'name': 'Brian', 'sport': 'Basketball'})
23+
self.assertHasExactTemplateData({'name': 'Brian', 'sport': 'Basketball'})
2424

2525
def test_component_name(self):
2626
response = self.client.get('/props/')

inertia/tests/testapp/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
path('empty/', views.empty_test),
77
path('redirect/', views.redirect_test),
88
path('props/', views.props_test),
9-
path('view_data/', views.view_data_test),
9+
path('template_data/', views.template_data_test),
1010
path('lazy/', views.lazy_test),
1111
path('complex-props/', views.complex_props_test),
1212
path('share/', views.share_test),

inertia/tests/testapp/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def props_test(request):
3030
'sport': 'Hockey',
3131
}
3232

33-
def view_data_test(request):
34-
return render(request, 'TestComponent', view_data={
33+
def template_data_test(request):
34+
return render(request, 'TestComponent', template_data={
3535
'name': 'Brian',
3636
'sport': 'Basketball',
3737
})

0 commit comments

Comments
 (0)