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

Add --template option to generators producing view templates #230

Open
Atelier-Mirai opened this issue Sep 2, 2024 · 6 comments
Open

Add --template option to generators producing view templates #230

Atelier-Mirai opened this issue Sep 2, 2024 · 6 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Atelier-Mirai
Copy link

I like slim templates and would like to use them in HANAMI.

--template option

The FEATURES.md file contains the following.

### v0.8.0 - 2016-07-22
- CLI: `hanami new` can be used with `--template` argument to generate a new project with (`erb`/`haml`/`slim`) templates

I executed the following command.

$ hanami new bookshelf --template=slim
ERROR: "hanami new" was called with arguments "bookshelf --template=slim"

Is the --template option already obsolete?

generate slim template

The following command was executed to generate the action.

$ hanami generate action home.show

The app/templates/home/show.html.erb is created.
How do I configure it to generate a show.html.slim instead of a show.html.erb?

Versions of Hanami are as follows.

$hanami --version
v2.2.0.beta1

Thank you very much for your time, and we appreciate your response.

@timriley
Copy link
Member

timriley commented Sep 2, 2024

Hi @Atelier-Mirai, thanks for your feedback!

The good news is that we already have first class support for Slim with the view layer we reintroduced in Hanami 2.1. Any *.html.slim template file will work :)

Unfortunately, our generators currently do not produce Slim templates. That --template=slim CHANGELOG entry you mentioned is from way back in Hanami 0.8.0, which is many years ago. That flag was lost when we reintroduced the view layer in 2.1.

If you'd like to open PRs bringing this flag back, I'd be very happy to review and accept them. Please also include Haml support, which is our other officially supported template engine :)

@timriley timriley changed the title About slim template support. Add --template option to generators producing view templates Sep 2, 2024
@timriley timriley transferred this issue from hanami/hanami Sep 2, 2024
@timriley timriley added good first issue Good for newcomers help wanted Extra attention is needed labels Sep 2, 2024
@Atelier-Mirai
Copy link
Author

Thank you for your guidance.

I can now use slim templates by writing gem “slim” in the Gemfile.

As a newbie, I do not have the ability to issue a PR and have manually changed from erb to slim. (I just finished the tutorial on BookShelf).

I would like to donate $1 as a thank you, is it possible, I am looking forward to the completion of 2.2.0.

@katafrakt
Copy link

@timriley I can take it, since there are no takers. Would you want it for 2.2 release1?

Also one question for clarification:

The original report mentions hanami new bookshelf --template=slim, which I assume sets the default format, so it does not need to be specified every time with the generator. Should that be supported as well?

Footnotes

  1. No promises, but I can try.

@Atelier-Mirai
Copy link
Author

I am very happy to reply from you.
And thank you for working on the 2.2 implementation.

It was my understanding that each time I use slim, I need to write the template options.

Example 1

hanami new bookshelf --template=slim
hanami new bookshelf2 --template=slim
hanami new bookshelf3 --template=slim

Slim is specified as the default format. Therefore, the template option will not be necessary next time. This is very convenient and appreciated.

Example 2

# Set default format to slim
hanami new bookshelf --template=slim
# You don't need to specify the template option next time.
hanami new bookshelf2
hanami new bookshelf3

Example 2 is more convenient, but if it is difficult to implement, just Example 1 is fine.

I really appreciate your willingness to work on the implementation.
Thank you very much.

@timriley
Copy link
Member

timriley commented Nov 1, 2024

@katafrakt I'd love it if you could pick this up, thank you!

This one feels like a bit of a stretch to include in the upcoming 2.2 release. However, I plan for releases to be smaller and more frequent after 2.2, so I wouldn't expect things like this to be stuck inside git repos forever.

The reason I say it feels like a stretch relates to your question:

The original report mentions hanami new bookshelf --template=slim, which I assume sets the default format, so it does not need to be specified every time with the generator. Should that be supported as well?

I think the ideal experience would be for a preferred template type to be saved somewhere so that the user doesn't have to specify it on every CLI invocation (which would be pretty annoying, I think). This expands the scope of this PR a little. There are several ways we might implement something like this, so I'd like to make sure we have the breathing room to get it right and do it well.

Does that make sense? I certainly don't want this to feel like a downer. I'm very excited to see you're interested in taking this on!

@katafrakt
Copy link

@timriley sure, that makes sense, of course. If the defaults should be stored that's indeed almost a new feature and probably unwise to introduce between the RC and final.

We can get back to discussing the details here after the release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants