Open
Description
Adding support for pure-python (.py
) dynamic resources, in addition to simplates, could be a solution to several issues. Here's what it could look like:
import things
do_one_time_stuff
a_global_var = None
def GET(website, response): # dependency injection here
if bad:
return response.error(400, 'xxx')
do_GET_stuff
return locals()
def POST(request, response):
do_POST_stuff
response.redirect('…')
PAGES = []
PAGES.append("""text/html
<p>Lorem ipsum</p>
""")
PAGES.append("""application/json
{'lorem': 'ipsum'}
""")
# or
PAGES = """
[---] text/html
<p>Lorem ipsum</p>
[---] application/json
{'lorem': 'ipsum'}
"""
Notes:
- it's a little more verbose than a simplate, but not much
- variables aren't passed implicitly to the templates by default (Switch default list of page 2 variables from 'all of them' to 'Nothing'. pando.py#215)
- pyflakes friendly (no need for implement aspen.simplate.context pando.py#30 and Teach pyflakes about simplates pando.py#546)
- also more friendly to other tools, e.g. test coverage measurement
- single source of truth for supported methods (that's even better than use page 1 metadata for allowed methods pando.py#204)
- possible to decorate functions
- for proper error reporting we can scan the file to determine the line number each template starts at
- syntax highlighting of templates is still possible, but instead of making a new syntax highlighter you need to modify the python one
@whit537 What do you think? Why did you originally go with a custom file format? Is there some issue with using pure python that I missed/forgot?
Metadata
Metadata
Assignees
Labels
No labels