ructe icon indicating copy to clipboard operation
ructe copied to clipboard

html only?

Open aep opened this issue 6 years ago • 13 comments

why do the template files have to end in .html?

aep avatar Apr 27 '18 14:04 aep

Currently, html is the only string escaping that's supported. It's a simple fix to allow any file name for templates, but I haven't really thought through how to handle string escaping for other formats yet.

kaj avatar Jun 09 '18 19:06 kaj

On second thought, though, .xml and .svg files (and some other xml-based formats) use the same escaping, and should be possible to use by only changing the filename-matching rules.

I'll take a look at this.

kaj avatar Dec 11 '18 11:12 kaj

I depend on compile_templates only picking up .html at the moment.

It would be neat if we could configure what extensions each template functions would pick up. compile_templates picks up .rs.html compile_static_files picks up lot's of extensions including .rs (on which it crashed for me when last experimented with it)

mocsy avatar Dec 22 '18 22:12 mocsy

@mocsy ;

I depend on compile_templates only picking up .html at the moment.

Why? Do you have your templates in your src directory rather than in an specific templates directory? If so, why?

I'm about to add compiling of templates named *.rs.svg and *.rs.xml besides *.rs.html. I might add other formats in the future, but for other formats, other quoting rules should apply, and I don't want to imply support for such formats before there is actul support for those quoting rules.

As for other xml-like formats, I'm open for suggestions for suffixes that would be useful.

kaj avatar Nov 01 '19 11:11 kaj

Instead of templates I have a modules folder like so I can organize an couple my code into modules, rather than crates. Had I used a separate templates folder, I'd have to use crates for each of those. Example:

  • src
    • modules
      • user
        • login.rs
        • login.rs.html
        • register.rs
        • register.rs.html
        • ...
      • api
      • emails
      • ... I think *.rs.svg and *.rs.xml and other would be neat.

mocsy avatar Nov 01 '19 17:11 mocsy

Ah, that should work even when picking up more template names. Even with more template formats, it will only assume a file named x.rs.y is a template if y is a known template format (currently html, soon html, xml or svg, maybe more in the future).

kaj avatar Nov 01 '19 21:11 kaj

It would be nice to allow manually set desired file extensions in configs. There would be nothing to do with escaping if we implement https://github.com/kaj/ructe/issues/2

Aunmag avatar Dec 04 '19 06:12 Aunmag

Would using Ructe for genering templated Rust code an option? From what I understand from it, it was made with HTML in mind, but definitely not limited to it. Thoughts on that? Or is there better options than templates to generate Rust code?

Please do not throw 🍅🍅🍅since I am a some-week-old Rustacean ;-) still getting to know the ecosystem.

Adeynack avatar Jan 21 '20 17:01 Adeynack

Would using Ructe for genering templated Rust code an option? From what I understand from it, it was made with HTML in mind, but definitely not limited to it. Thoughts on that? Or is there better options than templates to generate Rust code?

Please do not throw tomatotomatotomatosince I am a some-week-old Rustacean ;-) still getting to know the ecosystem.

I think in ructe 0.8.0 template source files can be named *.rs.svg, *.rs.xml and *.rs.html, that suggests *.rs.rs won't load. Might not be too hard to fix that, but I let @kaj to judge.

That being said, I built my first rust code generator in rust with the format! macro, which is enough to get something done quick. The de-facto standard nova-days is to write proc-macros, derives, or attributes. Those don't fit all use-cases, so it depends on what kind of rust code you actually want to generate and more importantly, when in the pipeline.

mocsy avatar Jan 22 '20 11:01 mocsy

The de-facto standard nova-days is to write proc-macros, derives, or attributes. Those don't fit all use-cases, so it depends on what kind of rust code you actually want to generate and more importantly, when in the pipeline.

My current project idea is code generation from an OpenAPI Specification, generating all routes and value parsing logic and creating types for inputs and outputs, so in the end, only the pure business logic has to be implemented, returning a typed result. Hence the Rust code generation.

Adeynack avatar Jan 26 '20 21:01 Adeynack

Can we just allow any file extensions as is, without escaping?

Aunmag avatar Aug 18 '20 04:08 Aunmag

Can we just allow any file extensions as is, without escaping?

I guess we could, but that would essentially be a separate template engine, so maybe it should be a separate crate?

kaj avatar Aug 18 '20 09:08 kaj

Can we just allow any file extensions as is, without escaping?

I guess we could, but that would essentially be a separate template engine, so maybe it should be a separate crate?

Maybe. I wish there was a generic library for text/code generation with great controll over spaces. I use ructe to generate boilerplate human-readable SQL and JS code, 'cause I see no alternatives for that so far. I really like ructe concept and syntax.

Aunmag avatar Aug 28 '20 09:08 Aunmag