Skip to content
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

The syntax of path variables is ambiguous #61

Open
Changaco opened this issue Jun 23, 2018 · 4 comments
Open

The syntax of path variables is ambiguous #61

Changaco opened this issue Jun 23, 2018 · 4 comments

Comments

@Changaco
Copy link
Member

When the dispatcher encounters a file named %varname.xxx.spt, it can't know for sure whether xxx is a typecast or a file extension. Should we change the separator used for typecasting from a dot . to a colon :?

@Changaco
Copy link
Member Author

Alternatively we could drop support for typecasting, it's seldom used AFAIK, and the current implementation is inefficient.

@chadwhitacre
Copy link
Contributor

Without typecasting you have to do the typecasting manually in each simplate. This gets verbose and WET.

/foo/%bar_id.bar/baz.spt
/foo/%bar_id.bar/buz.spt
/foo/%bar_id.bar/biz.spt

Inside each simplate I want a bar object without having to manually call a library function.

Option: typecasters only apply to directory parts, not file parts? Would that work?

@Changaco
Copy link
Member Author

In Liberapay we don't use typecasting to handle the /%username/ path segment, we import and call the get_participant function in every simplate. Calling the function explicitly makes it easier to send extra arguments to it. The extra import is a little redundant, but it could be removed by attaching get_participant to the website object. This leads me to the conclusion that builtin support for typecasters is unnecessary.

I think the default typecasters (int and float) could be advantageously replaced by simple helper methods that would be available for both the path and the querystring:

bar_id = request.path.get_int('bar_id', minimum=1)
x = request.path.parse('x', float)
page = request.qs.get_int('page', default=1)

@chadwhitacre
Copy link
Contributor

If you want to remove typecasting I won't object. If I ever get to build another Aspen/Pando site and I want typecasters I can bring it back locally as a state chain function. ☺️

@Changaco Changaco self-assigned this Jun 1, 2019
@Changaco Changaco removed their assignment Jun 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants