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,
  semantic: false,
  class: "breadcrumbs",
  current_class: "current",
  id: 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" },
  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.



25
26
27
28
29
# File 'lib/gretel/renderer.rb', line 25

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.



132
133
134
# File 'lib/gretel/renderer.rb', line 132

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 }


142
143
144
# File 'lib/gretel/renderer.rb', line 142

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

.stylesObject

Hash of registered styles.



147
148
149
# File 'lib/gretel/renderer.rb', line 147

def styles
  @styles ||= DEFAULT_STYLES
end

Instance Method Details

#parent_breadcrumb(options = {}) ⇒ Object

Returns the parent breadcrumb.



45
46
47
# File 'lib/gretel/renderer.rb', line 45

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

#render(options) ⇒ Object

Renders the breadcrumbs HTML.



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

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

  LinkCollection.new(context, links, options)
end

Yields links with applied options.

Yields:



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

def yield_links(options = {})
  yield render(options)
end

#yield_parent_breadcrumb(options = {}) ⇒ Object

Yields the parent breadcrumb if any.



50
51
52
53
54
# File 'lib/gretel/renderer.rb', line 50

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