Class: Domternal::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Domternal::Generators::InstallGenerator
- Defined in:
- lib/generators/domternal/install/install_generator.rb
Overview
rails g domternal:install
Detects whether the host app uses importmap-rails or a Node/Bun bundler (jsbundling-rails, vite_rails, ...) and wires up the JS accordingly, mirroring ActionText's install generator (lib/generators/action_text/install/install_generator.rb).
Constant Summary collapse
- CORE_PACKAGE =
@domternal/vanilla and every @domternal/extension-* package declare @domternal/core (and, transitively, @domternal/pm — the ProseMirror re-export used for plugin identity) as peer dependencies. esm.sh only emits real
importstatements for a peer (rather than inlining its own private copy) when it's passed via?external=, so every consumer below must externalize the same set — otherwise two different copies of ProseMirror's Plugin/PluginKey classes end up on the page and construction fails with "Adding different instances of a keyed plugin". @domternal/pm's own subpaths (state, view, model, ...) are covered by a single prefix pin instead of being listed one by one. "@domternal/core"- PM_PACKAGE =
"@domternal/pm"- NPM_PACKAGES =
{ CORE_PACKAGE => nil, "@domternal/vanilla" => [CORE_PACKAGE], "@domternal/extension-image" => [CORE_PACKAGE, PM_PACKAGE] }.freeze
- OPTIONAL_NPM_PACKAGES =
%w[ @domternal/extension-table @domternal/extension-mention @domternal/extension-markdown @domternal/extension-emoji @domternal/extension-math @domternal/extension-code-block-lowlight @domternal/extension-toc @domternal/extension-block-controls @domternal/extension-details ].index_with { [CORE_PACKAGE, PM_PACKAGE] }.freeze
Instance Method Summary collapse
- #create_initializer ⇒ Object
- #create_migrations ⇒ Object
- #create_stylesheet ⇒ Object
- #show_readme ⇒ Object
- #wire_up_javascript ⇒ Object
Instance Method Details
#create_initializer ⇒ Object
47 48 49 |
# File 'lib/generators/domternal/install/install_generator.rb', line 47 def create_initializer template "initializer.rb", "config/initializers/domternal.rb" end |
#create_migrations ⇒ Object
61 62 63 |
# File 'lib/generators/domternal/install/install_generator.rb', line 61 def create_migrations rails_command "railties:install:migrations FROM=active_storage,domternal", inline: true end |
#create_stylesheet ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/generators/domternal/install/install_generator.rb', line 51 def create_stylesheet template "domternal.css.erb", "app/assets/stylesheets/domternal.css" say <<~INSTRUCTIONS, :green Add `<%= stylesheet_link_tag "domternal" %>` to your layout (next to your application stylesheet tag) to load the Domternal theme and editor styles. INSTRUCTIONS create_content_stylesheet end |
#show_readme ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/generators/domternal/install/install_generator.rb', line 78 def show_readme say <<~INSTRUCTIONS, :green Domternal is installed. Next steps: 1. bin/rails db:migrate 2. In a model: has_rich_domternal :body 3. In a form: <%= form.domternal_area :body %> 4. To render: <%= domternal_content @post.body %> INSTRUCTIONS end |
#wire_up_javascript ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/generators/domternal/install/install_generator.rb', line 65 def wire_up_javascript if using_importmap? wire_up_importmap elsif using_jsbundling? wire_up_jsbundling else say <<~INSTRUCTIONS, :yellow Could not detect importmap-rails or a package.json — add the Domternal JS yourself. See #{__dir__}/../../../../README.md for both approaches. INSTRUCTIONS end end |