lib/svelte_on_rails/installer/hello_world.rb



module SvelteOnRails
  module Installer
    module HelloWorld

      def self.install_hello_world(files)

        utils_i = SvelteOnRails::Installer::Utils

        # write templates


        utils_i.write_templates(files)


        # route

        route = 'svelte_on_rails_hello_world#index'
        rr = utils_i.which_root_route
        root_url = "/"
        url = root_url + route.sub('#', '/')

        if rr && rr == route
          puts "Root route «#{route}» already exists, skipping."
          root_url
        elsif rr && utils_i.route_exists?(route.sub('#', '/'))
          puts "route «#{route}» already exists, skipping."
          url
        elsif rr
          utils_i.add_route("  get \"#{route.sub('#', '/')}\"")
          url
        else
          utils_i.add_route('  root "svelte_on_rails_hello_world#index"')
          root_url
        end

      end

      def self.remove_hello_world(files)

        utils = SvelteOnRails::Installer::Utils
        if utils.ask_yn('Remove the Hello World component?')
          utils.remove_files(files)
          utils.remove_line_from_file('config/routes.rb', 'svelte_on_rails_hello_world')
        end
      end

    end
  end
end