Module: SvelteOnRails::Installer::HelloWorld

Defined in:
lib/svelte_on_rails/installer/hello_world.rb

Class Method Summary collapse

Class Method Details

.install_hello_world(templates, force: false, app_root: nil, silent: false, vite_dir: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/svelte_on_rails/installer/hello_world.rb', line 5

def self.install_hello_world(templates, force: false, app_root: nil, silent: false, vite_dir: nil)

  utils_i = SvelteOnRails::Installer::Utils

  # write templates

  utils_i.write_templates(templates, ask_for_overwrite: !force, app_root: app_root, silent: silent, vite_dir: vite_dir)

  # routes

  utils_i.add_route("  get \"svelte_on_rails_showcase/backend_frontend_rendered\"", app_root: app_root)
  utils_i.add_route("  get \"svelte_on_rails_showcase/ssr_auto_rendered\"", app_root: app_root)
  utils_i.add_route("  get \"svelte_on_rails_showcase\", to: \"svelte_on_rails_showcase#index\"", app_root: app_root)

end

.remove_hello_world(templates = ['showcase'], app_root: nil, ask: true) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/svelte_on_rails/installer/hello_world.rb', line 22

def self.remove_hello_world(templates = ['showcase'], app_root: nil, ask: true)

  utils = SvelteOnRails::Installer::Utils

  files = utils.template_paths(templates, app_root: app_root)

  existing_files = files.dup.select { |f| File.exist?(f[2]) }

  if ask && existing_files.any?
    question = "Remove Hello World component?\nThe following files will be removed:\n#{existing_files.map { |f| f[1] }.join("\n")}"
    return unless utils.ask_yn(question)
  end

  existing_files.each do |f|
    File.delete(f[2])
  end
  puts "Removed Hello World component files."

  utils.remove_line_from_file(
    utils.app_root_path(app_root).join('config/routes.rb'),
    "svelte_on_rails_showcase",
    force: !ask,
  )

end