Class: Pinmark::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/pinmark/install/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_importmap_pinObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/generators/pinmark/install/install_generator.rb', line 16

def add_importmap_pin
  return unless File.exist?("config/importmap.rb")

  append_to_file "config/importmap.rb" do
    <<~RB

      # pinmark engine — Stimulus controller for the dev annotation overlay
      pin "controllers/pinmark_controller", to: "pinmark/pinmark_controller.js"
    RB
  end
end

#mount_engineObject



12
13
14
# File 'lib/generators/pinmark/install/install_generator.rb', line 12

def mount_engine
  route 'mount Pinmark::Engine, at: "/dev/pinmark" if Rails.env.local?'
end

#show_post_install_notesObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/generators/pinmark/install/install_generator.rb', line 28

def show_post_install_notes
  say "\nPinmark installed.", :green
  say <<~NOTES

    Next steps (manual):

    1. If you use Phlex, include the concern in your component base class
       so `<!-- pinmark:begin/end -->` markers wrap each render:

         class Components::Base < Phlex::HTML
           include Pinmark::Phlex if Rails.env.development?
         end

    2. Render the activator + overlay partials in your dev-only layout
       sections (works in any Rails view — ERB, Phlex, or ViewComponent):

         <%= render "pinmark/activator" %>
         <%= render "pinmark/overlay" %>

       Wrap with the usual dev-only / tracker guard if desired:

         if Rails.env.development? && Current.pinmark.present?
           render "pinmark/activator"
           render "pinmark/overlay"
         end

    3. Add `attribute :pinmark` to your `Current` model and include
       `Pinmark::Session` in the controllers whose responses should
       support annotations (typically StorefrontController).

    4. Register the in-process MCP server with Claude Code:

         claude mcp add pinmark --transport http \\
           http://localhost:PORT/dev/pinmark/annotations/mcp

    5. Webpack/yarn-based hosts (no importmap): add the engine as a
       `file:` dependency in your host's package.json, then import the
       Stimulus controller directly from the gem — do NOT copy the JS
       into the host. Example:

         # package.json
         "pinmark": "file:#{Pinmark::Engine.root}"

         # app/javascript/packs/your_pack.js
         import PinmarkController from 'pinmark/pinmark_controller'
         window.Stimulus.register('pinmark', PinmarkController)

       Run `yarn install` after adding the dependency. The engine is the
       single source of truth; updates flow through the symlink.

  NOTES
end