Class: Gretel::Renderer
- Inherits:
-
Object
- Object
- Gretel::Renderer
- Extended by:
- Resettable
- Defined in:
- lib/gretel/renderer.rb
Defined Under Namespace
Classes: Base, LinkCollection, NonSemanticRenderer, SemanticRenderer
Constant Summary collapse
- DEFAULT_OPTIONS =
{ style: :inline, pretext: "", posttext: "", separator: "", autoroot: true, display_single_fragment: false, link_current: false, link_current_to_request_path: true, semantic: false, class: "breadcrumbs", current_class: "current", pretext_class: "pretext", posttext_class: "posttext", link_class: nil, id: nil, aria_current: nil, link_data: nil }
- DEFAULT_STYLES =
{ inline: { container_tag: :div, separator: " › " }, ol: { container_tag: :ol, fragment_tag: :li }, ul: { container_tag: :ul, fragment_tag: :li }, bootstrap: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", current_class: "active" }, bootstrap4: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", fragment_class: "breadcrumb-item", current_class: "active" }, bootstrap5: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", fragment_class: "breadcrumb-item", current_class: "active" }, foundation5: { container_tag: :ul, fragment_tag: :li, class: "breadcrumbs", current_class: "current" } }
Class Method Summary collapse
-
.register_style(style_key, options) ⇒ Object
Registers a style for later use.
-
.styles ⇒ Object
Hash of registered styles.
Instance Method Summary collapse
-
#initialize(context, breadcrumb_key, *breadcrumb_args) ⇒ Renderer
constructor
A new instance of Renderer.
-
#parent_breadcrumb(options = {}) ⇒ Object
Returns the parent breadcrumb.
-
#render(options) ⇒ Object
Renders the breadcrumbs HTML.
-
#yield_parent_breadcrumb(options = {}) ⇒ Object
Yields the parent breadcrumb if any.
Methods included from Resettable
Constructor Details
#initialize(context, breadcrumb_key, *breadcrumb_args) ⇒ Renderer
Returns a new instance of Renderer.
36 37 38 39 40 |
# File 'lib/gretel/renderer.rb', line 36 def initialize(context, , *) @context = context @breadcrumb_key = @breadcrumb_args = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
Proxy to view context.
138 139 140 |
# File 'lib/gretel/renderer.rb', line 138 def method_missing(method, *args, &block) context.send(method, *args, &block) end |
Class Method Details
.register_style(style_key, options) ⇒ Object
148 149 150 |
# File 'lib/gretel/renderer.rb', line 148 def register_style(style_key, ) styles[style_key] = end |
.styles ⇒ Object
Hash of registered styles.
153 154 155 |
# File 'lib/gretel/renderer.rb', line 153 def styles @styles ||= DEFAULT_STYLES end |
Instance Method Details
#parent_breadcrumb(options = {}) ⇒ Object
Returns the parent breadcrumb.
51 52 53 |
# File 'lib/gretel/renderer.rb', line 51 def ( = {}) render()[-2] end |
#render(options) ⇒ Object
Renders the breadcrumbs HTML.
43 44 45 46 47 48 |
# File 'lib/gretel/renderer.rb', line 43 def render() = () links = links_for_render() LinkCollection.new(context, links, ) end |
#yield_parent_breadcrumb(options = {}) ⇒ Object
Yields the parent breadcrumb if any.
56 57 58 59 60 |
# File 'lib/gretel/renderer.rb', line 56 def ( = {}) if parent = () yield parent end end |