Class: Gretel::Renderer
- Inherits:
-
Object
- Object
- Gretel::Renderer
- 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", pretext_class: "pretext", posttext_class: "posttext", 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
-
.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_links(options = {}) {|render(options)| ... } ⇒ Object
Yields links with applied options.
-
#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.
27 28 29 30 31 |
# File 'lib/gretel/renderer.rb', line 27 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.
134 135 136 |
# File 'lib/gretel/renderer.rb', line 134 def method_missing(method, *args, &block) context.send(method, *args, &block) end |
Class Method Details
.register_style(style_key, options) ⇒ Object
144 145 146 |
# File 'lib/gretel/renderer.rb', line 144 def register_style(style_key, ) styles[style_key] = end |
.styles ⇒ Object
Hash of registered styles.
149 150 151 |
# File 'lib/gretel/renderer.rb', line 149 def styles @styles ||= DEFAULT_STYLES end |
Instance Method Details
#parent_breadcrumb(options = {}) ⇒ Object
Returns the parent breadcrumb.
47 48 49 |
# File 'lib/gretel/renderer.rb', line 47 def ( = {}) render()[-2] end |
#render(options) ⇒ Object
Renders the breadcrumbs HTML.
34 35 36 37 38 39 |
# File 'lib/gretel/renderer.rb', line 34 def render() = () links = links_for_render() LinkCollection.new(context, links, ) end |
#yield_links(options = {}) {|render(options)| ... } ⇒ Object
Yields links with applied options.
42 43 44 |
# File 'lib/gretel/renderer.rb', line 42 def yield_links( = {}) yield render() end |
#yield_parent_breadcrumb(options = {}) ⇒ Object
Yields the parent breadcrumb if any.
52 53 54 55 56 |
# File 'lib/gretel/renderer.rb', line 52 def ( = {}) if parent = () yield parent end end |