Class: ViewPrimitives::Generators::AddGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Detector
Defined in:
lib/generators/view_primitives/add/add_generator.rb

Constant Summary

Constants included from Detector

Detector::JS_CONTROLLER_DIRS, Detector::TAILWIND_ENTRIES

Instance Method Summary collapse

Instance Method Details

#copy_componentsObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/generators/view_primitives/add/add_generator.rb', line 15

def copy_components
  @copied = []
  @unknown = []

  components.each do |name|
    if Components.supported.include?(name)
      copy_component(name)
      @copied << name
    else
      @unknown << name
      say "  Unknown component: #{name}. Supported: #{Components.supported.join(", ")}", :red
    end
  end
end

#copy_file(source, *args, **options) ⇒ Object



58
59
60
61
62
# File 'lib/generators/view_primitives/add/add_generator.rb', line 58

def copy_file(source, *args, **options)
  destination = args.first || options[:to]
  warn_overwrite(destination) if destination
  super
end

#report_setup_notesObject



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

def report_setup_notes
  @copied&.each do |name|
    note = Components::SETUP_NOTES[name]
    next unless note

    say ""
    say "  ── Setup required for #{name} ──────────────────────────", :yellow
    note.each_line { |line| say "  #{line.chomp}", :cyan }
    say ""
  end
end

#report_summaryObject



30
31
32
33
34
35
36
37
38
# File 'lib/generators/view_primitives/add/add_generator.rb', line 30

def report_summary
  say "" if @copied&.any? || @unknown&.any?
  say "  Copied: #{@copied.join(", ")}", :green if @copied&.any?
  return if @unknown.blank?

  say "  Failed: #{@unknown.join(", ")} (unknown)", :red
  say "  Run `rails g view_primitives:list` to see all available components.", :cyan
  abort
end

#template(source, *args, **options, &block) ⇒ Object



52
53
54
55
56
# File 'lib/generators/view_primitives/add/add_generator.rb', line 52

def template(source, *args, **options, &block)
  destination = args.first || options[:to]
  warn_overwrite(destination) if destination
  super
end