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.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/rails_markup/configuration.rb', line 84

def initialize
  @base_controller_class = "RailsMarkup::ApplicationController"
  @api_token = nil
  @require_api_token_in_development = false
  @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



61
62
63
# File 'lib/rails_markup/configuration.rb', line 61

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"



52
53
54
# File 'lib/rails_markup/configuration.rb', line 52

def dashboard_layout
  @dashboard_layout
end

#enable_screenshotsObject

Enable element screenshot capture in the toolbar. Default: true



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

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



41
42
43
# File 'lib/rails_markup/configuration.rb', line 41

def fab_visible
  @fab_visible
end

#health_intervalObject

Health check poll interval in seconds. Default: 60



82
83
84
# File 'lib/rails_markup/configuration.rb', line 82

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)



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

def on_create_callback
  @on_create_callback
end

#per_pageObject

Number of annotations per page on the dashboard.



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

def per_page
  @per_page
end

#require_api_token_in_developmentObject

In development the external API skips token auth by default so you can reach it from another device on your LAN (e.g. your phone). That allows unauthenticated reads AND writes from any network peer. Set to true to require the bearer token even in development. Default: false (open in development)



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

def require_api_token_in_development
  @require_api_token_in_development
end

#return_urlObject

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



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

def return_url
  @return_url
end

#table_nameObject

Database table name for annotations.



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

def table_name
  @table_name
end

#toolbar_accentObject

Accent color for the toolbar FAB and UI elements.



29
30
31
# File 'lib/rails_markup/configuration.rb', line 29

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



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

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"



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

def toolbar_position
  @toolbar_position
end

#toolbar_sizeObject

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



78
79
80
# File 'lib/rails_markup/configuration.rb', line 78

def toolbar_size
  @toolbar_size
end

Instance Method Details

#resolve_author_name(user) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/rails_markup/configuration.rb', line 103

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