simple_navigation_renderers 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3b1c37c5e0b2ef981172bbf81dc7c32a6a5a949
4
- data.tar.gz: 3ad07a991af0a78262e0f7a26b390b2fa3522630
3
+ metadata.gz: 7276bc421ed996e92fba1beaa61417df42c5a5dd
4
+ data.tar.gz: 59e906ca0a02541ab03496dc57c9d35de21b8901
5
5
  SHA512:
6
- metadata.gz: 8cc6a6757952d15c52a0adea721363ac9a75b653261964a600c8fcadec6eee7feb731ecff1c4e45c516e1a7960de0a7758113994a75aadce0b8576da1bdf9048
7
- data.tar.gz: 33908fadd6c3336692d7ee2d5c07182a21b8e8668c22c20ccdc387b5b122728015875481294d2532adf03e223fca7508d9a8babdd9b0a32388af386a8d269572
6
+ metadata.gz: 50ce8afe6ff9a59e02fb0a115dad076a6cc048142b6d888f9dbc71ef554c364bb10f5cafeb23e3373a51b0d4108f731748c569dc7bb8075c151551574b21479a
7
+ data.tar.gz: 0dd816e533d28ba476f3535f9a81120440461f73fb76fe0c460ac4a0166c103b260195b6846f204c08a9635b35ad16b656b4aa1effbb00705484f1d7716c77ff
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  *.gem
2
2
  .bundle
3
+ coverage
3
4
  Gemfile.lock
4
5
  doc/
5
6
  pkg
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - "2.1.1"
4
+ - "2.1.0"
3
5
  - "2.0.0"
4
6
  - "1.9.3"
@@ -1,3 +1,10 @@
1
+ ## v1.0.2
2
+
3
+ * fix README
4
+ * add Code Climate, Coveralls and Gemnasium
5
+ * refactor rendering
6
+
7
+
1
8
  ## v1.0.1
2
9
 
3
10
  * fix problem with `name_generator` method (appeared after `simple-navigation` changes)
data/README.md CHANGED
@@ -1,9 +1,15 @@
1
- # SimpleNavigationRenderers [![Build Status](https://travis-ci.org/ShPakvel/simple_navigation_renderers.png?branch=master)](https://travis-ci.org/ShPakvel/simple_navigation_renderers)
1
+ # SimpleNavigationRenderers
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/simple_navigation_renderers.png)](http://badge.fury.io/rb/simple_navigation_renderers)
4
+ [![Build Status](https://travis-ci.org/ShPakvel/simple_navigation_renderers.png?branch=master)](https://travis-ci.org/ShPakvel/simple_navigation_renderers)
5
+ [![Code Climate](https://codeclimate.com/github/ShPakvel/simple_navigation_renderers.png)](https://codeclimate.com/github/ShPakvel/simple_navigation_renderers)
6
+ [![Coverage Status](https://coveralls.io/repos/ShPakvel/simple_navigation_renderers/badge.png)](https://coveralls.io/r/ShPakvel/simple_navigation_renderers)
7
+ [![Dependency Status](https://gemnasium.com/ShPakvel/simple_navigation_renderers.png)](https://gemnasium.com/ShPakvel/simple_navigation_renderers)
2
8
 
3
9
  This gem adds several [Simple Navigation](https://github.com/andi/simple-navigation) renderers.
4
10
  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)
11
+ * [Bootstrap 2 navigation](http://getbootstrap.com/2.3.2/components.html#navbar)
12
+ * [Bootstrap 3 navigation](http://getbootstrap.com/components/#navbar)
7
13
 
8
14
  With these renderers you will be able create **any bootstrap navigation elements**, such as: **submenu**, **navbar-text**, **divider**, **header**. As well as add **icons** to menu elements, such as: gliphicons, font-awesome icons, even custom icons. Also you have **split** option for main menu containing submenu.
9
15
 
@@ -176,3 +182,8 @@ $ rake
176
182
  3. Commit your changes (`git commit -am 'Add some feature'`)
177
183
  4. Push to the branch (`git push origin my-new-feature`)
178
184
  5. Create new Pull Request
185
+
186
+
187
+ ## MIT License
188
+
189
+ See the file LICENSE.txt for copying permission.
@@ -1,114 +1,65 @@
1
+ require "simple_navigation_renderers/rendered_item"
2
+
1
3
  module SimpleNavigationRenderers
2
4
 
3
5
  module Bootstrap
4
6
 
5
7
  def render( item_container )
6
- if (skip_if_empty? && item_container.empty?)
8
+ if skip_if_empty? && item_container.empty?
7
9
  ''
8
10
  else
9
11
  list_content = with_bootstrap_configs do
10
-
11
12
  item_container.items.inject([]) do |list, item|
12
- li_options = item.html_options
13
-
14
- navbar_text = li_options.delete(:navbar_text)
15
- navbar_divider = li_options.delete(:divider)
16
- navbar_header = li_options.delete(:header)
17
- link_options = li_options.delete(:link) || {}
18
- split = li_options.delete(:split)
19
-
20
- if navbar_text
21
- list << li_text( item.name, li_options )
22
- elsif navbar_divider
23
- list << li_divider( item_container.level, li_options )
24
- elsif navbar_header && (item_container.level != 1)
25
- list << li_header( item.name, li_options )
26
- else
27
- li_content = if include_sub_navigation?(item)
28
- if item_container.level == 1
29
- if split
30
- main_li_options = li_options.dup
31
- main_li_options[:class] = [ main_li_options[:class], "dropdown-split-left" ].flatten.compact.join(' ')
32
- list << content_tag(:li, simple_link(item, link_options), main_li_options)
33
- li_options[:id] = nil
34
- item.sub_navigation.dom_class = [ item.sub_navigation.dom_class, "pull-right" ].flatten.compact.join(' ')
35
- end
36
- li_options[:class] = [ li_options[:class], "dropdown", (split ? "dropdown-split-right" : nil) ].flatten.compact.join(' ')
37
- dropdown_link(item, split, link_options) + render_sub_navigation_for(item)
38
- else
39
- li_options[:class] = [ li_options[:class], "dropdown-submenu"].flatten.compact.join(' ')
40
- simple_link(item, link_options) + render_sub_navigation_for(item)
41
- end
42
- else
43
- simple_link(item, link_options)
44
- end
45
- list << content_tag(:li, li_content, li_options)
46
- end
13
+ list << SimpleNavigationRenderers::RenderedItem.new( self, item, item_container.level, options[:bv] ).to_s
47
14
  end.join
48
-
49
15
  end
50
-
51
- item_container.dom_class = [ item_container.dom_class,
52
- (item_container.level == 1) ? "nav#{(options[:bv] == 2) ? '' : ' navbar-nav'}" :
53
- "dropdown-menu" ].flatten.compact.join(' ')
16
+ item_container.dom_class = [ item_container.dom_class, container_class(item_container.level) ].flatten.compact.join(' ')
54
17
  content_tag(:ul, list_content, {id: item_container.dom_id, class: item_container.dom_class})
55
18
  end
56
19
  end
57
20
 
58
21
 
59
- protected
60
-
61
- def li_text( text, li_options )
62
- content_tag(:li, content_tag(:p, text, {class: 'navbar-text'}), li_options)
63
- end
22
+ private
64
23
 
65
- def li_divider( level, li_options )
66
- li_options[:class] = [ li_options[:class], ((level == 1) ? "divider-vertical" : "divider") ].flatten.compact.join(' ')
67
- content_tag(:li, '', li_options)
68
- end
69
-
70
- def li_header( text, li_options )
71
- li_options[:class] = [ li_options[:class], ((options[:bv] == 2) ? "nav-header" : "dropdown-header") ].flatten.compact.join(' ')
72
- content_tag(:li, text, li_options)
73
- end
74
-
75
- def simple_link( item, link_options )
76
- link_options[:method] ||= item.method
77
- link_to(item.name, (item.url || "#"), link_options)
78
- end
79
-
80
- def dropdown_link( item, split, link_options )
81
- link_options = {} if split
82
- link_options[:class] = [ link_options[:class], "dropdown-toggle" ].flatten.compact.join(' ')
83
- link_options[:"data-toggle"] = "dropdown"
84
- link_options[:"data-target"] = "#"
85
- link = [ (split ? nil : item.name), content_tag(:b, '', class: "caret") ].compact.join(' ')
86
- link_to(link, "#", link_options)
24
+ def container_class( level )
25
+ if level == 1
26
+ "nav" + ((options[:bv] == 3) ? ' navbar-nav' : '')
27
+ else
28
+ "dropdown-menu"
29
+ end
87
30
  end
88
31
 
89
32
  def with_bootstrap_configs
90
- config_selected_class = SimpleNavigation.config.selected_class
91
- config_name_generator = SimpleNavigation.config.name_generator
92
-
93
- SimpleNavigation.config.selected_class = "active"
33
+ sn_config = SimpleNavigation.config
34
+ config_selected_class = sn_config.selected_class
35
+ config_name_generator = sn_config.name_generator
36
+ sn_config.selected_class = "active"
94
37
  # name_generator should be proc (not lambda or method) to be compatible with earlier versions of simple-navigation
95
- SimpleNavigation.config.name_generator = proc do | name, item |
96
- if name.instance_of?(Hash)
97
- raise SimpleNavigationRenderers::InvalidHash unless name.keys.include?(:icon) || name.keys.include?(:text)
98
- [ (name[:icon] ? content_tag(:span, '', {class: name[:icon]}.merge(name[:title] ? {title: name[:title]} : {}) ) : nil), name[:text] ].compact.join(' ')
99
- else
100
- config_name_generator.call( name, item )
101
- end
38
+ sn_config.name_generator = proc do | name, item |
39
+ config_name_generator.call( prepare_name(name), item )
102
40
  end
103
41
 
104
42
  result = yield
105
43
 
106
- SimpleNavigation.config.name_generator = config_name_generator
107
- SimpleNavigation.config.selected_class = config_selected_class
44
+ sn_config.name_generator = config_name_generator
45
+ sn_config.selected_class = config_selected_class
108
46
 
109
47
  result
110
48
  end
111
49
 
50
+ def prepare_name( name )
51
+ if name.instance_of?(Hash)
52
+ if name[:icon]
53
+ icon_options = {class: name[:icon], title: name[:title]}.reject { |_, v| v.nil? }
54
+ content_tag(:span, '', icon_options) + ' ' + (name[:text] || '')
55
+ else
56
+ name[:text] || (raise SimpleNavigationRenderers::InvalidHash)
57
+ end
58
+ else
59
+ name
60
+ end
61
+ end
62
+
112
63
  end
113
64
 
114
65
 
@@ -0,0 +1,112 @@
1
+ require 'forwardable'
2
+
3
+ module SimpleNavigationRenderers
4
+
5
+ class RenderedItem
6
+ extend Forwardable
7
+
8
+ attr_reader :renderer
9
+ def_delegators :renderer, :link_to, :content_tag, :include_sub_navigation?, :render_sub_navigation_for
10
+
11
+ def initialize( renderer, item, level, bootstrap_version )
12
+ @renderer = renderer
13
+ @item = item
14
+ @level = level
15
+ @bootstrap_version = bootstrap_version
16
+
17
+ @options = item.html_options
18
+ @navbar_text = options.delete(:navbar_text)
19
+ @divider = options.delete(:divider)
20
+ @header = options.delete(:header)
21
+ @link_options = options.delete(:link) || {}
22
+ @split = options.delete(:split)
23
+ end
24
+
25
+ def to_s
26
+ if navbar_text
27
+ li_text
28
+ elsif divider
29
+ li_divider
30
+ elsif header && (level != 1)
31
+ li_header
32
+ else
33
+ li_link
34
+ end
35
+ end
36
+
37
+
38
+ private
39
+
40
+ attr_reader :item, :level, :bootstrap_version, :options, :navbar_text, :divider, :header, :link_options, :split
41
+
42
+ def li_text
43
+ content_tag(:li, content_tag(:p, item.name, {class: 'navbar-text'}), options)
44
+ end
45
+
46
+ def li_divider
47
+ options[:class] = [ options[:class], ((level == 1) ? "divider-vertical" : "divider") ].flatten.compact.join(' ')
48
+ content_tag(:li, '', options)
49
+ end
50
+
51
+ def li_header
52
+ options[:class] = [ options[:class], ((bootstrap_version == 3) ? "dropdown-header" : "nav-header") ].flatten.compact.join(' ')
53
+ content_tag(:li, item.name, options)
54
+ end
55
+
56
+ def li_link
57
+ if include_sub_navigation?(item)
58
+ if level == 1
59
+ if split
60
+ splitted_simple_part + splitted_dropdown_part
61
+ else
62
+ dropdown_part( item.name + ' ' + caret )
63
+ end
64
+ else
65
+ content_tag(:li, dropdown_submenu_link, options)
66
+ end
67
+ else
68
+ content_tag(:li, simple_link, options)
69
+ end
70
+ end
71
+
72
+ def splitted_simple_part
73
+ main_li_options = options.dup
74
+ main_li_options[:class] = [ main_li_options[:class], "dropdown-split-left" ].flatten.compact.join(' ')
75
+ content_tag(:li, simple_link, main_li_options)
76
+ end
77
+
78
+ def splitted_dropdown_part
79
+ item.sub_navigation.dom_class = [ item.sub_navigation.dom_class, "pull-right" ].flatten.compact.join(' ')
80
+ link_options = {}
81
+ options[:id] = nil
82
+ options[:class] = [ options[:class], "dropdown-split-right" ].flatten.compact.join(' ')
83
+ dropdown_part( caret )
84
+ end
85
+
86
+ def dropdown_part( name )
87
+ options[:class] = [ options[:class], "dropdown" ].flatten.compact.join(' ')
88
+ link_options[:class] = [ link_options[:class], "dropdown-toggle" ].flatten.compact.join(' ')
89
+ link_options[:"data-toggle"] = "dropdown"
90
+ link_options[:"data-target"] = "#"
91
+
92
+ content = link_to( name, "#", link_options ) + render_sub_navigation_for(item)
93
+ content_tag(:li, content, options)
94
+ end
95
+
96
+ def caret
97
+ content_tag(:b, '', class: "caret")
98
+ end
99
+
100
+ def dropdown_submenu_link
101
+ options[:class] = [ options[:class], "dropdown-submenu" ].flatten.compact.join(' ')
102
+ simple_link + render_sub_navigation_for(item)
103
+ end
104
+
105
+ def simple_link
106
+ link_options[:method] ||= item.method
107
+ link_to(item.name, (item.url || "#"), link_options)
108
+ end
109
+
110
+ end
111
+
112
+ end
@@ -1,3 +1,3 @@
1
1
  module SimpleNavigationRenderers
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rspec"
25
25
  spec.add_development_dependency "bundler", "~> 1.3"
26
26
  spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "coveralls", "~> 0.7"
27
28
  end
@@ -1,3 +1,6 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  ENV["RAILS_ENV"] = "test"
2
5
  require 'action_controller'
3
6
  module Rails
metadata CHANGED
@@ -1,85 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_navigation_renderers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Shpak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-14 00:00:00.000000000 Z
11
+ date: 2014-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple-navigation
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.11'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.11'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: actionpack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.7'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.7'
83
97
  description: 'simple_navigation_renderers gem adds renderers for Bootstrap 2 and 3.
84
98
  With these renderers you will be able create any bootstrap navigation elements,
85
99
  such as: submenu, navbar-text, divider, header. As well as add icons to menu elements,
@@ -91,10 +105,10 @@ executables: []
91
105
  extensions: []
92
106
  extra_rdoc_files: []
93
107
  files:
94
- - .gitignore
95
- - .rspec
96
- - .rvmrc
97
- - .travis.yml
108
+ - ".gitignore"
109
+ - ".rspec"
110
+ - ".rvmrc"
111
+ - ".travis.yml"
98
112
  - CHANGELOG.md
99
113
  - Gemfile
100
114
  - LICENSE.txt
@@ -104,6 +118,7 @@ files:
104
118
  - lib/simple_navigation_renderers/bootstrap.rb
105
119
  - lib/simple_navigation_renderers/engine.rb
106
120
  - lib/simple_navigation_renderers/exceptions.rb
121
+ - lib/simple_navigation_renderers/rendered_item.rb
107
122
  - lib/simple_navigation_renderers/version.rb
108
123
  - simple_navigation_renderers.gemspec
109
124
  - spec/lib/simple_navigation_renderers/bootstrap_spec.rb
@@ -124,17 +139,17 @@ require_paths:
124
139
  - lib
125
140
  required_ruby_version: !ruby/object:Gem::Requirement
126
141
  requirements:
127
- - - '>='
142
+ - - ">="
128
143
  - !ruby/object:Gem::Version
129
144
  version: '0'
130
145
  required_rubygems_version: !ruby/object:Gem::Requirement
131
146
  requirements:
132
- - - '>='
147
+ - - ">="
133
148
  - !ruby/object:Gem::Version
134
149
  version: '0'
135
150
  requirements: []
136
151
  rubyforge_project:
137
- rubygems_version: 2.1.11
152
+ rubygems_version: 2.2.2
138
153
  signing_key:
139
154
  specification_version: 4
140
155
  summary: 'simple_navigation_renderers gem adds renderers for Bootstrap 2 and 3. With