Class: ViewPrimitives::Generators::UpdateGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
ComponentCopier, Detector
Defined in:
lib/generators/view_primitives/update/update_generator.rb

Constant Summary

Constants included from Detector

Detector::JS_CONTROLLER_DIRS, Detector::TAILWIND_ENTRIES

Instance Method Summary collapse

Methods included from ComponentCopier

included

Instance Method Details

#report_usageObject



73
74
75
76
77
78
79
# File 'lib/generators/view_primitives/update/update_generator.rb', line 73

def report_usage
  say ""
  say "  Updated ViewPrimitives files from gem templates.", :green
  say "  Custom edits in generated files were overwritten.", :yellow
  say "  Rebuild CSS if Tailwind does not pick up changes automatically.", :cyan
  say ""
end

#update_componentsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/generators/view_primitives/update/update_generator.rb', line 27

def update_components
  return if options[:skip_components]

  names = component_names_to_update
  if names.empty?
    say "  No installed components found. Run `rails g view_primitives:add <name>` first.", :yellow
    return
  end

  @updated = []
  @skipped = []

  names.each do |name|
    unless Components.supported.include?(name)
      @skipped << name
      say "  Unknown component: #{name}", :red
      next
    end

    if copy_component(name)
      @updated << name
    else
      @skipped << name
    end
  end

  report_component_summary
end

#update_css_bundleObject



56
57
58
59
60
61
62
63
# File 'lib/generators/view_primitives/update/update_generator.rb', line 56

def update_css_bundle
  return if options[:skip_css]

  copy_file "view_primitives.css", css_dest_path
  directory "view_primitives", "#{css_dest_dir}/view_primitives"
  preserve_optional_theme_imports
  say "  CSS bundle → #{css_dest_dir}/view_primitives/", :green
end

#update_ui_stylesObject



65
66
67
68
69
70
71
# File 'lib/generators/view_primitives/update/update_generator.rb', line 65

def update_ui_styles
  return if options[:skip_styles]

  legacy = "app/components/ui/ui_styles.rb"
  remove_file legacy if File.exist?(File.join(destination_root, legacy))
  template "styles.rb.tt", "app/components/ui/styles.rb"
end