simple_navigation_renderers 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 75c2d6062eed56d76c167e010f5b7aed27febb81
4
+ data.tar.gz: a33a8834eab2ee4956a7085b9866c8ce1731ae34
5
+ SHA512:
6
+ metadata.gz: 6294b0a57fb7f3d55845674ea6cf1e956be576a6ba4c275b07918355af5e39f92644e18630df4cf37125f4770ef05ce83e8d037ad641a527220dfaa84c1d8da1
7
+ data.tar.gz: 58c7f34eac95c85d521db3bb89000155907c3445771a68bb71c0a892e153923174f53214a462258dba29312e9f48b78a17b552146cb4e44dca4d7d00943a05b0
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ doc/
5
+ pkg
6
+ rdoc
7
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color -f d
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ruby-2.0.0-p247@simple_navigation_renderers
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## v0.0.1
2
+
3
+ * Bootstrap 2 and Bootstrap 3 renderers
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple_navigation_renderers.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Pavel Shpak
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,187 @@
1
+ # SimpleNavigationRenderers
2
+
3
+ This gem adds several [Simple Navigation](https://github.com/andi/simple-navigation) renderers.
4
+ For now, it is include renderers for:
5
+ * [Bootstrap 2 navigation](http://getbootstrap.com/components/#navbar)
6
+ * [Bootstrap 3 navigation](http://getbootstrap.com/2.3.2/components.html#navbar)
7
+
8
+ With these renderers you can create any bootstrap navigation elements, such as: submenus, dividers, headers. As well as add icons to menu elements, such as: gliphicons, font-awesome icons, even custom icons.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'simple_navigation_renderers'
16
+ ```
17
+
18
+ and then execute:
19
+
20
+ ```console
21
+ $ bundle
22
+ ```
23
+
24
+ Or install it yourself as:
25
+
26
+ ```console
27
+ $ gem install simple_navigation_renderers
28
+ ```
29
+
30
+
31
+ ## Usage
32
+
33
+ ### Set up renderer
34
+
35
+ There are two ways to say that you want to use any of renderers.
36
+
37
+ 1. You can specify it in you view as a parameter to `render_navigation`:
38
+
39
+ ```erb
40
+ <nav class="navbar navbar-default navbar-fixed-top" role="navigation">
41
+ <div class="container">
42
+ <div class="navbar-header">
43
+ <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
44
+ <span class="sr-only">Toggle navigation</span>
45
+ <span class="icon-bar"></span>
46
+ <span class="icon-bar"></span>
47
+ <span class="icon-bar"></span>
48
+ </button>
49
+ <%= link_to "Name", root_path, class: "navbar-brand" %>
50
+ </div>
51
+ <div class="collapse navbar-collapse navbar-ex1-collapse">
52
+
53
+ <%= render_navigation( expand_all: true, renderer: :bootstrap3 ) %>
54
+
55
+ </div>
56
+ </div>
57
+ </nav>
58
+ ```
59
+
60
+ 2. Or you can set it in the very navigation configuration file (e.g. `config/navigation.rb`):
61
+
62
+ ```ruby
63
+ SimpleNavigation::Configuration.run do |navigation|
64
+ navigation.renderer = SimpleNavigationRenderers::Bootstrap2
65
+ # navigation itself goes here...
66
+ end
67
+ ```
68
+
69
+ ### Define navigation items
70
+
71
+ I think you already using `simple-navigation` gem and know how to define navigation items.
72
+ If not, you can always look at the [configuration instructions](https://github.com/andi/simple-navigation/wiki/Configuration) on the Simple Navigation wiki or read comments and examples in the generated by default `config/navigation.rb` file.
73
+
74
+ In addition to standard options you can use ones specific for Bootstrap renderers.
75
+ Lets look at the example:
76
+
77
+ ```ruby
78
+ SimpleNavigation::Configuration.run do |navigation|
79
+ navigation.renderer = SimpleNavigationRenderers::Bootstrap3
80
+ navigation.items do |primary|
81
+ primary.item :news, {icon: "fa fa-fw fa-bullhorn", text: "News"}, news_index_path, highlights_on: :subpath
82
+ primary.item :concerts, "Concerts", concerts_path, highlights_on: :subpath
83
+ primary.item :video, "Video", videos_path, highlights_on: :subpath
84
+ primary.item :info, {icon: "fa fa-fw fa-book", title: "Info"}, info_index_path, divider: true, split: true, highlights_on: :subpath do |info_nav|
85
+ info_nav.item :main_info_page, "Main info page", info_path(:main_info_page)
86
+ info_nav.item :about_info_page, "About", info_path(:about_info_page)
87
+ info_nav.item :misc_info_pages, "Misc.", divider: true do |misc_page|
88
+ misc_page.item :header_misc_pages, "Misc. Pages", header: true
89
+ Info.all.each do |info_page|
90
+ misc_page.item :"#{info_page.permalink}", info_page.title, info_path(info_page)
91
+ end
92
+ end
93
+ info_nav.item :contact_info_page, "Contact", info_path(:contact_info_page), divider: true
94
+ end
95
+ end
96
+ end
97
+ ```
98
+
99
+ Specific options used in the example:
100
+
101
+ * `:split` - Use it to split first level item link with caret. If you add `split: true` option to item, then caret itself will toggle first level submenu and link will have standard behaviour, instead of toggle submenu. You can use `:split` only with first level items, for the rest it will not do anything.
102
+ * `:divider` - Use it to add Bootstrap divider before item. if you add `divider: true` option to first level item, then it will first create addition li-tag with `divider-vertical` Bootstrap 2 class and after that create li-tag for item itself. (You can add `divider-vertical` class to Bootstrap 3 - see below) For the second level item and deeper it will create li-tag with class `divider` (the same in Bootstrap 2 and 3)
103
+ * `:header` - Use it to add Bootstrap menu header. If you add `header: true` option to item, then all parameters, except `:name` and `:divider` option, will be ignored. You can use `:header` only with submenus, for the first level items it will not do anything.
104
+ * `:name hash` - Use it in place of `:name` if you want. Hash can have three keys: `:text`, `:icon` and `:title`, which is only recognized. You can use it together or separatly, but at least one of `:text` and `:icon` parameters should be provided. For example:
105
+ * `{text: "News", icon: "fa fa-fw fa-bullhorn"}` will create Font Awesome icon and add text after it (name of the item)
106
+ * `{icon: "glyphicon glyphicon-book", title: "Info"}` will create Bootstrap icon with title without any text after it
107
+
108
+ #### Caveats
109
+
110
+ 1. Bootstrap 3 has only one level submenu. If you want to use nested submenus as in example above, import `bootstrap2_dropdown_submenu.css.scss` file into your Sass file (e.g. `application.css.scss`) as following:
111
+
112
+ ```scss
113
+ @import "bootstrap2_dropdown_submenu";
114
+ ```
115
+
116
+ 2. Bootstrap 3 has not `divider-vertical` class. If you want to use it as in example above, import `bootstrap2_navbar_divider_vertical.css.scss` file:
117
+
118
+ ```scss
119
+ @import "bootstrap2_navbar_divider_vertical";
120
+ ```
121
+
122
+ 3. You may also want to include following file which changes some first level submenu style:
123
+
124
+ ```scss
125
+ @import "simple_navigation_bootstrap_overrides";
126
+ ```
127
+
128
+ or you can add them all together:
129
+
130
+ ```scss
131
+ @import "simple_navigation_bootstrap";
132
+ ```
133
+
134
+ #### Result
135
+
136
+ Thus, above example will produce something like following code:
137
+
138
+ ```html
139
+ <ul class="nav navbar-nav">
140
+ <li class="active simple-navigation-active-leaf" id="news">
141
+ <a href="/news_index_path"><span class="fa fa-fw fa-bullhorn"></span> News</a>
142
+ </li>
143
+ <li id="concerts"><a href="/concerts_path">Concerts</a></li>
144
+ <li id="video"><a href="/videos_path">Video</a></li>
145
+ <li class="divider-vertical"></li>
146
+ <li class="dropdown-split-left" id="info">
147
+ <a href="/info_index_path"><span class="fa fa-fw fa-book" title="Info"></span></a>
148
+ </li>
149
+ <li class="dropdown dropdown-split-right">
150
+ <a class="dropdown-toggle" data-target="#" data-toggle="dropdown" href="#"><b class="caret"></b></a>
151
+ <ul class="pull-right dropdown-menu">
152
+ <li id="main_info_page"><a href="/info/main_info_page">Main info page</a></li>
153
+ <li id="about_info_page"><a href="/info/about_info_page">About</a></li>
154
+ <li class="divider"></li>
155
+ <li class="dropdown-submenu" id="misc_info_pages">
156
+ <a href="#">Misc.</a>
157
+ <ul class="dropdown-menu">
158
+ <li class="dropdown-header">Misc. Pages</li>
159
+ <li id="page1"><a href="/info/page1">Page1</a></li>
160
+ <li id="page2"><a href="/info/page2">Page2</a></li>
161
+ </ul>
162
+ </li>
163
+ <li class="divider"></li>
164
+ <li id="contact_info_page"><a href="/info/contact_info_page">Contact</a></li>
165
+ </ul>
166
+ </li>
167
+ </ul>
168
+ ```
169
+
170
+
171
+ ## Test
172
+
173
+ Just run following commands:
174
+
175
+ ```console
176
+ $ bundle
177
+ $ rake
178
+ ```
179
+
180
+
181
+ ## Contributing
182
+
183
+ 1. Fork it
184
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
185
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
186
+ 4. Push to the branch (`git push origin my-new-feature`)
187
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,11 @@
1
+ require "simple-navigation"
2
+ require "simple_navigation_renderers/exceptions"
3
+ require "simple_navigation_renderers/bootstrap"
4
+ require "simple_navigation_renderers/engine" if defined? Rails::Engine
5
+ require "simple_navigation_renderers/version"
6
+
7
+ module SimpleNavigationRenderers
8
+ end
9
+
10
+ SimpleNavigation.register_renderer :bootstrap2 => SimpleNavigationRenderers::Bootstrap2
11
+ SimpleNavigation.register_renderer :bootstrap3 => SimpleNavigationRenderers::Bootstrap3
@@ -0,0 +1,107 @@
1
+ module SimpleNavigationRenderers
2
+
3
+ module Bootstrap
4
+
5
+ def render( item_container )
6
+ config_selected_class = SimpleNavigation.config.selected_class
7
+ SimpleNavigation.config.selected_class = "active"
8
+ @config_name_generator = SimpleNavigation.config.name_generator
9
+ SimpleNavigation.config.name_generator = self.method(:name_generator)
10
+
11
+ item_container.dom_class = [ item_container.dom_class,
12
+ (item_container.level == 1) ? "nav#{(options[:bv] == 2) ? '' : ' navbar-nav'}" :
13
+ "dropdown-menu" ].flatten.compact.join(' ')
14
+
15
+ list_content = item_container.items.inject([]) do |list, item|
16
+ li_options = item.html_options
17
+
18
+ if li_options.delete(:divider)
19
+ if (item_container.level != 1)
20
+ list << content_tag(:li, '', {class: "divider"})
21
+ else
22
+ list << content_tag(:li, '', {class: "divider-vertical"})
23
+ end
24
+ end
25
+
26
+ if li_options.delete(:header) && (item_container.level != 1)
27
+ list << content_tag(:li, item.name, { class: ((options[:bv] == 2) ? "nav-header" : "dropdown-header") })
28
+ else
29
+
30
+ link_options = li_options.delete(:link) || {}
31
+ split = li_options.delete(:split)
32
+ li_content = if include_sub_navigation?(item)
33
+ if item_container.level == 1
34
+ if split
35
+ main_li_options = li_options.dup
36
+ main_li_options[:class] = [ main_li_options[:class], "dropdown-split-left" ].flatten.compact.join(' ')
37
+ list << content_tag(:li, simple_link(item, link_options), main_li_options)
38
+ li_options[:id] = nil
39
+ item.sub_navigation.dom_class = [ item.sub_navigation.dom_class, "pull-right" ].flatten.compact.join(' ')
40
+ end
41
+ li_options[:class] = [ li_options[:class], "dropdown", (split ? "dropdown-split-right" : nil) ].flatten.compact.join(' ')
42
+ dropdown_link(item, split, link_options) + render_sub_navigation_for(item)
43
+ else
44
+ li_options[:class] = [ li_options[:class], "dropdown-submenu"].flatten.compact.join(' ')
45
+ simple_link(item, link_options) + render_sub_navigation_for(item)
46
+ end
47
+ else
48
+ simple_link(item, link_options)
49
+ end
50
+ list << content_tag(:li, li_content, li_options)
51
+
52
+ end
53
+ end.join
54
+
55
+ SimpleNavigation.config.selected_class = config_selected_class
56
+ SimpleNavigation.config.name_generator = @config_name_generator
57
+
58
+ (skip_if_empty? && item_container.empty?) ? '' :
59
+ content_tag(:ul, list_content, {id: item_container.dom_id, class: item_container.dom_class})
60
+ end
61
+
62
+
63
+ protected
64
+
65
+ def simple_link( item, link_options )
66
+ link_options[:method] ||= item.method
67
+ link_to(item.name, (item.url || "#"), link_options)
68
+ end
69
+
70
+ def dropdown_link( item, split, link_options )
71
+ link_options = {} if split
72
+ link_options[:class] = [ link_options[:class], "dropdown-toggle" ].flatten.compact.join(' ')
73
+ link_options[:"data-toggle"] = "dropdown"
74
+ link_options[:"data-target"] = "#"
75
+ link = [ (split ? nil : item.name), content_tag(:b, '', class: "caret") ].compact.join(' ')
76
+ link_to(link, "#", link_options)
77
+ end
78
+
79
+ def name_generator( name )
80
+ if name.instance_of?(Hash)
81
+ raise SimpleNavigationRenderers::InvalidHash unless name.keys.include?(:icon) || name.keys.include?(:text)
82
+ [ (name[:icon] ? content_tag(:span, '', {class: name[:icon]}.merge(name[:title] ? {title: name[:title]} : {}) ) : nil), name[:text] ].compact.join(' ')
83
+ else
84
+ @config_name_generator.call(name)
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+
91
+ class Bootstrap2 < SimpleNavigation::Renderer::Base
92
+ include SimpleNavigationRenderers::Bootstrap
93
+
94
+ def initialize( options )
95
+ super( options.merge!({bv: 2}) ) # add bootstrap version option
96
+ end
97
+ end
98
+
99
+ class Bootstrap3 < SimpleNavigation::Renderer::Base
100
+ include SimpleNavigationRenderers::Bootstrap
101
+
102
+ def initialize( options )
103
+ super( options.merge!({bv: 3}) ) # add bootstrap version option
104
+ end
105
+ end
106
+
107
+ end
@@ -0,0 +1,4 @@
1
+ module SimpleNavigationRenderers
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,8 @@
1
+ module SimpleNavigationRenderers
2
+ # Exception raised when you set Hash without both 'text' and 'icon' parameters as Item 'name' parameter
3
+ class InvalidHash < StandardError
4
+ def initialize( msg = "Hash does not contain any of parameters: 'text', 'icon'" )
5
+ super
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleNavigationRenderers
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_navigation_renderers/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simple_navigation_renderers"
8
+ spec.version = SimpleNavigationRenderers::VERSION
9
+ spec.authors = ["Pavel Shpak"]
10
+ spec.email = ["shpakvel@gmail.com"]
11
+ spec.description = %q{simple_navigation_renderers gem adds renderers for Bootstrap 2 and 3. With these renderers you can create any bootstrap navigation elements, such as: submenus, dividers, headers. As well as add icons to menu elements, such as: gliphicons, font-awesome icons, even custom icons. }
12
+ spec.summary = %q{simple_navigation_renderers gem adds renderers for Bootstrap 2 and 3. With these renderers you can create any bootstrap navigation elements, such as: submenus, dividers, headers. As well as add icons to menu elements, such as: gliphicons, font-awesome icons, even custom icons. }
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "simple-navigation", "~> 3.11"
22
+
23
+ spec.add_development_dependency "actionpack"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake"
27
+ end
@@ -0,0 +1,197 @@
1
+ require 'spec_helper'
2
+ require 'html/document' unless defined? HTML::Document
3
+
4
+ describe SimpleNavigationRenderers::Bootstrap do
5
+
6
+ describe '.render' do
7
+
8
+ # 'bv' is bootstrap version
9
+ # 'stub_name' neads to check raising error when invalid 'Item name hash' provided
10
+ def render_result( bv=3, stub_name=false )
11
+ SimpleNavigation::Configuration.instance.renderer = (bv == 3) ? SimpleNavigationRenderers::Bootstrap3 : SimpleNavigationRenderers::Bootstrap2
12
+
13
+ SimpleNavigation.stub(adapter: ( SimpleNavigation::Adapters::Rails.new( double(:context, view_context: ActionView::Base.new) )) )
14
+
15
+ SimpleNavigation::Item.any_instance.stub( selected?: false, selected_by_condition?: false )
16
+ primary_navigation = SimpleNavigation::ItemContainer.new(1)
17
+ fill_in( primary_navigation ) # helper method
18
+ primary_navigation.items.find { |item| item.key == :news }.stub( selected?: true, selected_by_condition?: true )
19
+
20
+ primary_navigation.items[0].instance_variable_set(:@name, {}) if stub_name
21
+
22
+ HTML::Document.new( primary_navigation.render(expand_all: true) ).root
23
+ end
24
+
25
+
26
+
27
+ context "for 'bootstrap3' renderer" do
28
+ it "wraps main menu in ul-tag with 'nav navbar-nav' classes" do
29
+ HTML::Selector.new('ul.nav.navbar-nav').select(render_result).should have(1).entries
30
+ end
31
+ end
32
+
33
+ context "for 'bootstrap2' renderer" do
34
+ it "wraps main menu in ul-tag with 'nav' class" do
35
+ HTML::Selector.new('ul.nav.navbar-nav').select(render_result(2)).should have(0).entries
36
+ HTML::Selector.new('ul.nav').select(render_result(2)).should have(1).entries
37
+ end
38
+ end
39
+
40
+ it "sets up 'active' class on selected items (on li-tags)" do
41
+ HTML::Selector.new('ul.nav.navbar-nav > li.active > a[href="news_index_path"]').select(render_result).should have(1).entries
42
+ end
43
+
44
+ it "wraps submenu in ul-tag 'dropdown-menu' class" do
45
+ HTML::Selector.new('ul > li > ul.dropdown-menu > li > ul.dropdown-menu').select(render_result).should have(1).entries
46
+ end
47
+
48
+ context "for the first level submenu (the second level menu)" do
49
+ it "sets up 'dropdown' class on li-tag which contains that submenu" do
50
+ HTML::Selector.new('ul > li.dropdown').select(render_result).should have(1).entries
51
+ end
52
+
53
+ it "sets up 'dropdown-toggle' class on link-tag which is used for toggle that submenu" do
54
+ HTML::Selector.new('ul > li.dropdown > a.dropdown-toggle').select(render_result).should have(1).entries
55
+ end
56
+
57
+ it "sets up 'data-toggle' attribute to 'dropdown' on link-tag which is used for toggle that submenu" do
58
+ HTML::Selector.new('ul > li.dropdown > a[data-toggle=dropdown]').select(render_result).should have(1).entries
59
+ end
60
+
61
+ it "sets up 'data-target' attribute to '#' on link-tag which is used for toggle that submenu" do
62
+ HTML::Selector.new('ul > li.dropdown > a[data-target=#]').select(render_result).should have(1).entries
63
+ end
64
+
65
+ it "sets up 'href' attribute to '#' on link-tag which is used for toggle that submenu" do
66
+ HTML::Selector.new('ul > li.dropdown > a[href=#]').select(render_result).should have(1).entries
67
+ end
68
+
69
+ it "puts b-tag with 'caret' class in li-tag which contains that submenu" do
70
+ HTML::Selector.new('ul > li.dropdown > a[href=#] > b.caret').select(render_result).should have(1).entries
71
+ end
72
+ end
73
+
74
+ context "for nested submenu (the third level menu and deeper)" do
75
+ it "sets up 'dropdown-submenu' class on li-tag which contains that submenu" do
76
+ HTML::Selector.new('ul > li > ul.dropdown-menu > li.dropdown-submenu').select(render_result).should have(1).entries
77
+ end
78
+ end
79
+
80
+
81
+
82
+ context "when ':split' option provided" do
83
+ context "for the first level item which contains submenu" do
84
+ it "splits item on two li-tags (left and right) and right li-tag will contain the first level submenu (second level menu)" do
85
+ HTML::Selector.new('ul > li.dropdown-split-left + li.dropdown.dropdown-split-right > ul.dropdown-menu').select(render_result).should have(1).entries
86
+ end
87
+
88
+ it "sets up 'pull-right' class on ul-tag which is the submenu" do
89
+ HTML::Selector.new('ul > li > ul.dropdown-menu.pull-right').select(render_result).should have(1).entries
90
+ end
91
+ end
92
+
93
+ context "for the second level item and deeper which contains submenu" do
94
+ it "does not splits item on two li-tags" do
95
+ HTML::Selector.new('ul.dropdown-menu > li.dropdown-split-left + li.dropdown.dropdown-split-right > ul.dropdown-menu').select(render_result).should have(0).entries
96
+ HTML::Selector.new('ul.dropdown-menu > li.dropdown-submenu > ul.dropdown-menu').select(render_result).should have(1).entries
97
+ end
98
+
99
+ it "does not sets up 'pull-right' class on ul-tag which is the submenu" do
100
+ HTML::Selector.new('ul.dropdown-menu > li > ul.dropdown-menu.pull-right').select(render_result).should have(0).entries
101
+ end
102
+ end
103
+
104
+ context "for item which does not contain submenu" do
105
+ it "does not splits item on two li-tags" do
106
+ HTML::Selector.new('ul > li.to_check_split.dropdown-split-left + li.dropdown.dropdown-split-right').select(render_result).should have(0).entries
107
+ HTML::Selector.new('ul > li.to_check_split').select(render_result).should have(1).entries
108
+ end
109
+ end
110
+ end
111
+
112
+
113
+
114
+ context "when ':divider' option provided" do
115
+ context "for the first level item" do
116
+ it "adds li-tag with class 'divider-vertical' before normal li-tag" do
117
+ HTML::Selector.new('ul > li.divider-vertical + li > a[href="info_index_path"]').select(render_result).should have(1).entries
118
+ end
119
+ end
120
+
121
+ context "for the second level item and deeper" do
122
+ it "adds li-tag with class 'divider' before normal li-tag" do
123
+ HTML::Selector.new('ul.dropdown-menu > li.divider + li > a[href="misc_info_pages"]').select(render_result).should have(1).entries
124
+ HTML::Selector.new('ul.dropdown-menu > li.divider + li > a[href="contact_info_page"]').select(render_result).should have(1).entries
125
+ end
126
+ end
127
+ end
128
+
129
+
130
+
131
+ context "when ':header' option provided" do
132
+ context "for the first level item" do
133
+ it "does not set up 'dropdown-header' class on li-tag" do
134
+ HTML::Selector.new('ul.nav.navbar-nav > li.to_check_header.dropdown-header').select(render_result).should have(0).entries
135
+ HTML::Selector.new('ul.nav > li.to_check_header.dropdown-header').select(render_result(2)).should have(0).entries
136
+ end
137
+
138
+ it "creates link-tag for the item (standard item)" do
139
+ HTML::Selector.new('ul.nav.navbar-nav > li.to_check_header > a').select(render_result).should have(1).entries
140
+ HTML::Selector.new('ul.nav > li.to_check_header > a').select(render_result(2)).should have(1).entries
141
+ end
142
+ end
143
+
144
+ context "for the second level item and deeper" do
145
+ context "for 'bootstrap3' renderer" do
146
+ it "sets up 'dropdown-header' class on li-tag" do
147
+ HTML::Selector.new('ul.dropdown-menu > li.dropdown-header').select(render_result).should have(1).entries
148
+ end
149
+ end
150
+
151
+ context "for 'bootstrap2' renderer" do
152
+ it "sets up 'nav-header' class on li-tag" do
153
+ HTML::Selector.new('ul.dropdown-menu > li.nav-header').select(render_result(2)).should have(1).entries
154
+ end
155
+ end
156
+
157
+ it "does not create link-tag for the item (puts only item name as plain text)" do
158
+ HTML::Selector.new('ul.dropdown-menu > li.dropdown-header > a').select(render_result).should have(0).entries
159
+ HTML::Selector.new('ul.dropdown-menu > li.nav-header > a').select(render_result(2)).should have(0).entries
160
+ HTML::Selector.new('ul.dropdown-menu > li.dropdown-header').select(render_result)[0].children[0].to_s.should == "Misc. Pages"
161
+ HTML::Selector.new('ul.dropdown-menu > li.nav-header').select(render_result(2))[0].children[0].to_s.should == "Misc. Pages"
162
+ end
163
+ end
164
+ end
165
+
166
+
167
+
168
+ context "when 'hash' provided in place of 'name'" do
169
+ context "with ':icon' parameter" do
170
+ it "adds span-tag with classes from the parameter" do
171
+ HTML::Selector.new('ul > li > a > span.fa.fa-fw.fa-bullhorn').select(render_result).should have(1).entries
172
+ end
173
+ end
174
+
175
+ context "with ':title' parameter" do
176
+ it "sets up 'title' attribute on icon's span-tag to the parameter value" do
177
+ HTML::Selector.new('ul > li > a > span.fa.fa-fw.fa-book[title="Info"]').select(render_result).should have(1).entries
178
+ end
179
+ end
180
+
181
+ context "with ':text' parameter" do
182
+ it "uses the parameter value as 'name' of the item" do
183
+ HTML::Selector.new('ul > li > a > span.fa.fa-fw.fa-bullhorn').select(render_result)[0].parent.children[1].to_s.should == " News"
184
+ end
185
+ end
186
+
187
+ context "without ':text' and ':icon' parameters" do
188
+ it "raises 'InvalidHash' error" do
189
+ expect {
190
+ render_result(3, true)
191
+ }.to raise_error( SimpleNavigationRenderers::InvalidHash )
192
+ end
193
+ end
194
+ end
195
+
196
+ end
197
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe SimpleNavigationRenderers::InvalidHash do
4
+ it "has specific default message" do
5
+ subject.message.should == "Hash does not contain any of parameters: 'text', 'icon'"
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ require "spec_helper"
2
+
3
+ describe SimpleNavigationRenderers do
4
+ it "register 'bootstrap2' renderer" do
5
+ SimpleNavigation.registered_renderers[:bootstrap2].should == SimpleNavigationRenderers::Bootstrap2
6
+ end
7
+
8
+ it "register 'bootstrap3' renderer" do
9
+ SimpleNavigation.registered_renderers[:bootstrap3].should == SimpleNavigationRenderers::Bootstrap3
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require 'action_controller'
3
+ module Rails
4
+ module VERSION
5
+ MAJOR = 2
6
+ end
7
+ end unless defined? Rails
8
+ RAILS_ROOT = './' unless defined?(RAILS_ROOT)
9
+ RAILS_ENV = 'test' unless defined?(RAILS_ENV)
10
+
11
+ require "simple_navigation_renderers"
12
+
13
+ # helper method
14
+ def fill_in( primary )
15
+ primary.item :news, {icon: "fa fa-fw fa-bullhorn", text: "News"}, "news_index_path"
16
+ primary.item :concerts, "Concerts", "concerts_path", class: "to_check_header", header: true
17
+ primary.item :video, "Video", "videos_path", class: "to_check_split", split: true
18
+ primary.item :info, {icon: "fa fa-fw fa-book", title: "Info"}, "info_index_path", divider: true, split: true do |info_nav|
19
+ info_nav.item :main_info_page, "Main info page", "main_info_page"
20
+ info_nav.item :about_info_page, "About", "about_info_page"
21
+ info_nav.item :misc_info_pages, "Misc.", "misc_info_pages", divider: true, split: true do |misc_nav|
22
+ misc_nav.item :header_misc_pages, "Misc. Pages", header: true
23
+ misc_nav.item :page1, "Page1", "page1"
24
+ misc_nav.item :page2, "Page2", "page2"
25
+ end
26
+ info_nav.item :contact_info_page, "Contact", "contact_info_page", divider: true
27
+ end
28
+ end
@@ -0,0 +1,51 @@
1
+ .dropdown-submenu:hover > a,
2
+ .dropdown-submenu:focus > a {
3
+ text-decoration: none;
4
+ color: $dropdown-link-hover-color;
5
+ @include gradient-vertical($dropdown-link-hover-bg, darken($dropdown-link-hover-bg, 5%));
6
+ }
7
+ // Sub menus
8
+ // ---------------------------
9
+ .dropdown-submenu {
10
+ position: relative;
11
+ }
12
+ // Default dropdowns
13
+ .dropdown-submenu > .dropdown-menu {
14
+ top: 0;
15
+ left: 100%;
16
+ margin-top: -6px;
17
+ margin-left: -1px;
18
+ border-radius: 0 6px 6px 6px;
19
+ }
20
+ .dropdown-submenu:hover > .dropdown-menu {
21
+ display: block;
22
+ }
23
+ // Caret to indicate there is a submenu
24
+ .dropdown-submenu > a:after {
25
+ display: block;
26
+ content: " ";
27
+ float: right;
28
+ width: 0;
29
+ height: 0;
30
+ border-top: $caret-width-base solid transparent;
31
+ border-bottom: $caret-width-base solid transparent;
32
+ border-left: $caret-width-base solid $navbar-default-link-color;
33
+ border-right: 0 dotted;
34
+ margin-top: 5px;
35
+ margin-right: -10px;
36
+ }
37
+ .dropdown-submenu:hover > a:after {
38
+ border-left-color: $dropdown-link-hover-color;
39
+ }
40
+ // Left aligned submenus
41
+ .dropdown-submenu.pull-left {
42
+ // Undo the float
43
+ // Yes, this is awkward since .pull-left adds a float, but it sticks to our conventions elsewhere.
44
+ float: none;
45
+ // Positioning the submenu
46
+ > .dropdown-menu {
47
+ left: -100%;
48
+ margin-left: 10px;
49
+ border-radius: 6px 0 6px 6px;
50
+ }
51
+ }
@@ -0,0 +1,11 @@
1
+ .navbar .divider-vertical {
2
+ height: $navbar-height;
3
+ margin: 0 9px;
4
+ border-left: 1px solid $navbar-default-bg;
5
+ border-right: 1px solid lighten($navbar-default-bg, 5%);;
6
+ }
7
+ // Inverted navbar
8
+ .divider-vertical {
9
+ border-left-color: $navbar-inverse-bg;
10
+ border-right-color: lighten($navbar-inverse-bg, 5%);;
11
+ }
@@ -0,0 +1,4 @@
1
+
2
+ @import "bootstrap2_dropdown_submenu";
3
+ @import "bootstrap2_navbar_divider_vertical";
4
+ @import "simple_navigation_bootstrap_overrides";
@@ -0,0 +1,16 @@
1
+
2
+ // add style for navigation splitted dropdowns
3
+ .navbar .nav > li.dropdown-split-left > a {
4
+ border-right: none;
5
+ }
6
+ .navbar .nav > li.dropdown-split-right > a {
7
+ border-left: none;
8
+ }
9
+
10
+ // correct some style
11
+ .navbar .nav > li > .dropdown-menu.pull-right {
12
+ float: none ! important;
13
+ }
14
+ .navbar .nav > li > a > .caret {
15
+ margin: 0;
16
+ }
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_navigation_renderers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Pavel Shpak
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: simple-navigation
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '3.11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionpack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: 'simple_navigation_renderers gem adds renderers for Bootstrap 2 and 3.
84
+ With these renderers you can create any bootstrap navigation elements, such as:
85
+ submenus, dividers, headers. As well as add icons to menu elements, such as: gliphicons,
86
+ font-awesome icons, even custom icons. '
87
+ email:
88
+ - shpakvel@gmail.com
89
+ executables: []
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - .gitignore
94
+ - .rspec
95
+ - .rvmrc
96
+ - CHANGELOG.md
97
+ - Gemfile
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - lib/simple_navigation_renderers.rb
102
+ - lib/simple_navigation_renderers/bootstrap.rb
103
+ - lib/simple_navigation_renderers/engine.rb
104
+ - lib/simple_navigation_renderers/exceptions.rb
105
+ - lib/simple_navigation_renderers/version.rb
106
+ - simple_navigation_renderers.gemspec
107
+ - spec/lib/simple_navigation_renderers/bootstrap_spec.rb
108
+ - spec/lib/simple_navigation_renderers/exceptions_spec.rb
109
+ - spec/lib/simple_navigation_renderers_spec.rb
110
+ - spec/spec_helper.rb
111
+ - vendor/assets/stylesheets/bootstrap2_dropdown_submenu.css.scss
112
+ - vendor/assets/stylesheets/bootstrap2_navbar_divider_vertical.css.scss
113
+ - vendor/assets/stylesheets/simple_navigation_bootstrap.css.scss
114
+ - vendor/assets/stylesheets/simple_navigation_bootstrap_overrides.css.scss
115
+ homepage: ''
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.1.10
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: 'simple_navigation_renderers gem adds renderers for Bootstrap 2 and 3. With
139
+ these renderers you can create any bootstrap navigation elements, such as: submenus,
140
+ dividers, headers. As well as add icons to menu elements, such as: gliphicons, font-awesome
141
+ icons, even custom icons.'
142
+ test_files:
143
+ - spec/lib/simple_navigation_renderers/bootstrap_spec.rb
144
+ - spec/lib/simple_navigation_renderers/exceptions_spec.rb
145
+ - spec/lib/simple_navigation_renderers_spec.rb
146
+ - spec/spec_helper.rb