agentation 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Agentation
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace Agentation
6
+
7
+ # Configure asset paths for all asset pipelines (Sprockets/Propshaft)
8
+ initializer "agentation.assets" do |app|
9
+ next unless app.config.respond_to?(:assets)
10
+
11
+ # CSS is served from app/assets/stylesheets
12
+ app.config.assets.paths << Engine.root.join("app/assets/stylesheets")
13
+
14
+ # ESM JavaScript is served from vendor/javascript
15
+ app.config.assets.paths << Engine.root.join("vendor/javascript")
16
+
17
+ # Precompile the main assets
18
+ app.config.assets.precompile += %w[agentation.css agentation.esm.js]
19
+ end
20
+
21
+ # Importmap support (Rails 7+)
22
+ initializer "agentation.importmap", before: "importmap" do |app|
23
+ next unless defined?(Importmap) && app.respond_to?(:importmap)
24
+
25
+ # Pin the ESM module
26
+ app.config.after_initialize do
27
+ app.importmap.pin "agentation", to: "agentation.esm.js" if app.importmap.respond_to?(:pin)
28
+ end
29
+ end
30
+
31
+ # Add view helpers
32
+ initializer "agentation.view_helpers" do
33
+ ActiveSupport.on_load(:action_view) do
34
+ include Agentation::ViewHelpers
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Agentation
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Agentation
6
+ module ViewHelpers
7
+ # Renders the Agentation toolbar
8
+ #
9
+ # Options:
10
+ # output_detail: "compact" | "standard" | "detailed" | "forensic" (default: "standard")
11
+ # annotation_color: hex color string (default: "#3c82f7")
12
+ # auto_clear_after_copy: boolean (default: false)
13
+ # block_interactions: boolean (default: false)
14
+ # dark_mode: boolean (default: true)
15
+ #
16
+ # Example:
17
+ # <%= agentation_toolbar %>
18
+ # <%= agentation_toolbar(output_detail: "forensic", annotation_color: "#34C759") %>
19
+ #
20
+ def agentation_toolbar(options = {})
21
+ content_tag(:div, id: "agentation-root", data: {
22
+ agentation: true,
23
+ options: options.to_json
24
+ }) do
25
+ # Empty content - JavaScript initializes the toolbar
26
+ ""
27
+ end
28
+ end
29
+ end
30
+ end
data/lib/agentation.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "agentation/version"
4
+ require_relative "agentation/engine" if defined?(Rails::Engine)
5
+ require_relative "agentation/view_helpers"
6
+
7
+ module Agentation
8
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/base"
4
+
5
+ module Agentation
6
+ module Generators
7
+ class InstallGenerator < Rails::Generators::Base
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ desc "Install Agentation toolbar into your Rails application"
11
+
12
+ def add_stylesheet
13
+ if File.exist?("app/assets/stylesheets/application.css")
14
+ inject_into_file "app/assets/stylesheets/application.css",
15
+ " *= require agentation\n",
16
+ before: " *= require_tree ."
17
+ say "Added agentation stylesheet to application.css", :green
18
+ else
19
+ say "Could not find application.css - please add manually:", :yellow
20
+ say ' @import "agentation";', :yellow
21
+ end
22
+ end
23
+
24
+ def add_javascript
25
+ if File.exist?("app/javascript/application.js")
26
+ append_to_file "app/javascript/application.js", 'import "agentation"' + "\n"
27
+ say "Added agentation import to application.js", :green
28
+ else
29
+ say "Could not find application.js - please add manually:", :yellow
30
+ say ' import "agentation"', :yellow
31
+ end
32
+ end
33
+
34
+ def add_toolbar_helper
35
+ layout_file = "app/views/layouts/application.html.erb"
36
+
37
+ if File.exist?(layout_file)
38
+ content = File.read(layout_file)
39
+
40
+ if content.include?("agentation_toolbar")
41
+ say "Toolbar helper already present in layout", :yellow
42
+ elsif content.include?("</body>")
43
+ inject_into_file layout_file,
44
+ " <%= agentation_toolbar %>\n",
45
+ before: " </body>"
46
+ say "Added agentation_toolbar helper to layout", :green
47
+ else
48
+ say "Could not find </body> tag - please add manually:", :yellow
49
+ say " <%= agentation_toolbar %>", :yellow
50
+ end
51
+ else
52
+ say "Could not find application layout - please add manually:", :yellow
53
+ say " <%= agentation_toolbar %>", :yellow
54
+ end
55
+ end
56
+
57
+ def show_instructions
58
+ say ""
59
+ say "Agentation installed successfully!", :green
60
+ say ""
61
+ say "The toolbar will appear in the bottom-right corner of your app."
62
+ say "Click the sparkle icon to activate annotation mode."
63
+ say ""
64
+ say "Options available:"
65
+ say ' <%= agentation_toolbar(output_detail: "forensic") %>'
66
+ say ' <%= agentation_toolbar(annotation_color: "#ff6b6b") %>'
67
+ say ""
68
+ end
69
+ end
70
+ end
71
+ end