Class: Gretel::Renderer

Inherits:
Object
  • Object
show all
Extended by:
Resettable
Defined in:
lib/gretel/renderer.rb

Defined Under Namespace

Classes: LinkCollection

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",
  id: nil,
  aria_current: 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" },
  foundation5: { container_tag: :ul, fragment_tag: :li, class: "breadcrumbs", current_class: "current" }
}

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resettable

reset!

Constructor Details

#initialize(context, breadcrumb_key, *breadcrumb_args) ⇒ Renderer

Returns a new instance of Renderer.



33
34
35
36
37
# File 'lib/gretel/renderer.rb', line 33

def initialize(context, breadcrumb_key, *breadcrumb_args)
  @context = context
  @breadcrumb_key = breadcrumb_key
  @breadcrumb_args = 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.



135
136
137
# File 'lib/gretel/renderer.rb', line 135

def method_missing(method, *args, &block)
  context.send(method, *args, &block)
end

Class Method Details

.register_style(style_key, options) ⇒ Object

Registers a style for later use.

Gretel::Renderer.register_style :ul, { container_tag: :ul, fragment_tag: :li }


145
146
147
# File 'lib/gretel/renderer.rb', line 145

def register_style(style_key, options)
  styles[style_key] = options
end

.stylesObject

Hash of registered styles.



150
151
152
# File 'lib/gretel/renderer.rb', line 150

def styles
  @styles ||= DEFAULT_STYLES
end

Instance Method Details

#parent_breadcrumb(options = {}) ⇒ Object

Returns the parent breadcrumb.



48
49
50
# File 'lib/gretel/renderer.rb', line 48

def parent_breadcrumb(options = {})
  render(options)[-2]
end

#render(options) ⇒ Object

Renders the breadcrumbs HTML.



40
41
42
43
44
45
# File 'lib/gretel/renderer.rb', line 40

def render(options)
  options = options_for_render(options)
  links = links_for_render(options)

  LinkCollection.new(context, links, options)
end

#yield_parent_breadcrumb(options = {}) ⇒ Object

Yields the parent breadcrumb if any.



53
54
55
56
57
# File 'lib/gretel/renderer.rb', line 53

def yield_parent_breadcrumb(options = {})
  if parent = parent_breadcrumb(options)
    yield parent
  end
end