simple-navigation-bootstrap 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in simple-navigation-bootstrap.gemspec
4
+ gemspec
@@ -0,0 +1,44 @@
1
+ == Simple Navigation for Bootstrap
2
+ This gem adds a renderer for {Simple Navigation}[http://github.com/andi/simple-navigation] to output markup compatible
3
+ with {Twitter Bootstrap}[http://twitter.github.com/bootstrap/].
4
+
5
+ == Getting Started
6
+ For Rails >= 3, simply add this gem to your <tt>Gemfile</tt>:
7
+ gem 'simple-navigation-bootstrap'
8
+ and run
9
+ bundle install
10
+ Follow the {configuration instructions}[https://github.com/andi/simple-navigation/wiki/Configuration] on the Simple Navigation wiki for initial configuration.
11
+
12
+ To use the Bootstrap renderer, specify it in your view:
13
+ render_navigation :expand_all => true, :renderer => :bootstrap
14
+
15
+ == Additional Functionality
16
+ In addition to generating Bootstrap-comptible list markup, you may specify
17
+ an <tt>:icon</tt> attribute on your navigation items, either as an array
18
+ or string, containing Bootstrap {icon classes}[http://twitter.github.com/bootstrap/base-css.html#icons], to add an icon to the item.
19
+
20
+ == Examples
21
+ To create a navigation menu, you might do something like this:
22
+ SimpleNavigation::Configuration.run do |navigation|
23
+ navigation.items do |primary|
24
+ primary.item :music, 'Music', musics_path
25
+ primary.item :dvds, 'Dvds', dvds_path
26
+ primary.item :books, 'Books', :icon => [:icon-book, :icon-white] do |books|
27
+ books.item :fiction, 'Fiction', books_fiction_path
28
+ books.item :history, 'History', books_history_path
29
+ end
30
+ primary.dom_class = 'nav'
31
+ end
32
+ end
33
+
34
+ == Caveats
35
+ Because Bootstrap only supports dropdown on-click, items with sub-navigation
36
+ may not contain links - any links will be overwritten with a <tt>#</tt> anchor.
37
+
38
+ == Further Reading
39
+ * {Twitter Bootstrap Documentation}[http://twitter.github.com/bootstrap/]
40
+ * {Simple Navigation Wiki}[https://github.com/andi/simple-navigation/wiki/]
41
+
42
+ == TODO
43
+ So far, only nav markup and dropdowns are supported, may also implement
44
+ buttons and nav lists in the future.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ require "simple-navigation"
2
+ require "simple_navigation/rendering/renderer/bootstrap"
3
+ require "simple-navigation-bootstrap/version"
4
+ SimpleNavigation.register_renderer :bootstrap => SimpleNavigation::Renderer::Bootstrap
@@ -0,0 +1,3 @@
1
+ module SimpleNavigationBootstrap
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,47 @@
1
+ module SimpleNavigation
2
+ module Renderer
3
+ class Bootstrap < SimpleNavigation::Renderer::Base
4
+ def render(item_container)
5
+ config_selected_class = SimpleNavigation.config.selected_class
6
+ SimpleNavigation.config.selected_class = 'active'
7
+ list_content = item_container.items.inject([]) do |list, item|
8
+ li_options = item.html_options.reject {|k, v| k == :link}
9
+ li_content = tag_for(item, li_options.delete(:icon))
10
+ if include_sub_navigation?(item)
11
+ item.sub_navigation.dom_class = [item.sub_navigation.dom_class, 'dropdown-menu'].flatten.compact.join(' ')
12
+ li_content << render_sub_navigation_for(item)
13
+ li_options[:class] = [li_options[:class], 'dropdown'].flatten.compact.join(' ')
14
+ end
15
+ list << content_tag(:li, li_content, li_options)
16
+ end.join
17
+ SimpleNavigation.config.selected_class = config_selected_class
18
+ if skip_if_empty? && item_container.empty?
19
+ ''
20
+ else
21
+ content_tag(:ul, list_content, {:id => item_container.dom_id, :class => item_container.dom_class})
22
+ end
23
+ end
24
+
25
+ protected
26
+
27
+ def tag_for(item, icon = nil)
28
+ url = item.url
29
+ link = Array.new
30
+ link << content_tag(:i, '', :class => [icon].flatten.compact.join(' ')) unless icon.nil?
31
+ link << item.name
32
+ if include_sub_navigation?(item)
33
+ url = '#'
34
+ item_options = item.html_options
35
+ item_options[:link] = Hash.new if item_options[:link].nil?
36
+ item_options[:link][:data] = Hash.new if item_options[:link][:data].nil?
37
+ item_options[:link][:class] = Array.new if item_options[:link][:class].nil?
38
+ item_options[:link][:class] << 'dropdown-toggle'
39
+ item_options[:link][:data][:toggle] = 'dropdown'
40
+ item.html_options = item_options
41
+ link << content_tag(:b, '', :class => 'caret')
42
+ end
43
+ link_to(link.join(" "), url, options_for(item))
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "simple-navigation-bootstrap/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "simple-navigation-bootstrap"
7
+ s.version = SimpleNavigationBootstrap::VERSION
8
+ s.authors = ["Peter Fern"]
9
+ s.email = ["github@obfusc8.org"]
10
+ s.homepage = "https://github.com/pdf/simple-navigation-bootstrap"
11
+ s.summary = %q{simple-navigation-bootstrap is a simple-navigation renderer for twitter-bootstrap navigation and dropdowns.}
12
+ s.description = %q{simple-navigation-bootstrap is a simple-navigation renderer for twitter-bootstrap navigation and dropdowns.}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+ s.extra_rdoc_files = ["README.rdoc"]
19
+
20
+ # specify any dependencies here; for example:
21
+ s.add_development_dependency "rake"
22
+ s.add_runtime_dependency "simple-navigation", ">= 3.7.0"
23
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple-navigation-bootstrap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Peter Fern
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &6568100 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *6568100
25
+ - !ruby/object:Gem::Dependency
26
+ name: simple-navigation
27
+ requirement: &6566040 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 3.7.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *6566040
36
+ description: simple-navigation-bootstrap is a simple-navigation renderer for twitter-bootstrap
37
+ navigation and dropdowns.
38
+ email:
39
+ - github@obfusc8.org
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files:
43
+ - README.rdoc
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
47
+ - README.rdoc
48
+ - Rakefile
49
+ - lib/simple-navigation-bootstrap.rb
50
+ - lib/simple-navigation-bootstrap/version.rb
51
+ - lib/simple_navigation/rendering/renderer/bootstrap.rb
52
+ - simple-navigation-bootstrap.gemspec
53
+ homepage: https://github.com/pdf/simple-navigation-bootstrap
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ segments:
66
+ - 0
67
+ hash: 1341464271989467196
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ segments:
75
+ - 0
76
+ hash: 1341464271989467196
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.10
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: simple-navigation-bootstrap is a simple-navigation renderer for twitter-bootstrap
83
+ navigation and dropdowns.
84
+ test_files: []