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

Allow specifying engine for generated templates #280

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

katafrakt
Copy link

This addresses part of #230 by allowing to specify --template CLI option, which will create an ERb, HAML or Slim base template. For example:

hanami generate view users.sign_in.new --template haml

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`
@katafrakt katafrakt force-pushed the template-engine-generator branch from 5b9aaea to a79c842 Compare December 11, 2024 16:28
@@ -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,
Copy link
Author

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,
Copy link
Author

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)",
Copy link
Author

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

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

Successfully merging this pull request may close these issues.

1 participant