Class: RailsMarkup::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- RailsMarkup::Generators::InstallGenerator
- Includes:
- ActiveRecord::Generators::Migration
- Defined in:
- lib/generators/rails_markup/install_generator.rb
Instance Method Summary collapse
- #configure_mcp ⇒ Object
-
#configure_table_name ⇒ Object
Keep the model's config.table_name in lockstep with the table the migration actually creates when a custom name is requested.
- #copy_migration ⇒ Object
- #create_auth_controller ⇒ Object
- #create_bin_wrapper ⇒ Object
- #create_initializer ⇒ Object
- #inject_procfile ⇒ Object
- #inject_toolbar_into_layout ⇒ Object
- #mount_engine ⇒ Object
- #show_post_install ⇒ Object
Instance Method Details
#configure_mcp ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/generators/rails_markup/install_generator.rb', line 100 def configure_mcp require_relative "../../rails_markup/mcp_config" config = RailsMarkup::McpConfig.new(dir: destination_root) dev_url = detect_dev_url env_updates = { "RAILS_MARKUP_DEV_URL" => dev_url, "RAILS_MARKUP_MOUNT_PATH" => [:mount_path] } config.update_env(env_updates) say_status :create, ".mcp.json (dev URL: #{dev_url})", :green end |
#configure_table_name ⇒ Object
Keep the model's config.table_name in lockstep with the table the migration actually creates when a custom name is requested.
35 36 37 38 39 40 41 |
# File 'lib/generators/rails_markup/install_generator.rb', line 35 def configure_table_name return if [:table_name] == "rails_markup_annotations" gsub_file "config/initializers/rails_markup.rb", /^\s*#?\s*config\.table_name\s*=.*$/, %( config.table_name = "#{[:table_name]}") end |
#copy_migration ⇒ Object
24 25 26 27 |
# File 'lib/generators/rails_markup/install_generator.rb', line 24 def copy_migration migration_template "create_rails_markup_annotations.rb.erb", "db/migrate/create_rails_markup_annotations.rb" end |
#create_auth_controller ⇒ Object
43 44 45 |
# File 'lib/generators/rails_markup/install_generator.rb', line 43 def create_auth_controller template "auth_controller.rb.erb", "app/controllers/rails_markup_auth_controller.rb" end |
#create_bin_wrapper ⇒ Object
95 96 97 98 |
# File 'lib/generators/rails_markup/install_generator.rb', line 95 def create_bin_wrapper template "bin_markup.erb", "bin/markup" chmod "bin/markup", 0o755 end |
#create_initializer ⇒ Object
29 30 31 |
# File 'lib/generators/rails_markup/install_generator.rb', line 29 def create_initializer template "initializer.rb.erb", "config/initializers/rails_markup.rb" end |
#inject_procfile ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/generators/rails_markup/install_generator.rb', line 76 def inject_procfile procfile = File.join(destination_root, "Procfile.dev") return unless File.exist?(procfile) content = File.read(procfile) if content =~ /^markup:/ unless content =~ /^markup:\s*bin\/markup\s+server/ gsub_file "Procfile.dev", /^markup:.*$/, "markup: bin/markup server" say_status :update, "Procfile.dev (markup → bin/markup server)", :green else say_status :skip, "Procfile.dev already uses bin/markup server", :yellow end else append_to_file "Procfile.dev", "markup: bin/markup server\n" say_status :append, "Procfile.dev (added markup server)", :green end end |
#inject_toolbar_into_layout ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/generators/rails_markup/install_generator.rb', line 53 def layout_path = "app/views/layouts/#{[:layout]}.html.erb" unless File.exist?(File.join(destination_root, layout_path)) say_status :skip, "#{layout_path} not found — add the toolbar manually", :yellow return end = <<~ERB.indent(4) <%# Rails Markup annotation toolbar %> <% if lookup_context.exists?("rails_markup/shared/toolbar", [], true) %> <%= render "rails_markup/shared/toolbar" %> <% end %> ERB if File.read(File.join(destination_root, layout_path)).include?("rails_markup/shared/toolbar") say_status :skip, "toolbar already present in #{layout_path}", :yellow return end inject_into_file layout_path, , before: %r{</body>} end |
#mount_engine ⇒ Object
47 48 49 50 51 |
# File 'lib/generators/rails_markup/install_generator.rb', line 47 def mount_engine mount_path = [:mount_path] route_line = %{mount RailsMarkup::Engine, at: "#{mount_path}" if defined?(RailsMarkup::Engine)} route route_line end |
#show_post_install ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/generators/rails_markup/install_generator.rb', line 112 def show_post_install say "" say "Rails Markup installed successfully!", :green say "" say "Created:" say " - db/migrate/*_create_rails_markup_annotations.rb" say " - config/initializers/rails_markup.rb" say " - app/controllers/rails_markup_auth_controller.rb" say " - bin/markup" say " - .mcp.json (MCP config for AI agents)" say "" say "Next steps:" say " 1. Run migrations: rails db:migrate" say " 2. Visit dashboard: #{[:mount_path]}" say " 3. Configure auth in config/initializers/rails_markup.rb" say "" dev_url = detect_dev_url unless dev_url == "http://localhost:3000" say "Detected dev server: #{dev_url} (from Procfile.dev)" end say "" say "Not using localhost:3000? Update your dev URL:", :yellow say " bin/markup configure --dev-url=http://YOUR_HOST:PORT" say "" say "CLI commands:" say " bin/markup fetch # See pending annotations" say " bin/markup fetch --env=production # From production" say " bin/markup configure --prod-url=URL --prod-token=TOKEN" say " bin/markup status # Show current config" say "" end |