Skip to content

Commit

Permalink
Merge pull request #3058 from kulturbande/generate-view-component-in-…
Browse files Browse the repository at this point in the history
…ingredient-generator
  • Loading branch information
tvdeyen authored Sep 29, 2024
2 parents 8d4c097 + 6bb2595 commit 34f8b34
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/generators/alchemy/ingredient/ingredient_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ def init
@ingredients_view_path = "app/views/alchemy/ingredients"
end

def create_view_component
template "view_component.rb.tt", "app/components/alchemy/ingredients/#{file_name}_view.rb"
end

def create_model
template "model.rb.tt", "app/models/alchemy/ingredients/#{file_name}.rb"
end

def copy_templates
@ingredient_editor_local = "#{file_name}_editor"
@ingredient_view_local = "#{file_name}_view"
@ingredient_view_component_class = "#{@class_name}View"
template "view.html.erb", "#{@ingredients_view_path}/_#{file_name}_view.html.erb"
template "editor.html.erb", "#{@ingredients_view_path}/_#{file_name}_editor.html.erb"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/alchemy/ingredient/templates/view.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%%= <%= @ingredient_view_local %>.value %>
<%%= render Alchemy::Ingredients::<%= @ingredient_view_component_class %>.new(<%= @ingredient_view_local %>) %>
10 changes: 10 additions & 0 deletions lib/generators/alchemy/ingredient/templates/view_component.rb.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Alchemy
module Ingredients
class <%= @class_name %>View < BaseView

def call
content_tag(:div, ingredient.value)
end
end
end
end

0 comments on commit 34f8b34

Please sign in to comment.