Class: RailsMarkup::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_markup/configuration.rb

Constant Summary collapse

ALLOWED_ACCENTS =
%w[indigo amber blue emerald rose].freeze
ALLOWED_POSITIONS =
%w[tl tr br bl].freeze
ALLOWED_SIZES =
%w[slim compact default].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rails_markup/configuration.rb', line 77

def initialize
  @base_controller_class = "RailsMarkup::ApplicationController"
  @api_token = nil
  @table_name = "rails_markup_annotations"
  @per_page = 25
  @toolbar_accent = "indigo"
  @toolbar_enabled = true
  @fab_visible = true
  @toolbar_position = "bl"
  @toolbar_size = "default"
  @return_url = nil
  @dashboard_layout = "rails_markup/application"
  @author_name_method = :email
  @on_create_callback = nil
  @enable_screenshots = true
  @health_interval = 60
end

Instance Attribute Details

#api_tokenObject

Bearer token for the external API (MCP production tools). Set to nil to disable external API.



16
17
18
# File 'lib/rails_markup/configuration.rb', line 16

def api_token
  @api_token
end

#author_name_methodObject

Method name (Symbol) or Proc to resolve the author's display name from the current_user. Symbol: calls user.public_send(method_name) — e.g. :name, :email, :display_name Proc: receives user, returns string — e.g. ->(u) { u.full_name } Default: :email



54
55
56
# File 'lib/rails_markup/configuration.rb', line 54

def author_name_method
  @author_name_method
end

#base_controller_classObject

Base controller class name for dashboard/API controllers. Set to a controller that provides authentication. Example: "AdminAuthController"



12
13
14
# File 'lib/rails_markup/configuration.rb', line 12

def base_controller_class
  @base_controller_class
end

#dashboard_layoutObject

Layout for the dashboard views. Set to a host app layout name to embed within that layout. Default: "rails_markup/application" (engine's own layout) Example: "admin"



45
46
47
# File 'lib/rails_markup/configuration.rb', line 45

def dashboard_layout
  @dashboard_layout
end

#enable_screenshotsObject

Enable element screenshot capture in the toolbar. Default: true



63
64
65
# File 'lib/rails_markup/configuration.rb', line 63

def enable_screenshots
  @enable_screenshots
end

#fab_visibleObject

Show the floating action button (FAB) specifically. When false, the FAB is hidden but the toolbar system stays active — pins still render and the panel is reachable via its toggle. Use when the host provides its own trigger or wants read-only pins. Requires toolbar_enabled. Default: true



34
35
36
# File 'lib/rails_markup/configuration.rb', line 34

def fab_visible
  @fab_visible
end

#health_intervalObject

Health check poll interval in seconds. Default: 60



75
76
77
# File 'lib/rails_markup/configuration.rb', line 75

def health_interval
  @health_interval
end

#on_create_callbackObject

Proc called after an annotation is created. Receives the annotation record. Use for email/Slack/webhook notifications. Default: nil (no callback)



59
60
61
# File 'lib/rails_markup/configuration.rb', line 59

def on_create_callback
  @on_create_callback
end

#per_pageObject

Number of annotations per page on the dashboard.



48
49
50
# File 'lib/rails_markup/configuration.rb', line 48

def per_page
  @per_page
end

#return_urlObject

URL path for "Back to app" link in the dashboard header. Set to nil to hide the link. Example: "/admin"



39
40
41
# File 'lib/rails_markup/configuration.rb', line 39

def return_url
  @return_url
end

#table_nameObject

Database table name for annotations.



19
20
21
# File 'lib/rails_markup/configuration.rb', line 19

def table_name
  @table_name
end

#toolbar_accentObject

Accent color for the toolbar FAB and UI elements.



22
23
24
# File 'lib/rails_markup/configuration.rb', line 22

def toolbar_accent
  @toolbar_accent
end

#toolbar_enabledObject

Render the annotation toolbar system at all (FAB, panel, pins, sync). Set to false to disable rails-markup entirely for a request/environment. Default: true



27
28
29
# File 'lib/rails_markup/configuration.rb', line 27

def toolbar_enabled
  @toolbar_enabled
end

#toolbar_positionObject

FAB button position: "bl" (bottom-left), "br" (bottom-right), "tl" (top-left), "tr" (top-right). Default: "bl"



67
68
69
# File 'lib/rails_markup/configuration.rb', line 67

def toolbar_position
  @toolbar_position
end

#toolbar_sizeObject

FAB button size: "default" (48px), "compact" (40px), "slim" (32px). Default: "default"



71
72
73
# File 'lib/rails_markup/configuration.rb', line 71

def toolbar_size
  @toolbar_size
end

Instance Method Details

#resolve_author_name(user) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/rails_markup/configuration.rb', line 95

def resolve_author_name(user)
  return nil unless user

  case author_name_method
  when Symbol then user.respond_to?(author_name_method) ? user.public_send(author_name_method) : nil
  when Proc   then author_name_method.call(user)
  end
rescue => e
  Rails.logger.warn("[rails-markup] author_name_method error: #{e.message}") if defined?(Rails)
  nil
end