Class: Railsbytes::Commands::Install
- Inherits:
-
Railsbytes::Command
- Object
- Railsbytes::Command
- Railsbytes::Commands::Install
- Includes:
- Thor::Actions
- Defined in:
- lib/railsbytes/commands/install.rb
Constant Summary collapse
- TEMPLATES =
[ { value: 'X8Bsjx', name: 'devise' }, { value: 'x9Qsqx', name: 'bootstrap' }, { value: 'VMysyV', name: 'stimulus_reflex' }, { value: 'z5OsqV', name: 'tailwind' } ].freeze
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(name) ⇒ Install
constructor
A new instance of Install.
Methods inherited from Railsbytes::Command
Constructor Details
#initialize(name) ⇒ Install
Returns a new instance of Install.
24 25 26 |
# File 'lib/railsbytes/commands/install.rb', line 24 def initialize(name) @name = name end |
Instance Method Details
#execute ⇒ Object
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 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/railsbytes/commands/install.rb', line 28 def execute(*) puts '' spinner = TTY::Spinner.new(":spinner Searching for '#{@name}' templates on railsbytes.com", format: :bouncing_ball) spinner.auto_spin sleep 0.5 spinner.stop template_id = prompt.select("\nAwesome! Found the following templates:", TEMPLATES) template = TEMPLATES.find { |t| t[:value] == template_id } script = LHC.get("https://railsbytes.com/script/#{template_id}").body puts '' print TTY::Box.info( script, title: { top_left: "Template: #{template[:name]}", bottom_right: "id: #{template_id}" }, style: { fg: :white, bg: :bright_black, border: { fg: :white, bg: :bright_black } } ) puts '' install = prompt.yes?("Do you want apply this template to your Rails app '#{Dir.pwd}'?", default: false) return unless install command.run("rails app:template LOCATION=\"https://railsbytes.com/script/#{template_id}\"") rescue TTY::Reader::InputInterrupt puts "\nAborting..." exit(0) end |