Class: HotGlue::DirectUploadInstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- HotGlue::DirectUploadInstallGenerator
- Defined in:
- lib/generators/hot_glue/direct_upload_install_generator.rb
Instance Method Summary collapse
- #filepath_prefix ⇒ Object
-
#initialize(*args) ⇒ DirectUploadInstallGenerator
constructor
A new instance of DirectUploadInstallGenerator.
Constructor Details
#initialize(*args) ⇒ DirectUploadInstallGenerator
Returns a new instance of DirectUploadInstallGenerator.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/generators/hot_glue/direct_upload_install_generator.rb', line 12 def initialize(*args) #:nodoc: super if Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name }['importmap-rails'] # impomrtmaps file_contents = File.read("#{filepath_prefix}app/javascript/application.js") if !file_contents.include?("//= require activestorage") file_contents << "//= require activestorage" File.write("#{filepath_prefix}app/javascript/application.js", file_contents) puts " HOTGLUE --> added to #{filepath_prefix}app/javascript/application.js: `//= require activestorage" else puts " HOTGLUE --> #{filepath_prefix}app/javascript/application.js already contains `//= require activestorage`" end elsif Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name }['jsbundling-rails'] file_contents = File.read("#{filepath_prefix}app/javascript/application.js") if !file_contents.include?("ActiveStorage.start()") file_contents << "import * as ActiveStorage from \"@rails/activestorage\" ActiveStorage.start()" File.write("#{filepath_prefix}app/javascript/application.js", file_contents) puts " HOTGLUE --> added to #{filepath_prefix}app/javascript/application.js: `ActiveStorage.start()" else puts " HOTGLUE --> #{filepath_prefix}app/javascript/application.js already contains `ActiveStorage.start()`" end else puts " HOTGLUE --> could not detect either importmap-rails or jsbundling-rails app" end end |
Instance Method Details
#filepath_prefix ⇒ Object
7 8 9 10 |
# File 'lib/generators/hot_glue/direct_upload_install_generator.rb', line 7 def filepath_prefix # todo: inject the context 'spec/dummy/' if $INTERNAL_SPECS end |