Class: Ariane::Render::HTMLList
Overview
Public: HTML renderer.
Displays the breadcrumb as follows:
<ul class="breadcrumb">
<li>
<a href="/">Home</a>
<span class="divider">/</span>
</li>
<li>Other</li>
</ul>
Instance Attribute Summary
Attributes inherited from HTML
Attributes inherited from Base
Instance Method Summary (collapse)
-
- (Object) divider
Public: Returns the divider used to separate crumbs.
-
- (HTMLList) initialize(options = {})
constructor
Public: Initialize an HMTLList renderer.
-
- (Object) item(crumb, active = false)
Public: Returns a rendered breadcrumb item.
-
- (Object) link(crumb, active = false)
Public: Returns a Crumb link.
-
- (Object) list(crumbs)
Public: Defines the breadcrumb container.
Methods inherited from HTML
Methods inherited from Base
Constructor Details
- (HTMLList) initialize(options = {})
Public: Initialize an HMTLList renderer.
options - A Hash containing options for the renderer (default: {}):
:active_class - The String class used for active Crumb when
rendered as a link (default: 'active').
:divider - The String divider used to separate crumbs
(default: HTMLList#divider).
:item_class - A String class used for each breadcrumb item
(default: nil).
:link_active - A Boolean telling if the active Crumb should
be rendered as a link (default: false).
:link_class - The String html class for each link
(default: nil).
:list_class - The String html class used for the crumbs list
container (default: 'breadcrumb').
:list_id - The String html id used for the crumbs list
container (default: nil).
36 37 38 39 40 41 42 |
# File 'lib/ariane/render/html_list.rb', line 36 def initialize(={}) = { item_class: nil }.merge() super() end |
Instance Method Details
- (Object) divider
Public: Returns the divider used to separate crumbs.
Examples
htmllist.divider
# => "<span class=\"divider\">/</span>"
Returns the String representing the html divider.
135 136 137 |
# File 'lib/ariane/render/html_list.rb', line 135 def divider content_tag(:span, '/', class: 'divider') end |
- (Object) item(crumb, active = false)
Public: Returns a rendered breadcrumb item.
Appends the divider unless active is true.
crumb - The Crumb item to be rendered. active - A Boolean indicating if the Crumb is active or not
(default: false).
Examples
htmllist.item(crumb)
# => "<li><a href=\"/\">Home</a><span class=\"divider\">/</span></li>"
# If the :item_class options is set to 'crumb':
htmllist.item(crumb)
# => "<li class=\"crumb\"> ... </li>"
htmllist.item(crumb, true)
# => "<li>Home</li>"
htmllist.item(crumb, true)
# => "<li class=\"active\">Home</li>"
Returns an hmtl safe String representing a rendered Crumb item.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ariane/render/html_list.rb', line 86 def item(crumb, active=false) classes = [:item_class] if active && [:active_class] classes ||= '' classes << [:active_class] end content_tag(:li, class: classes) do out = link(crumb, active) out << [:divider] if [:divider] && !active out end end |
- (Object) link(crumb, active = false)
Public: Returns a Crumb link.
crumb - The Crumb item to be rendered. active - A Boolean indicating if the Crumb is active or not
(default: false).
Examples
htmllist.link(crumb)
# => "<a href=\"/\">Home</a>"
# If the :link_active option is false:
htmllist.link(crumb, true)
# => "Home"
Returns an html safe String representing the link for the Crumb item.
117 118 119 120 121 122 123 124 125 |
# File 'lib/ariane/render/html_list.rb', line 117 def link(crumb, active=false) link_active = !active || [:link_active] if crumb.url && link_active link = link_to crumb.text, crumb.url, class: [:link_class] else link = crumb.text end link.html_safe end |
- (Object) list(crumbs)
Public: Defines the breadcrumb container.
crumbs - An Array containing a list of Crumb objects composing the
breadcrumb.
Examples
htmllist.list(crumbs)
# => "<ul class=\"breadcrumb\"> ... </ul>"
# The String returned cannot be considered as html safe.
Returns a non html safe String representing the breadcrumb.
56 57 58 59 60 |
# File 'lib/ariane/render/html_list.rb', line 56 def list(crumbs) content_tag(:ul, id: [:list_id], class: [:list_class]) do raw items(crumbs) end end |