Class: Zestui::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/zestui/install/install_generator.rb

Constant Summary collapse

TAILWIND_CONFIGURATION_PATH =
Rails.root.join("config/tailwind.config.js")
TAILWIND_STYLESHEET_PATH =
Rails.root.join("app/assets/stylesheets/application.tailwind.cs")

Instance Method Summary collapse

Instance Method Details

#after_install_messageObject



81
82
83
# File 'lib/generators/zestui/install/install_generator.rb', line 81

def after_install_message
  say "Visit https://zestui.com/docs/installation for next steps.\n\n", :yellow
end

#configure_tailwind_configObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/generators/zestui/install/install_generator.rb', line 32

def configure_tailwind_config
    unless File.exist?(TAILWIND_CONFIGURATION_PATH)
      say "\n"
      say "************" * 10
      say "\n"
      say "#{TAILWIND_CONFIGURATION_PATH} not found", :red
      say "Please follow the manual installation instructions at https://zestui.com/docs/installation#manual-tailwind-config", :yellow
      say "\n"
      say "************" * 10
      say "\n"
      return
    end


    prepend_to_file TAILWIND_CONFIGURATION_PATH do
      "const zestuiPreset = require('./config/zestui/tailwind/preset');\n\n"
    end

    inject_into_file TAILWIND_CONFIGURATION_PATH, "\n  presets: [zestuiPreset],\n", after: /module\.exports = \{$/

    insert_into_file TAILWIND_CONFIGURATION_PATH, after: "content: [" do
		"\n    './app/views/**/*.rb'," \
		"\n    './app/components/**/*.rb',"
	end
end

#configure_tailwind_stylesheetObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/generators/zestui/install/install_generator.rb', line 58

def configure_tailwind_stylesheet
  unless File.exist?(TAILWIND_STYLESHEET_PATH)
    say "\n"
    say "************" * 10
    say "\n"
    say "#{TAILWIND_STYLESHEET_PATH} not found", :red
    say "Please follow the manual installation instructions at https://zestui.com/docs/installation#manual-tailwind-css-config", :yellow
    say "\n"
    say "************" * 10
    say "\n"
    return
  end

  gsub_file TAILWIND_STYLESHEET_PATH, /@tailwind (base|components|utilities);/, ''

  append_to_file TAILWIND_STYLESHEET_PATH do
    "@import 'tailwindcss/base';\n" \
    "@import 'tailwindcss/components';\n" \
    "@import 'tailwindcss/utilities';\n" \
    "\n\n @import './zui/index.css'; \n"
  end
end

#copy_zestuiObject



24
25
26
# File 'lib/generators/zestui/install/install_generator.rb', line 24

def copy_zestui
  directory self.class.source_root, Rails.root
end

#update_stimulus_manifestObject



28
29
30
# File 'lib/generators/zestui/install/install_generator.rb', line 28

def update_stimulus_manifest
  rails_command "stimulus:manifest:update"
end

#verify_zestui_pathObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/generators/zestui/install/install_generator.rb', line 9

def verify_zestui_path
  zestui_path = self.class.source_root

  unless zestui_path && File.directory?(zestui_path)
    say "ZESTUI_PATH is not set or invalid.", :red
    abort
  end

  initializer_path = File.join(zestui_path, 'config/initializers/zui.rb')
  unless File.exist?(initializer_path)
    say "The required file 'config/initializers/zui.rb' is not found in the ZESTUI_PATH. The path is likely invalid.", :red
    abort
  end
end