class Gretel::Renderer

Constants

DEFAULT_OPTIONS
DEFAULT_STYLES

Attributes

breadcrumb_args[R]
breadcrumb_key[R]
context[R]

Public Class Methods

new(context, breadcrumb_key, *breadcrumb_args) click to toggle source
# File lib/gretel/renderer.rb, line 28
def initialize(context, breadcrumb_key, *breadcrumb_args)
  @context = context
  @breadcrumb_key = breadcrumb_key
  @breadcrumb_args = breadcrumb_args
end

Private Class Methods

register_style(style_key, options) click to toggle source

Registers a style for later use.

Gretel::Renderer.register_style :ul, { container_tag: :ul, fragment_tag: :li }
# File lib/gretel/renderer.rb, line 145
def register_style(style_key, options)
  styles[style_key] = options
end
styles() click to toggle source

Hash of registered styles.

# File lib/gretel/renderer.rb, line 150
def styles
  @styles ||= DEFAULT_STYLES
end

Public Instance Methods

parent_breadcrumb(options = {}) click to toggle source

Returns the parent breadcrumb.

# File lib/gretel/renderer.rb, line 48
def parent_breadcrumb(options = {})
  render(options)[-2]
end
render(options) click to toggle source

Renders the breadcrumbs HTML.

# File lib/gretel/renderer.rb, line 35
def render(options)
  options = options_for_render(options)
  links = links_for_render(options)

  LinkCollection.new(context, links, options)
end
yield_parent_breadcrumb(options = {}) { |parent| ... } click to toggle source

Yields the parent breadcrumb if any.

# File lib/gretel/renderer.rb, line 53
def yield_parent_breadcrumb(options = {})
  if parent = parent_breadcrumb(options)
    yield parent
  end
end

Private Instance Methods

method_missing(method, *args, &block) click to toggle source

Proxy to view context.

# File lib/gretel/renderer.rb, line 135
def method_missing(method, *args, &block)
  context.send(method, *args, &block)
end
options_for_render(options = {}) click to toggle source

Returns merged options for rendering breadcrumbs.

# File lib/gretel/renderer.rb, line 64
def options_for_render(options = {})
  style = options_for_style(options[:style] || DEFAULT_OPTIONS[:style])
  DEFAULT_OPTIONS.merge(style).merge(options)
end
options_for_style(style_key) click to toggle source

Returns options for the given style_key and raises an exception if it's not found.

# File lib/gretel/renderer.rb, line 70
def options_for_style(style_key)
  if style = self.class.styles[style_key]
    style
  else
    raise ArgumentError, "Breadcrumbs style #{style_key.inspect} not found. Use any of #{self.class.styles.keys.inspect}."
  end
end