Class: Practical::Views::Navigation::BreadcrumbsComponent
- Inherits:
-
BaseComponent
- Object
- BaseComponent
- Practical::Views::Navigation::BreadcrumbsComponent
- Defined in:
- app/components/practical/views/navigation/breadcrumbs_component.rb
Instance Attribute Summary collapse
-
#breadcrumb_trail ⇒ Object
Returns the value of attribute breadcrumb_trail.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #build_crumb(crumb:) ⇒ Object
- #crumbs_for_truncation ⇒ Object
- #finalized_options ⇒ Object
-
#initialize(breadcrumb_trail:, options: {}) ⇒ BreadcrumbsComponent
constructor
A new instance of BreadcrumbsComponent.
- #truncate_end ⇒ Object
- #truncate_middle? ⇒ Boolean
- #truncate_start ⇒ Object
- #truncated_items ⇒ Object
Constructor Details
#initialize(breadcrumb_trail:, options: {}) ⇒ BreadcrumbsComponent
Returns a new instance of BreadcrumbsComponent.
7 8 9 10 |
# File 'app/components/practical/views/navigation/breadcrumbs_component.rb', line 7 def initialize(breadcrumb_trail:, options: {}) self. = self. = end |
Instance Attribute Details
#breadcrumb_trail ⇒ Object
Returns the value of attribute breadcrumb_trail.
4 5 6 |
# File 'app/components/practical/views/navigation/breadcrumbs_component.rb', line 4 def end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'app/components/practical/views/navigation/breadcrumbs_component.rb', line 5 def end |
Instance Method Details
#build_crumb(crumb:) ⇒ Object
36 37 38 39 40 |
# File 'app/components/practical/views/navigation/breadcrumbs_component.rb', line 36 def build_crumb(crumb:) render(Practical::Views::::BreadcrumbItemComponent.new(options: { href: crumb.current? ? nil : crumb.url })) { crumb.name } end |
#crumbs_for_truncation ⇒ Object
16 17 18 |
# File 'app/components/practical/views/navigation/breadcrumbs_component.rb', line 16 def crumbs_for_truncation @crumbs_for_truncation ||= .to_a end |
#finalized_options ⇒ Object
12 13 14 |
# File 'app/components/practical/views/navigation/breadcrumbs_component.rb', line 12 def mix({}, ) end |
#truncate_end ⇒ Object
28 29 30 |
# File 'app/components/practical/views/navigation/breadcrumbs_component.rb', line 28 def truncate_end crumbs_for_truncation.last(2) end |
#truncate_middle? ⇒ Boolean
20 21 22 |
# File 'app/components/practical/views/navigation/breadcrumbs_component.rb', line 20 def truncate_middle? crumbs_for_truncation.size > 5 end |
#truncate_start ⇒ Object
24 25 26 |
# File 'app/components/practical/views/navigation/breadcrumbs_component.rb', line 24 def truncate_start crumbs_for_truncation.first(1) end |
#truncated_items ⇒ Object
32 33 34 |
# File 'app/components/practical/views/navigation/breadcrumbs_component.rb', line 32 def truncated_items crumbs_for_truncation - truncate_start - truncate_end end |