Class: Crumpet::Renderer
- Inherits:
-
Object
- Object
- Crumpet::Renderer
- Includes:
- ActionView::Helpers::UrlHelper, ERB::Util
- Defined in:
- lib/crumpet/renderer.rb
Instance Attribute Summary collapse
-
#crumbs ⇒ Object
readonly
Returns the value of attribute crumbs.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(crumbs, options = {}) ⇒ Renderer
constructor
A new instance of Renderer.
- #render ⇒ Object
Constructor Details
#initialize(crumbs, options = {}) ⇒ Renderer
Returns a new instance of Renderer.
12 13 14 15 |
# File 'lib/crumpet/renderer.rb', line 12 def initialize(crumbs, = {}) @crumbs = crumbs @options = end |
Instance Attribute Details
#crumbs ⇒ Object (readonly)
Returns the value of attribute crumbs.
6 7 8 |
# File 'lib/crumpet/renderer.rb', line 6 def crumbs @crumbs end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/crumpet/renderer.rb', line 6 def @options end |
Class Method Details
.render(crumbs, options = {}) ⇒ Object
8 9 10 |
# File 'lib/crumpet/renderer.rb', line 8 def self.render(crumbs, = {}) new(crumbs, ).render end |
Instance Method Details
#render ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/crumpet/renderer.rb', line 17 def render return '' if crumbs.empty? && !option_or_default(:render_when_blank) case option_or_default(:format) when :html output = crumbs.map{ |crumb| render_html(crumb) }.join(option_or_default(:separator)).html_safe output = content_tag(option_or_default(:container).to_sym, output, ) if option_or_default(:container).present? output when :xml output = crumbs.map{ |crumb| render_xml(crumb) }.join output = content_tag(:crumbs, output) output when :json crumbs.map{ |crumb| render_json(crumb) }.to_json else raise NotImplementedError, "unsupported format: #{option_or_default(:format)}" end end |