-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Allow specifying engine for generated templates #280
base: main
Are you sure you want to change the base?
Conversation
Currently ERB template is always generated by default, but it's desirable to be able to also create HAML or slim templates. This commit makes it possible by passing a CLI option `--template`: `hanami generate view users.sign_in.new --template haml`
5b9aaea
to
a79c842
Compare
@@ -51,6 +54,8 @@ class Action < App::Command | |||
default: DEFAULT_SKIP_ROUTE, | |||
desc: "Skip route generation" | |||
option :slice, required: false, desc: "Slice name" | |||
option :template, required: false, type: :string, default: DEFAULT_TEMPLATE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used template
because this was mentioned in the original issue and apparently it was named like this in Hanami 1 times. But maybe template-engine
would be more descriptive? Although a bit long.
@@ -106,7 +112,8 @@ def call( | |||
raise InvalidActionNameError.new(name) | |||
end | |||
|
|||
generator.call(app.namespace, controller, action, url, http, format, skip_view, skip_route, slice, context: context) | |||
generator.call(app.namespace, controller, action, url, http, format, skip_view, skip_route, template, slice, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels weird with so many positional arguments. Should I convert this to keyword?
argument :name, required: true, desc: "View name" | ||
option :slice, required: false, desc: "Slice name" | ||
option :template, required: false, desc: "Template engine to use (officially supported: erb, haml, slim)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should happen if an engine outside the list is called? Currently you can do --template md
and it will create a file with .md
extension and with default HTML (from ERb engine). Which is not entirely wrong, but maybe the list should be restricted and produce error if user specifies unsupported engine?
This also brought the question if this should not be extensible in some way, so gems could hook into it and provide own base templates for their engines (for example hanami-phlex
).
This addresses part of #230 by allowing to specify
--template
CLI option, which will create an ERb, HAML or Slim base template. For example: