-
-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,9 @@ class Action < App::Command | |
DEFAULT_SKIP_ROUTE = false | ||
private_constant :DEFAULT_SKIP_ROUTE | ||
|
||
DEFAULT_TEMPLATE = "erb" | ||
private_constant :DEFAULT_TEMPLATE | ||
|
||
argument :name, required: true, desc: "Action name" | ||
option :url, required: false, type: :string, desc: "Action URL" | ||
option :http, required: false, type: :string, desc: "Action HTTP method" | ||
|
@@ -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, | ||
desc: "Template engine to use (officially supported options: erb, haml, slim)" | ||
|
||
# rubocop:disable Layout/LineLength | ||
example [ | ||
|
@@ -94,6 +99,7 @@ def call( | |
skip_view: DEFAULT_SKIP_VIEW, | ||
skip_tests: DEFAULT_SKIP_TESTS, # rubocop:disable Lint/UnusedMethodArgument, | ||
skip_route: DEFAULT_SKIP_ROUTE, | ||
template: DEFAULT_TEMPLATE, | ||
slice: nil, | ||
context: nil, | ||
** | ||
|
@@ -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 commentThe 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? |
||
context: context) | ||
end | ||
|
||
# rubocop:enable Metrics/ParameterLists | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,10 +18,10 @@ class View < App::Command | |
DEFAULT_FORMAT = "html" | ||
private_constant :DEFAULT_FORMAT | ||
|
||
# TODO: make engine configurable | ||
|
||
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 commentThe 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 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 |
||
default: "erb" | ||
|
||
example [ | ||
%(books.index (MyApp::Actions::Books::Index)), | ||
|
@@ -43,10 +43,10 @@ def initialize( | |
|
||
# @since 2.0.0 | ||
# @api private | ||
def call(name:, format: DEFAULT_FORMAT, slice: nil, **) | ||
def call(name:, format: DEFAULT_FORMAT, template: "erb", slice: nil, **) | ||
slice = inflector.underscore(Shellwords.shellescape(slice)) if slice | ||
|
||
generator.call(app.namespace, name, format, slice) | ||
generator.call(app.namespace, name, format, template, slice) | ||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
%h1= <%= camelized_slice_name %>::Views::<%= camelized_controller_name %>::<%= camelized_action_name %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
h1 = <%= camelized_slice_name %>::Views::<%= camelized_controller_name %>::<%= camelized_action_name %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
%h1= <%= camelized_app_name %>::Views::<%= camelized_controller_name %>::<%= camelized_action_name %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
h1 = <%= camelized_app_name %>::Views::<%= camelized_controller_name %>::<%= camelized_action_name %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
%h1 <%= camelized_app_name %>::Views::<%= camelized_namespace %>::<%= camelized_name %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
h1 <%= camelized_app_name %>::Views::<%= camelized_namespace %>::<%= camelized_name %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
%h1 <%= camelized_slice_name %>::Views::<%= camelized_namespace %>::<%= camelized_name %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
h1 <%= camelized_slice_name %>::Views::<%= camelized_namespace %>::<%= camelized_name %> |
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 maybetemplate-engine
would be more descriptive? Although a bit long.