Class: NitroKit::AddGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Extended by:
SchemaBuilder
Defined in:
lib/generators/nitro_kit/add_generator.rb

Constant Summary collapse

SCHEMA =
build_schema do |s|
  s.add(:badge)
  s.add(
    :button,
    components: [:button, :button_group],
    helpers: [:button, :button_group]
  )
  s.add(
    :dropdown,
    js: [:dropdown],
    modules: ["@floating-ui/core", "@floating-ui/dom"]
  )
  s.add(
    :icon,
    gems: ["lucide-rails"]
  )
end

Instance Method Summary collapse

Methods included from SchemaBuilder

build_schema

Instance Method Details

#add_gemsObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/generators/nitro_kit/add_generator.rb', line 41

def add_gems
  gems = components.flat_map(&:gems)

  return unless gems.any?

  gems.each do |name|
    gem(name)
  end

  run("bundle install")
end

#copy_base_componentObject



29
30
31
# File 'lib/generators/nitro_kit/add_generator.rb', line 29

def copy_base_component
  copy_file("app/components/nitro_kit/component.rb", "app/components/nitro_kit/component.rb")
end

#copy_component_filesObject



33
34
35
36
37
38
39
# File 'lib/generators/nitro_kit/add_generator.rb', line 33

def copy_component_files
  components.each do |component|
    component.files.each do |path|
      copy_file(path, path)
    end
  end
end

#install_modulesObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/generators/nitro_kit/add_generator.rb', line 53

def install_modules
  modules = components.flat_map(&:modules)

  return unless modules.any?

  if importmaps?
    run("bin/importmap pin #{modules.join(" ")}")
  else
    say("oh hai npm/yarn/bun")
  end
end