askama icon indicating copy to clipboard operation
askama copied to clipboard

Add support for generating templates in `no_implicit_prelude` modules

Open cipriancraciun opened this issue 4 years ago • 6 comments

At the moment if the template deriving code is used in a module that uses no_implicit_prelude, the code fails to compile because it uses unqualified identifiers from std.

The fix implies using std::result::Result::Ok for example instead of Ok in the generated code.

cipriancraciun avatar May 15 '20 11:05 cipriancraciun

Patches welcome. :)

djc avatar May 15 '20 11:05 djc

Patches welcome. :)

@djc Yes, I intend to do so in the weekend, especially since this is an easy one.

(BTW, I am well aware this is an open-source project, and that especially feature requests should be closely followed by pull requests...) :)

I mainly opened this before the pull request to get some feedback before committing to the actual code.

cipriancraciun avatar May 15 '20 11:05 cipriancraciun

I mainly opened this before the pull request to get some feedback before committing to the actual code.

Good thinking. I think I've provided feedback on all your issues now. :) Let me know if you need further pointers on how to implement/fix things.

djc avatar May 15 '20 12:05 djc

I've started working on this, bellow is the diff that makes the necessary changes:

https://github.com/cipriancraciun/askama/compare/patches/upstream/no-implicit-prelude--base...cipriancraciun:patches/upstream/no-implicit-prelude

I'm unsure how to create thorough test-cases for this. I've copy-pasted the simple.rs test-case, removed all actual testing code, and left only the structures.

(The code is based on-top of the two other issues I've been working on, regarding io::Write and generic render methods, thus once those two are accepted upstream, I'll send a pull request for this one.)

Until then, @djc could you review this?

cipriancraciun avatar May 23 '20 20:05 cipriancraciun

I'm fine with the code generator changes. For the test changes, I don't like all the duplication. I propose you make one test case in an inline module at the bottom of simple.rs, you can decide how complex you want to make the template used in there. Basically, this feature is of low value to me and I don't want myself or other contributors to spend much on supporting it.

djc avatar May 24 '20 18:05 djc

OK, I've made the requested changes. Once the io::Write (with the generic patch) is included I'll create a pull request for this one.

cipriancraciun avatar May 25 '20 08:05 cipriancraciun