Skip to content

Conversation

@katafrakt
Copy link
Contributor

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

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
Contributor 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
Contributor 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