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

html only? #20

Open
aep opened this issue Apr 27, 2018 · 13 comments
Open

html only? #20

aep opened this issue Apr 27, 2018 · 13 comments

Comments

@aep
Copy link

aep commented Apr 27, 2018

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

@kaj
Copy link
Owner

kaj commented Jun 9, 2018

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
Copy link
Owner

kaj commented Dec 11, 2018

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.

@mocsy
Copy link

mocsy commented Dec 22, 2018

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)

@kaj
Copy link
Owner

kaj commented Nov 1, 2019

@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.

@mocsy
Copy link

mocsy commented Nov 1, 2019

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.

@kaj
Copy link
Owner

kaj commented Nov 1, 2019

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 added a commit that referenced this issue Nov 1, 2019
Allow template source files to be named *.rs.svg or *.rs.xml along
with *.rs.html.  The generated template functions will simlilarly be
suffixed _svg, _xml or _html (any template_html will get a template
alias, for backwards compatibility.

Helps #20.
kaj added a commit that referenced this issue Nov 2, 2019
* PR #55 from kornelski: Improve benchmarks.
* Part of issue #20: Allow template source files to be named *.rs.svg
  or *.rs.xml as well as *.rs.html.  The generated template functions
  will simlilarly be suffixed _svg, _xml or _html (any template_html
  will get a template alias, for backwards compatibility.
* PR #61 from Eroc33: Improve parsing for tuple and generic type
  expressions.
* Fix old doc link in readme.
* Update dependencies in ructe and examples.

Thaks to @kornelski and Eroc33.
kaj added a commit that referenced this issue Nov 6, 2019
* Issue #62: New version number due to abi breakage, reported by
  @kornelski.

Otherwise same as 0.7.4:

* PR #55 from kornelski: Improve benchmarks.
* Part of issue #20: Allow template source files to be named *.rs.svg
  or *.rs.xml as well as *.rs.html.  The generated template functions
  will simlilarly be suffixed _svg, _xml or _html (any template_html
  will get a template alias, for backwards compatibility.
* PR #61 from Eroc33: Improve parsing for tuple and generic type
  expressions.
* Fix old doc link in readme.
* Update dependencies in ructe and examples.

Thaks to @kornelski and Eroc33.
kaj added a commit that referenced this issue Nov 6, 2019
* Issue #62: New version number due to a semver-breaking change,
  reported by @kornelski.

Otherwise same as 0.7.4:

* PR #55 from kornelski: Improve benchmarks.
* Part of issue #20: Allow template source files to be named *.rs.svg
  or *.rs.xml as well as *.rs.html.  The generated template functions
  will simlilarly be suffixed _svg, _xml or _html (any template_html
  will get a template alias, for backwards compatibility.
* PR #61 from Eroc33: Improve parsing for tuple and generic type
  expressions.
* Fix old doc link in readme.
* Update dependencies in ructe and examples.

Thaks to @kornelski and Eroc33.
kaj added a commit that referenced this issue Nov 6, 2019
* Issue #62: New version number due to a semver-breaking change,
  reported by @kornelski.

Otherwise same as 0.7.4:

* PR #55 from kornelski: Improve benchmarks.
* Part of issue #20: Allow template source files to be named *.rs.svg
  or *.rs.xml as well as *.rs.html.  The generated template functions
  will simlilarly be suffixed _svg, _xml or _html (any template_html
  will get a template alias, for backwards compatibility.
* PR #61 from Eroc33: Improve parsing for tuple and generic type
  expressions.
* Fix old doc link in readme.
* Update dependencies in ructe and examples.

Thaks to @kornelski and @Eroc33.
@Aunmag
Copy link

Aunmag commented Dec 4, 2019

It would be nice to allow manually set desired file extensions in configs. There would be nothing to do with escaping if we implement #2

@Adeynack
Copy link

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.

@mocsy
Copy link

mocsy commented Jan 22, 2020

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.

@Adeynack
Copy link

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.

@Aunmag
Copy link

Aunmag commented Aug 18, 2020

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

@kaj
Copy link
Owner

kaj commented Aug 18, 2020

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?

@Aunmag
Copy link

Aunmag commented Aug 28, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants