Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

another implementation about breadcrumb in bootstrap #8

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Example to configurate for Ace layout Nav List (bootstrap) by me

```ruby
primary.item :dashboard, {icon: "menu-icon menu-icon fa fa-desktop", text: t(:dashboard, scope: 'navigate')}, dashboard_path
primary.item :ledgers, {icon: "menu-icon glyphicon glyphicon-plus", text: t(:ledgers, scope: 'navigate')} do |ledger|
ledger.item :credits, {icon: "menu-icon fa fa-caret-right", text: t(:credits, scope: 'navigate')}, ledgers_path(ledger: 'credits')
ledger.item :debits, {icon: "menu-icon fa fa-caret-right", text: t(:debits, scope: 'navigate')}, ledgers_path(ledger: 'debits')
ledger.item :store_debits, {icon: "menu-icon fa fa-caret-right", text: t(:store_debits, scope: 'navigate')}, ledgers_path(ledger: 'store_debits')
end
```

### Default readme by developer

# SimpleNavigationRenderers

[![Gem Version](https://badge.fury.io/rb/simple_navigation_renderers.png)](http://badge.fury.io/rb/simple_navigation_renderers)
Expand Down
2 changes: 2 additions & 0 deletions lib/simple_navigation_renderers.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "simple-navigation"
require "simple_navigation_renderers/exceptions"
require "simple_navigation_renderers/bootstrap"
require "simple_navigation_renderers/bootstrap_breadcrumb"
require "simple_navigation_renderers/engine" if defined? Rails::Engine
require "simple_navigation_renderers/version"

Expand All @@ -9,3 +10,4 @@ module SimpleNavigationRenderers

SimpleNavigation.register_renderer( bootstrap2: SimpleNavigationRenderers::Bootstrap2 )
SimpleNavigation.register_renderer( bootstrap3: SimpleNavigationRenderers::Bootstrap3 )
SimpleNavigation.register_renderer( breadcrumb3: SimpleNavigationRenderers::BootstrapBreadcrumbs )
10 changes: 6 additions & 4 deletions lib/simple_navigation_renderers/bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ def render( item_container )

def container_class( level )
if level == 1
"nav" + ((options[:bv] == 3) ? ' navbar-nav' : '')
"nav" + ((options[:bv] == 3) ? ' nav-list' : '')
else
"dropdown-menu"
"submenu can-scroll"
end
end

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"
sn_config.selected_class = "active hover"
# 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 )
Expand All @@ -51,7 +51,9 @@ 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] || '')
# content_tag(:span, '', icon_options) + ' ' + (name[:text] || '')
content_tag(:i, '', icon_options) +
content_tag(:span, (name[:text] || ''))
else
name[:text] || (raise SimpleNavigationRenderers::InvalidHash)
end
Expand Down
35 changes: 35 additions & 0 deletions lib/simple_navigation_renderers/bootstrap_breadcrumb.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module SimpleNavigationRenderers
class BootstrapBreadcrumbs < SimpleNavigation::Renderer::Base
def render(item_container)

content_tag :ul, li_tags(item_container).join(join_with), {
id: item_container.dom_id,
class: "#{item_container.dom_class} breadcrumb"
}
end

protected

def li_tags(item_container)
item_container.items.each_with_object([]) do |item, list|
next unless item.selected?

if include_sub_navigation?(item)
options = { method: item.method }.merge(item.html_options.except(:class, :id))
list << unless item.url
content_tag(:li, item.name[:text])
else
content_tag(:li, link_to(item.name[:text], item.url), options)
end
list.concat li_tags(item.sub_navigation)
else
list << content_tag(:li, item.name[:text], { class: 'active' })
end
end
end

def join_with
@join_with ||= options[:join_with] ? ("<span class='divider'>"+ options[:join_with] +"</span>").html_safe : ''
end
end
end
13 changes: 7 additions & 6 deletions lib/simple_navigation_renderers/rendered_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def li_link
content_tag(:li, dropdown_submenu_link, options)
end
else
content_tag(:li, simple_link, options)
content_tag(:li, simple_link, options.include?(:class) ? options : options.merge(class: 'hover'))
end
end

Expand All @@ -84,17 +84,18 @@ def splitted_dropdown_part
end

def dropdown_part( name )
options[:class] = [ options[:class], "dropdown" ].flatten.compact.join(' ')
options[:class] = [ options[:class], "hsub hover" ].flatten.compact.join(' ')
# options[:class] = [ options[:class], "dropdown dropdown-hover" ].flatten.compact.join(' ')
link_options[:class] = [ link_options[:class], "dropdown-toggle" ].flatten.compact.join(' ')
link_options[:"data-toggle"] = "dropdown"
link_options[:"data-target"] = "#"

content = link_to( name, "#", link_options ) + render_sub_navigation_for(item)
content = link_to( name.html_safe, "#", link_options ) + render_sub_navigation_for(item)
content_tag(:li, content, options)
end

def caret
content_tag(:b, '', class: "caret")
content_tag(:span, '', class: "caret")
end

def dropdown_submenu_link
Expand All @@ -109,4 +110,4 @@ def simple_link

end

end
end