Class: LcpRuby::ViewSlots::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/lcp_ruby/view_slots/registry.rb

Constant Summary collapse

BUILT_IN_COMPONENTS =
[
  { page: :index, slot: :toolbar_center, name: :view_switcher,      partial: "lcp_ruby/slots/index/view_switcher",      position: 10 },
  { page: :index, slot: :toolbar_end,    name: :manage_all,         partial: "lcp_ruby/slots/index/manage_all",          position: 5 },
  { page: :index, slot: :toolbar_end,    name: :collection_actions, partial: "lcp_ruby/slots/index/collection_actions",  position: 10 },
  { page: :index, slot: :filter_bar,     name: :search,             partial: "lcp_ruby/slots/index/search",              position: 10 },
  { page: :index, slot: :filter_bar,     name: :predefined_filters, partial: "lcp_ruby/slots/index/predefined_filters",  position: 20 },
  { page: :index, slot: :filter_bar,     name: :saved_filters,      partial: "lcp_ruby/slots/index/saved_filters",       position: 25,
    enabled: ->(ctx) { SavedFilters::Registry.available? && ctx.presenter.saved_filters_enabled? } },
  { page: :index, slot: :filter_bar,     name: :sort_dropdown,      partial: "lcp_ruby/slots/index/sort_dropdown",       position: 5,
    enabled: ->(ctx) { ctx.presenter.tiles? || ctx.presenter.sort_fields.any? } },
  { page: :index, slot: :filter_bar,     name: :advanced_filter,    partial: "lcp_ruby/slots/index/advanced_filter",     position: 30 },
  { page: :index, slot: :below_content,  name: :summary_bar,        partial: "lcp_ruby/slots/index/summary_bar",         position: 3,
    enabled: ->(ctx) { ctx.presenter.summary_enabled? } },
  { page: :index, slot: :below_content,  name: :pagination_footer,  partial: "lcp_ruby/slots/index/pagination_footer",   position: 10 },
  { page: :show,  slot: :toolbar_start,  name: :view_switcher,      partial: "lcp_ruby/slots/show/view_switcher",        position: 10 },
  { page: :show,  slot: :toolbar_start,  name: :back_to_list,       partial: "lcp_ruby/slots/show/back_to_list",         position: 20,
    enabled: ->(ctx) { ctx.action_set&.permission_evaluator&.can?("index") } },
  { page: :show,  slot: :toolbar_end,    name: :copy_url,           partial: "lcp_ruby/slots/show/copy_url",             position: 10 },
  { page: :show,  slot: :toolbar_end,    name: :single_actions,     partial: "lcp_ruby/slots/show/single_actions",       position: 20 }
].freeze

Class Method Summary collapse

Class Method Details

.clear!Object



55
56
57
# File 'lib/lcp_ruby/view_slots/registry.rb', line 55

def clear!
  @registry = {}
end

.components_for(page, slot) ⇒ Object



39
40
41
42
# File 'lib/lcp_ruby/view_slots/registry.rb', line 39

def components_for(page, slot)
  key = registry_key(page, slot)
  (registry[key] || []).sort_by(&:position)
end

.register(page:, slot:, name:, partial:, position: 10, enabled: nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/lcp_ruby/view_slots/registry.rb', line 26

def register(page:, slot:, name:, partial:, position: 10, enabled: nil)
  component = SlotComponent.new(
    page: page, slot: slot, name: name,
    partial: partial, position: position, enabled: enabled
  )
  key = registry_key(page, slot)
  registry[key] ||= []

  # Replace existing component with the same name (enables host app overrides)
  registry[key].reject! { |c| c.name == component.name }
  registry[key] << component
end

.register_built_ins!Object



49
50
51
52
53
# File 'lib/lcp_ruby/view_slots/registry.rb', line 49

def register_built_ins!
  BUILT_IN_COMPONENTS.each do |attrs|
    register(**attrs)
  end
end

.registered?(page, slot, name) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
# File 'lib/lcp_ruby/view_slots/registry.rb', line 44

def registered?(page, slot, name)
  key = registry_key(page, slot)
  (registry[key] || []).any? { |c| c.name == name.to_sym }
end