Skip to content

Commit

Permalink
More refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cllns committed Jan 3, 2025
1 parent eb7bf14 commit 2e019c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/hanami/cli/generators/app/ruby_class_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def write
end

def fully_qualified_name
inflector.camelize([namespace, "Views", *key.split(KEY_SEPARATOR)].join("/"))
inflector.camelize([namespace, extra_namespace, *key.split(KEY_SEPARATOR)].join("/"))
end

private
Expand Down
19 changes: 14 additions & 5 deletions lib/hanami/cli/generators/app/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class View
DEFAULT_FORMAT = "html"
private_constant :DEFAULT_FORMAT

TEMPLATES_FOLDER = "templates"
private_constant :TEMPLATES_FOLDER

# @since 2.0.0
# @api private
def initialize(fs:, inflector:, out: $stdout)
Expand All @@ -27,7 +30,8 @@ def initialize(fs:, inflector:, out: $stdout)
def call(key:, namespace:, base_path:)
view_class = view_class_file(key:, namespace:, base_path:)
view_class.create
write_template_file(key:, namespace:, base_path:, view_class_name: view_class.fully_qualified_name)
view_class_name = view_class.fully_qualified_name
write_template_file(key:, namespace:, base_path:, view_class_name:)
end

private
Expand All @@ -49,14 +53,19 @@ def view_class_file(key:, namespace:, base_path:)
def write_template_file(key:, namespace:, base_path:, view_class_name:)
key_parts = key.split(KEY_SEPARATOR)
class_name_from_key = key_parts.pop
modules_from_key = key_parts # Now that the class name has popped off
folder_path = fs.join(base_path, "templates", modules_from_key)
file_path = fs.join(folder_path, template_with_format_ext(class_name_from_key, DEFAULT_FORMAT))
module_names_from_key = key_parts # Now that the class name has popped off

file_path = fs.join(
base_path,
TEMPLATES_FOLDER,
module_names_from_key,
template_file_name(class_name_from_key, DEFAULT_FORMAT),
)
body = "<h1>#{view_class_name}</h1>\n"
fs.write(file_path, body)
end

def template_with_format_ext(name, format)
def template_file_name(name, format)
ext =
case format.to_sym
when :html
Expand Down

0 comments on commit 2e019c7

Please sign in to comment.