Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add configuration to control breadcrumb display #15

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/plutonium/definition/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Definition
class Base
include DefineableProps
include ConfigAttr
include InheritableConfigAttr
include Actions
include Sorting
include Search
Expand Down Expand Up @@ -64,6 +65,14 @@ class TextFilter < Plutonium::Query::Filters::Text; end
:new_page_title, :new_page_description,
:edit_page_title, :edit_page_description

# breadcrumbs
inheritable_config_attr :breadcrumbs,
:index_page_breadcrumbs, :new_page_breadcrumbs,
:edit_page_breadcrumbs, :show_page_breadcrumbs,
:interactive_action_page_breadcrumbs
# global default
breadcrumbs true

def initialize
super
end
Expand Down
33 changes: 33 additions & 0 deletions lib/plutonium/definition/inheritable_config_attr.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Plutonium
module Definition
module InheritableConfigAttr
extend ActiveSupport::Concern

class_methods do
def inheritable_config_attr(*names)
names.each do |name|
# Create the underlying class_attribute
attr_name = :"#{name}_config"
class_attribute attr_name, instance_reader: true, instance_accessor: false, default: nil

# Define class-level method that acts as both getter/setter
define_singleton_method(name) do |value = :__not_set__|
if value == :__not_set__
# Getter behavior
public_send(:"#{attr_name}")
else
# Setter behavior
public_send(:"#{attr_name}=", value)
end
end

# Instance-level method
define_method(name) do
self.class.send(name)
end
end
end
end
end
end
end
10 changes: 10 additions & 0 deletions lib/plutonium/ui/page/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,17 @@ def render_header
end

def render_breadcrumbs
return unless render_breadcrumbs?

Breadcrumbs()
end

def render_breadcrumbs?
# Check specific page setting first, fall back to global setting
page_specific_setting = current_definition.send(:"#{page_type}_breadcrumbs")
page_specific_setting.nil? ? current_definition.breadcrumbs : page_specific_setting
end

def render_page_header
return unless page_title

Expand Down Expand Up @@ -106,6 +114,8 @@ def render_before_footer

def render_after_footer
end

def page_type = raise NotImplementedError, "#{self.class}#page_type"
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/plutonium/ui/page/edit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def page_description
def render_default_content
render "resource_form"
end

def page_type = :edit_page
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/plutonium/ui/page/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def page_actions
def render_default_content
render "resource_table"
end

def page_type = :index_page
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/plutonium/ui/page/interactive_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def page_description
def render_default_content
render "interactive_action_form"
end

def page_type = :interactive_action_page
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/plutonium/ui/page/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def page_description
def render_default_content
render "resource_form"
end

def page_type = :new_page
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/plutonium/ui/page/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def page_actions
def render_default_content
render "resource_details"
end

def page_type = :show_page
end
end
end
Expand Down
Loading