Permalink
Browse files

Merge pull request #100 from rodrigomanhaes/preceding_text

Add support to prepend text to breadcrumbs (prefix)
  • Loading branch information...
2 parents d9e744c + acb6ca1 commit e12296945e8bf22a7c947a110d6c024af4c7087c @andi andi committed Aug 18, 2012
@@ -11,7 +11,10 @@ module Renderer
class Breadcrumbs < SimpleNavigation::Renderer::Base
def render(item_container)
- content_tag(:div, a_tags(item_container).join(join_with), {:id => item_container.dom_id, :class => item_container.dom_class})
+ content = a_tags(item_container).join(join_with)
+ content_tag(:div,
+ prefix_for(content) + content,
+ {:id => item_container.dom_id, :class => item_container.dom_class})
end
protected
@@ -36,6 +39,10 @@ def suppress_link?(item)
super || (options[:static_leaf] && item.active_leaf_class)
end
+ def prefix_for(content)
+ content.empty? ? '' : options[:prefix] || ''
+ end
+
# Extracts the options relevant for the generated link
#
def link_options_for(item)
@@ -23,7 +23,7 @@ def render(current_nav=nil, options={:level => :all})
it "the rendered div-tag should have the specified class" do
HTML::Selector.new('div.nav_dom_class').select(render).should have(1).entries
end
-
+
context 'without current_navigation set' do
it "should not render any a-tag in the div-tag" do
HTML::Selector.new('div a').select(render).should have(0).entries
@@ -59,6 +59,22 @@ def render(current_nav=nil, options={:level => :all})
end
end
+ context 'with prefix option' do
+ it 'should render prefix before breadcrumbs' do
+ selection = HTML::Selector.new('div').select(render(:subnav1, :level => :all, :prefix => 'You are here: '))
+ raise unless selection.count == 1
+ tag = selection.first
+ tag.to_s.should =~ /^\<div.+\>You are here\: /
+ end
+
+ it 'should not render prefix if there is no available breadcrumb' do
+ allow_message_expectations_on_nil
+ selection = HTML::Selector.new('div').select(render('', :prefix => 'You are here: '))
+ tag = selection.first
+ tag.to_s.should =~ /^\<div.+\>\<\/div\>/
+ end
+ end
+
context 'with static_leaf option' do
before(:each) do
@selection = HTML::Selector.new('div *').select(render(:subnav1, :level => :all, :static_leaf => true))

0 comments on commit e122969

Please sign in to comment.