Class: ActionText::Generators::InstallGenerator
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
| Class Chain: 
          self,
           ::Rails::Generators::Base,
          Thor::Group | |
| Instance Chain: 
          self,
           ::Rails::Generators::Base,::Rails::Generators::Actions,
          Thor::Actions,
          Thor::Group | |
| Inherits: | Rails::Generators::Base 
 | 
| Defined in: | actiontext/lib/generators/action_text/install/install_generator.rb | 
Class Method Summary
::Rails::Generators::Base - Inherited
| .base_root | Returns the base root for a common set of generators. | 
| .default_source_root | Returns the default source root for a given generator. | 
| .desc | Tries to get the description from a USAGE file one folder above the source root otherwise uses a default description. | 
| .hide! | Convenience method to hide this generator from the available ones when running rails generator command. | 
| .hook_for | Invoke a generator based on the value supplied by the user to the given option named “name”. | 
| .namespace | Convenience method to get the namespace from the class name. | 
| .remove_hook_for | Remove a previously added hook. | 
| .source_root | Returns the source root for this generator using default_source_root as default. | 
| .add_shebang_option! | Small macro to add ruby as an option to the generator with proper default value plus an instance helper method called shebang. | 
| .banner | Use Rails default banner. | 
| .base_name | Sets the base_name taking into account the current class namespace. | 
| .default_aliases_for_option | Returns default aliases for the option name given doing a lookup in Rails::Generators.aliases. | 
| .default_for_option | Returns default for the option name given doing a lookup in config. | 
| .default_generator_root, | |
| .default_value_for_option | Returns the default value for the option name given doing a lookup in Rails::Generators.options. | 
| .generator_name | Removes the namespaces and get the generator name. | 
| .usage_path | |
Instance Attribute Summary
- #using_bun? ⇒ Boolean readonly
- #using_js_runtime? ⇒ Boolean readonly
- #using_node? ⇒ Boolean readonly
::Rails::Generators::Base - Inherited
Instance Method Summary
- #append_javascript_dependencies
- #create_actiontext_files
- #create_migrations
- #enable_image_processing_gem
- #install_javascript_dependencies
::Rails::Generators::Base - Inherited
| #extract_last_module | Takes in an array of nested modules and extracts the last module. | 
| #indent, | |
| #module_namespacing | Wrap block with namespace of current application if namespace exists and is not skipped. | 
| #namespace, #namespaced_path, #wrap_with_namespace | |
::Rails::Generators::Actions - Included
| #add_source | Add the given source to  | 
| #application | Alias for Rails::Generators::Actions#environment. | 
| #environment | Adds configuration code to a Rails runtime environment. | 
| #gem | Adds a  | 
| #gem_group | Wraps gem entries inside a group. | 
| #generate | Runs another generator. | 
| #git | Runs one or more git commands. | 
| #github, | |
| #initializer | Creates an initializer file in  | 
| #lib | Creates a file in  | 
| #rails_command | Runs the specified Rails command. | 
| #rake | Runs the specified Rake task. | 
| #rakefile | Creates a Rake tasks file in  | 
| #readme | Reads the given file at the source root and prints it in the console. | 
| #route | Make an entry in Rails routing file  | 
| #vendor | Creates a file in  | 
| #execute_command | Runs the supplied command using either  | 
| #indentation | Returns a string corresponding to the current indentation level (i.e. 2 *  | 
| #log | Define log for backwards compatibility. | 
| #optimize_indentation | Returns optimized string with indentation. | 
| #quote | Always returns value in double quotes. | 
| #with_indentation | Increases the current indentation indentation level for the duration of the given block, and decreases it after the block ends. | 
Instance Attribute Details
    #using_bun?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
# File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 82
def using_bun? # Cannot assume yarn.lock has been generated yet so we look for a file known to # be generated by the jsbundling-rails gem @using_bun ||= using_js_runtime? && Pathname(destination_root).join("bun.config.js").exist? end
    #using_js_runtime?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
# File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 78
def using_js_runtime? @using_js_runtime ||= Pathname(destination_root).join("package.json").exist? end
    #using_node?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
# File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 88
def using_node? # Bun is the only runtime that _isn't_ node. @using_node ||= using_js_runtime? && !Pathname(destination_root).join("bun.config.js").exist? end
Instance Method Details
#append_javascript_dependencies
[ GitHub ]# File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 22
def append_javascript_dependencies destination = Pathname(destination_root) if (application_javascript_path = destination.join("app/javascript/application.js")).exist? insert_into_file application_javascript_path.to_s, %(\nimport "trix"\nimport "@rails/actiontext"\n) else say <<~INSTRUCTIONS, :green You must import the @rails/actiontext and trix JavaScript modules in your application entrypoint. INSTRUCTIONS end if (importmap_path = destination.join("config/importmap.rb")).exist? append_to_file importmap_path.to_s, %(pin "trix"\npin "@rails/actiontext", to: "actiontext.esm.js"\n) end end
#create_actiontext_files
[ GitHub ]# File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 38
def create_actiontext_files destination = Pathname(destination_root) template "actiontext.css", "app/assets/stylesheets/actiontext.css" unless destination.join("app/assets/application.css").exist? if (stylesheets = Dir.glob "#{destination_root}/app/assets/stylesheets/application.*.{scss,css}").length > 0 insert_into_file stylesheets.first.to_s, %(@import 'actiontext.css';) else say <<~INSTRUCTIONS, :green To use the Trix editor, you must require 'app/assets/stylesheets/actiontext.css' in your base stylesheet. INSTRUCTIONS end end gem_root = "#{__dir__}/../../../.." copy_file "#{gem_root}/app/views/active_storage/blobs/_blob.html.erb", "app/views/active_storage/blobs/_blob.html.erb" copy_file "#{gem_root}/app/views/layouts/action_text/contents/_content.html.erb", "app/views/layouts/action_text/contents/_content.html.erb" end
#create_migrations
[ GitHub ]# File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 74
def create_migrations rails_command "railties:install:migrations FROM=active_storage,action_text", inline: true end
#enable_image_processing_gem
[ GitHub ]# File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 62
def enable_image_processing_gem if (gemfile_path = Pathname(destination_root).join("Gemfile")).exist? say "Ensure image_processing gem has been enabled so image uploads will work (remember to bundle!)" image_processing_regex = /gem ["']image_processing["']/ if File.readlines(gemfile_path).grep(image_processing_regex).any? uncomment_lines gemfile_path, image_processing_regex else run "bundle add --skip-install image_processing" end end end
#install_javascript_dependencies
[ GitHub ]# File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 13
def install_javascript_dependencies say "Installing JavaScript dependencies", :green if using_bun? run "bun add @rails/actiontext trix" elsif using_node? run "yarn add @rails/actiontext trix" end end