Class: Ariane::Render::HTML
- Includes:
- ActionView::Helpers::OutputSafetyHelper, ActionView::Helpers::TagHelper, ActionView::Helpers::UrlHelper
- Defined in:
- lib/ariane/render/html.rb
Overview
Public: HTML renderer.
Displays the breadcrumb as follows:
<p class="breadcrumb">
<a href="/">Home</a> / Other
</p>
Direct Known Subclasses
Instance Attribute Summary collapse
-
#output_buffer ⇒ Object
Public: Gets/Sets the String output_buffer.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ HTML
constructor
Public: Initialize an HTML renderer.
-
#item(crumb, active = false) ⇒ Object
Public: Returns a rendered breadcrumb item.
-
#items(crumbs) ⇒ Object
Public: Returns the rendered list of breadcrumb items.
-
#link(crumb, active = false) ⇒ Object
Public: Returns a Crumb link.
-
#list(crumbs) ⇒ Object
Public: Defines the breadcrumb container.
-
#render(crumbs) ⇒ Object
Public: Renders the breadcrumb.
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ HTML
Public: Initialize an HTML 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: Base#divider).
: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).
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ariane/render/html.rb', line 38 def initialize(={}) = { active_class: 'active', link_active: false, link_class: nil, list_class: 'breadcrumb', list_id: nil }.merge() super() end |
Instance Attribute Details
#output_buffer ⇒ Object
Public: Gets/Sets the String output_buffer.
21 22 23 |
# File 'lib/ariane/render/html.rb', line 21 def output_buffer @output_buffer end |
Instance Method Details
#item(crumb, active = false) ⇒ Object
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
html.item(crumb)
# => "<a href=\"/\">Home</a> /"
html.item(crumb, true)
# => "Home"
Returns an hmtl safe String representing a rendered Crumb item.
120 121 122 123 124 |
# File 'lib/ariane/render/html.rb', line 120 def item(crumb, active=false) out = link(crumb, active) out << [:divider] if [:divider] && !active out end |
#items(crumbs) ⇒ Object
Public: Returns the rendered list of breadcrumb items.
crumbs - An Array containing a list of Crumb objects composing the
.
Examples
html.items(crumbs)
# => "<a href=\"/\">Home</a> / Other"
# The String returned cannot be considered as html safe.
Returns a non html safe String representing the breadcrumb items.
95 96 97 98 99 100 101 |
# File 'lib/ariane/render/html.rb', line 95 def items(crumbs) crumbs.inject('') do |out, crumb| active = crumb == crumbs.last out << item(crumb, active) out end end |
#link(crumb, active = false) ⇒ Object
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
html.link(crumb)
# => "<a href=\"/\">Home</a>"
# If the :link_active option is false:
html.link(crumb, true)
# => "Home"
# If the :link_active option is true and
# the :link_class option is set to 'active':
html.link(crumb, true)
# => "<a href=\"/\" class=\"active\">Home</a>"
Returns an html safe String representing the link for the Crumb item.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/ariane/render/html.rb', line 147 def link(crumb, active=false) classes = [:link_class] if active && [:active_class] classes ||= '' classes << [:active_class] end link_active = !active || [:link_active] if crumb.url && link_active link = link_to crumb.text, crumb.url, class: classes else link = crumb.text end link.html_safe end |
#list(crumbs) ⇒ Object
Public: Defines the breadcrumb container.
crumbs - An Array containing a list of Crumb objects composing the
.
Examples
html.list(crumbs)
# => "<p class=\"breadcrumb\"> ... </p>"
# The String returned cannot be considered as html safe.
Returns a non html safe String representing the breadcrumb.
77 78 79 80 81 |
# File 'lib/ariane/render/html.rb', line 77 def list(crumbs) content_tag(:p, id: [:list_id], class: [:list_class]) do raw items(crumbs) end end |
#render(crumbs) ⇒ Object
Public: Renders the breadcrumb.
crumbs - An Array containing a list of Crumb objects composing the
.
Examples
html.render(crumbs)
# => "<p class=\"breadcrumb\"><a href=\"/\">Home</a> / Other</p>"
Returns an html safe String representing the breadcrumb to print.
61 62 63 |
# File 'lib/ariane/render/html.rb', line 61 def render(crumbs) list(crumbs).html_safe end |