Class: HotwiredComponent::ComponentGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/hotwired_component/component/component_generator.rb

Overview

Generates ViewComponents with Stimulus/Hotwire

Instance Method Summary collapse

Instance Method Details

#create_component_fileObject



9
10
11
12
13
14
# File 'lib/generators/hotwired_component/component/component_generator.rb', line 9

def create_component_file
  template(
    "component.rb.erb",
    File.join("app/components", class_path, "#{file_name}_component.rb")
  )
end

#create_javascript_fileObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/generators/hotwired_component/component/component_generator.rb', line 38

def create_javascript_file
  template(
    "component_controller.js.erb",
    File.join(
      "app/components",
      class_path,
      "#{file_name}_component/component_controller.js"
    )
  )
end

#create_scss_fileObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/generators/hotwired_component/component/component_generator.rb', line 16

def create_scss_file
  template(
    "component.scss.erb",
    File.join(
      "app/components",
      class_path,
      "#{file_name}_component/#{file_name}_component.scss"
    )
  )
end

#create_template_fileObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/generators/hotwired_component/component/component_generator.rb', line 27

def create_template_file
  create_file(
    File.join(
      "app/components",
      class_path,
      "#{file_name}_component/#{file_name}_component.html.erb"
    ),
    component_div
  )
end

#create_test_fileObject



49
50
51
52
53
54
55
# File 'lib/generators/hotwired_component/component/component_generator.rb', line 49

def create_test_file
  template(
    "component_test.rb.erb",
    File.join("test/components", class_path,
      "#{file_name}_component_test.rb")
  )
end