Class: Svelte::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/svelte/rails/install_generator.rb

Constant Summary collapse

TEMPLATE_DIR =
File.expand_path('../templates', __FILE__)

Instance Method Summary collapse

Instance Method Details

#copy_templatesObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/svelte/rails/install_generator.rb', line 16

def copy_templates
  copy_template(webpack_dir, 'environment.js')
  copy_template(webpack_dir, 'development.js')
  copy_template(webpack_dir, 'production.js')
  copy_template(webpack_dir, 'test.js')

  copy_template(webpack_dir, 'loaders', 'svelte.js')
  copy_template(webpack_dir, 'loaders', 'svelte-ssr.js')

  copy_template(packs_dir, 'server_rendering.js')
  copy_template(components_dir, 'Hello.svelte')
end

#create_directoriesObject



11
12
13
14
# File 'lib/svelte/rails/install_generator.rb', line 11

def create_directories
  empty_directory components_dir
  create_file File.join(components_dir, '.keep')
end

#install_svelte_ujsObject



40
41
42
# File 'lib/svelte/rails/install_generator.rb', line 40

def install_svelte_ujs
  `yarn add svelte_ujs_ng svelte-preprocess`
end

#update_application_entryObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/svelte/rails/install_generator.rb', line 29

def update_application_entry
  path = Pathname.new('app/javascript/packs/application.js')
  content = File.read(File.join(TEMPLATE_DIR, path))

  if path.exist?
    append_file(path, content)
  else
    create_file(path, content)
  end
end