Class: Svelte::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Svelte::InstallGenerator
- Defined in:
- lib/svelte/rails/install_generator.rb
Constant Summary collapse
- TEMPLATE_DIR =
File.('../templates', __FILE__)
Instance Method Summary collapse
- #copy_templates ⇒ Object
- #create_directories ⇒ Object
- #install_svelte_ujs ⇒ Object
- #update_application_entry ⇒ Object
Instance Method Details
#copy_templates ⇒ Object
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_directories ⇒ Object
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_ujs ⇒ Object
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_entry ⇒ Object
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 |