Skip to content

Commit a32a03f

Browse files
add configuration to control breadcrumb dispaly (#15)
1 parent 7556173 commit a32a03f

File tree

8 files changed

+62
-0
lines changed

8 files changed

+62
-0
lines changed

lib/plutonium/definition/base.rb

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module Definition
2626
class Base
2727
include DefineableProps
2828
include ConfigAttr
29+
include InheritableConfigAttr
2930
include Actions
3031
include Sorting
3132
include Search
@@ -64,6 +65,14 @@ class TextFilter < Plutonium::Query::Filters::Text; end
6465
:new_page_title, :new_page_description,
6566
:edit_page_title, :edit_page_description
6667

68+
# breadcrumbs
69+
inheritable_config_attr :breadcrumbs,
70+
:index_page_breadcrumbs, :new_page_breadcrumbs,
71+
:edit_page_breadcrumbs, :show_page_breadcrumbs,
72+
:interactive_action_page_breadcrumbs
73+
# global default
74+
breadcrumbs true
75+
6776
def initialize
6877
super
6978
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module Plutonium
2+
module Definition
3+
module InheritableConfigAttr
4+
extend ActiveSupport::Concern
5+
6+
class_methods do
7+
def inheritable_config_attr(*names)
8+
names.each do |name|
9+
# Create the underlying class_attribute
10+
attr_name = :"#{name}_config"
11+
class_attribute attr_name, instance_reader: true, instance_accessor: false, default: nil
12+
13+
# Define class-level method that acts as both getter/setter
14+
define_singleton_method(name) do |value = :__not_set__|
15+
if value == :__not_set__
16+
# Getter behavior
17+
public_send(:"#{attr_name}")
18+
else
19+
# Setter behavior
20+
public_send(:"#{attr_name}=", value)
21+
end
22+
end
23+
24+
# Instance-level method
25+
define_method(name) do
26+
self.class.send(name)
27+
end
28+
end
29+
end
30+
end
31+
end
32+
end
33+
end

lib/plutonium/ui/page/base.rb

+10
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,17 @@ def render_header
4343
end
4444

4545
def render_breadcrumbs
46+
return unless render_breadcrumbs?
47+
4648
Breadcrumbs()
4749
end
4850

51+
def render_breadcrumbs?
52+
# Check specific page setting first, fall back to global setting
53+
page_specific_setting = current_definition.send(:"#{page_type}_breadcrumbs")
54+
page_specific_setting.nil? ? current_definition.breadcrumbs : page_specific_setting
55+
end
56+
4957
def render_page_header
5058
return unless page_title
5159

@@ -106,6 +114,8 @@ def render_before_footer
106114

107115
def render_after_footer
108116
end
117+
118+
def page_type = raise NotImplementedError, "#{self.class}#page_type"
109119
end
110120
end
111121
end

lib/plutonium/ui/page/edit.rb

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def page_description
1717
def render_default_content
1818
render "resource_form"
1919
end
20+
21+
def page_type = :edit_page
2022
end
2123
end
2224
end

lib/plutonium/ui/page/index.rb

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def page_actions
2121
def render_default_content
2222
render "resource_table"
2323
end
24+
25+
def page_type = :index_page
2426
end
2527
end
2628
end

lib/plutonium/ui/page/interactive_action.rb

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def page_description
1717
def render_default_content
1818
render "interactive_action_form"
1919
end
20+
21+
def page_type = :interactive_action_page
2022
end
2123
end
2224
end

lib/plutonium/ui/page/new.rb

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def page_description
1717
def render_default_content
1818
render "resource_form"
1919
end
20+
21+
def page_type = :new_page
2022
end
2123
end
2224
end

lib/plutonium/ui/page/show.rb

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def page_actions
2121
def render_default_content
2222
render "resource_details"
2323
end
24+
25+
def page_type = :show_page
2426
end
2527
end
2628
end

0 commit comments

Comments
 (0)