module SimpleNavigationRenderers::Bootstrap

Public Instance Methods

render( item_container ) click to toggle source
# File lib/simple_navigation_renderers/bootstrap.rb, line 7
def render( item_container )
  if skip_if_empty? && item_container.empty?
    ''
  else
    list_content = with_bootstrap_configs do
      item_container.items.inject([]) do |list, item|
        list << SimpleNavigationRenderers::RenderedItem.new( self, item, item_container.level, options[:bv] ).to_s
      end.join
    end
    item_container.dom_class = [ item_container.dom_class, container_class(item_container.level) ].flatten.compact.join(' ')
    content_tag(:ul, list_content, {id: item_container.dom_id, class: item_container.dom_class})
  end
end

Private Instance Methods

container_class( level ) click to toggle source
# File lib/simple_navigation_renderers/bootstrap.rb, line 24
def container_class( level )
  if level == 1
    "nav" + ((options[:bv] == 3) ? ' navbar-nav' : '')
  else
    "dropdown-menu"
  end
end
prepare_name( name ) click to toggle source
# File lib/simple_navigation_renderers/bootstrap.rb, line 50
def prepare_name( name )
  if name.instance_of?(Hash)
    if name[:icon]
      icon_options = {class: name[:icon], title: name[:title]}.reject { |_, v| v.nil? }
      content_tag(:span, '', icon_options) + ' ' + (name[:text] || '')
    else
      name[:text] || (raise SimpleNavigationRenderers::InvalidHash)
    end
  else
    name
  end
end
with_bootstrap_configs() { || ... } click to toggle source
# File lib/simple_navigation_renderers/bootstrap.rb, line 32
def with_bootstrap_configs
  sn_config = SimpleNavigation.config
  config_selected_class = sn_config.selected_class
  config_name_generator = sn_config.name_generator
  sn_config.selected_class = "active"
  # name_generator should be proc (not lambda or method) to be compatible with earlier versions of simple-navigation
  sn_config.name_generator = proc do | name, item |
    config_name_generator.call( prepare_name(name), item )
  end

  result = yield

  sn_config.name_generator = config_name_generator
  sn_config.selected_class = config_selected_class

  result
end