Module: RubyCms

Defined in:
lib/ruby_cms.rb,
lib/ruby_cms/cli.rb,
lib/ruby_cms/engine.rb,
lib/ruby_cms/version.rb,
lib/ruby_cms/settings.rb,
lib/ruby_cms/css_compiler.rb,
lib/ruby_cms/app_integration.rb,
app/models/ruby_cms/permission.rb,
app/models/ruby_cms/preference.rb,
lib/ruby_cms/settings_registry.rb,
app/models/ruby_cms/permittable.rb,
lib/ruby_cms/content_blocks_sync.rb,
app/models/ruby_cms/content_block.rb,
app/models/ruby_cms/visitor_error.rb,
app/models/ruby_cms/user_permission.rb,
app/helpers/ruby_cms/settings_helper.rb,
lib/ruby_cms/content_blocks_grouping.rb,
app/services/ruby_cms/analytics/report.rb,
app/services/ruby_cms/security_tracker.rb,
app/helpers/ruby_cms/application_helper.rb,
app/components/ruby_cms/admin/admin_page.rb,
lib/generators/ruby_cms/install_generator.rb,
app/controllers/ruby_cms/errors_controller.rb,
app/helpers/ruby_cms/content_blocks_helper.rb,
app/components/ruby_cms/admin/base_component.rb,
app/helpers/ruby_cms/admin/admin_page_helper.rb,
app/helpers/ruby_cms/bulk_action_table_helper.rb,
app/controllers/ruby_cms/admin/base_controller.rb,
app/components/ruby_cms/admin/admin_page_header.rb,
app/controllers/concerns/ruby_cms/page_tracking.rb,
app/controllers/ruby_cms/admin/users_controller.rb,
app/controllers/ruby_cms/admin/locale_controller.rb,
app/components/ruby_cms/admin/admin_resource_card.rb,
app/controllers/concerns/ruby_cms/admin_pagination.rb,
app/controllers/ruby_cms/admin/settings_controller.rb,
app/controllers/concerns/ruby_cms/admin_turbo_table.rb,
app/controllers/ruby_cms/admin/analytics_controller.rb,
app/controllers/ruby_cms/admin/dashboard_controller.rb,
app/helpers/ruby_cms/admin/bulk_action_table_helper.rb,
app/controllers/ruby_cms/admin/permissions_controller.rb,
app/controllers/concerns/ruby_cms/visitor_error_capture.rb,
app/controllers/ruby_cms/admin/visual_editor_controller.rb,
app/controllers/ruby_cms/admin/content_blocks_controller.rb,
app/controllers/ruby_cms/admin/visitor_errors_controller.rb,
app/controllers/ruby_cms/admin/user_permissions_controller.rb,
app/components/ruby_cms/admin/admin_page/admin_table_content.rb,
app/components/ruby_cms/admin/bulk_action_table/bulk_actions.rb,
app/components/ruby_cms/admin/bulk_action_table/bulk_action_table.rb,
app/components/ruby_cms/admin/bulk_action_table/bulk_action_table_row.rb,
app/components/ruby_cms/admin/bulk_action_table/bulk_action_table_body.rb,
app/components/ruby_cms/admin/bulk_action_table/bulk_action_table_header.rb,
app/components/ruby_cms/admin/bulk_action_table/bulk_action_table_actions.rb,
app/components/ruby_cms/admin/bulk_action_table/bulk_action_table_header_bar.rb,
app/components/ruby_cms/admin/bulk_action_table/bulk_action_table_pagination.rb,
app/components/ruby_cms/admin/bulk_action_table/bulk_action_table_delete_modal.rb,
app/components/ruby_cms/admin/bulk_action_table/bulk_action_table_checkbox_cell.rb,
app/components/ruby_cms/admin/bulk_action_table/bulk_action_table_checkbox_head.rb

Defined Under Namespace

Modules: Admin, AdminPagination, AdminTurboTable, Analytics, AppIntegration, ApplicationHelper, BulkActionTableHelper, ContentBlocksGrouping, ContentBlocksHelper, CssCompiler, Generators, Nav, PageTracking, Permittable, Settings, SettingsHelper, SettingsRegistry, VisitorErrorCapture Classes: CLI, ContentBlock, ContentBlocksSync, Engine, Error, ErrorsController, Permission, Preference, RunSetupAdmin, SecurityTracker, UserPermission, VisitorError

Constant Summary collapse

DEFAULT_PERMISSION_KEYS =

Permission configuration (available at boot, before models load)

%w[
  manage_admin
  manage_permissions
  manage_content_blocks
  manage_visitor_errors
  manage_analytics
].freeze
"main"
"Settings"
ANALYTICS_ICON_PATH =
'<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" ' \
'd="M3 3v18h18"></path>' \
'<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" ' \
'd="M7 13l3-3 3 2 4-5"></path>'
VERSION =
"0.1.9"

Class Method Summary collapse

Class Method Details

.app_routesObject

Get registered routes



68
69
70
# File 'lib/ruby_cms/app_integration.rb', line 68

def app_routes
  AppIntegration::LinkApp.registered_routes
end

.configure {|Rails.application.config.ruby_cms| ... } ⇒ Object

Yields:

  • (Rails.application.config.ruby_cms)


53
54
55
# File 'lib/ruby_cms.rb', line 53

def self.configure
  yield(Rails.application.config.ruby_cms)
end

.load_app_settings(view_context) ⇒ Object

Load app settings for view context



78
79
80
# File 'lib/ruby_cms/app_integration.rb', line 78

def load_app_settings(view_context)
  AppIntegration::AppSettings.load_settings(view_context)
end

Register a link for admin navigation. Sections: main (top), Settings (bottom). Add to main with section: “main”, order: 10+; add to bottom with section: “Settings”, order: 10+. Order can be changed via Settings → Navigation drag-and-drop. Options:

  • key: required Symbol/String

  • label: required String

  • path: required String or callable(view_context) -> path

  • icon: optional SVG path fragment

  • section: “main” | “Settings” (or nil => main)

  • order: optional Integer for sorting within section

  • permission: optional permission key (e.g., :manage_analytics)

  • default_visible: optional Boolean (default true)

  • if: optional callable for custom visibility gate



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/ruby_cms.rb', line 74

def self.nav_register(key:, label:, path:, icon: nil, section: nil, order: nil, permission: nil, default_visible: true, **options)
  normalized_key = key.to_sym
  normalized_section = section.presence || NAV_SECTION_MAIN
  entry = {
    key: normalized_key,
    label: label.to_s,
    path: path,
    icon: icon,
    section: normalized_section,
    order: order,
    permission: permission&.to_s,
    default_visible: default_visible ? true : false,
    if: options[:if]
  }

  self.nav_registry = nav_registry.reject {|e| e[:key] == normalized_key }
  self.nav_registry += [entry]

  register_navigation_setting!(entry)

  entry
end

.register_app_routeObject

Register an app route



63
64
65
# File 'lib/ruby_cms/app_integration.rb', line 63

def register_app_route(**)
  AppIntegration::LinkApp.register_route(**)
end

.register_app_settingObject

Register an app setting



73
74
75
# File 'lib/ruby_cms/app_integration.rb', line 73

def register_app_setting(**)
  AppIntegration::AppSettings.register_setting(**)
end

.register_permission_keys(*keys) ⇒ Object



30
31
32
# File 'lib/ruby_cms.rb', line 30

def self.register_permission_keys(*keys)
  self.extra_permission_keys = (extra_permission_keys + keys.flatten.map(&:to_s)).uniq
end

.register_permission_template(name, label:, keys:, description: nil) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/ruby_cms.rb', line 34

def self.register_permission_template(name, label:, keys:, description: nil)
  permission_templates[name.to_sym] = {
    label: label,
    keys: keys.map(&:to_s),
    description: description
  }
end

.setting(key, default: nil) ⇒ Object



57
58
59
# File 'lib/ruby_cms.rb', line 57

def self.setting(key, default: nil)
  RubyCms::Settings.get(key, default:)
end

.visible_nav_registry(view_context: nil, user: nil) ⇒ Object

Returns only entries that pass settings + permissions + conditional checks, sorted by saved nav_order (Settings → Navigation drag-and-drop) when set, else by section + order.



99
100
101
102
103
104
105
106
107
# File 'lib/ruby_cms.rb', line 99

def self.visible_nav_registry(view_context: nil, user: nil)
  list = nav_registry
         .select {|item| nav_entry_visible?(item, view_context:, user:) }
         .sort_by {|item| nav_sort_tuple(item) }
  localize_nav_labels(apply_nav_order(list))
rescue StandardError => e
  Rails.logger.error("[RubyCMS] Error filtering navigation: #{e.message}") if defined?(Rails.logger)
  nav_registry
end