rocket_navigation 0.1.3 → 0.2.0

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
  SHA256:
3
- metadata.gz: b655c6a0dbb6ce63dcb632e0c33e3246ea244a47f971b5346ebb9932403143f5
4
- data.tar.gz: 74b8609b86f56eb04b00e41f321bc1387d744406f3152fd50f4808620b113b35
3
+ metadata.gz: ba6c352fa00bc6cca0365fa054ecd8eea509bd0dfa7203ba05bafc6fb34a7838
4
+ data.tar.gz: e6f3918f1a5b5eeeb1a1ebd0b5fddd5913df78ee7b5cfde4710853983ddd65cd
5
5
  SHA512:
6
- metadata.gz: 3f6508e1b90e1d51aa28bb89d84faa96d8470159d085e9ebef8d83876bcd87856c77be6178d3b36baa6f05f4007c9f6c3c6c3236301470ae46d2be2e637b3de0
7
- data.tar.gz: f8554c570158217805b53da94b09536166bbbc6ce5b7f54ee31d632be37d74780dd2afd839935b2987c0438b48889fad9a54c19d873e67d711471e0426d19368
6
+ metadata.gz: b0b64f5aa257aa7851f7e17504f08939c934e41da9fca3558d0046f8ffa2701c4d1346bf08d407e99476b718c8f781f03e05a9e8154ec54189d4cab656a069f8
7
+ data.tar.gz: 88b2bfc17c3f0a18c714ea6468f86c7a46c7a76a73afe5c71bfdb319ae45dfd12cc6ce68d19ef5e1d3a78c0a959d2031a277caa4137f08d40795bb2293779e60
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rocket_navigation (0.1.3)
4
+ rocket_navigation (0.2.0)
5
5
  actionpack (>= 5.0)
6
6
  actionview (>= 5.0)
7
7
  activesupport (>= 5.0)
@@ -54,7 +54,7 @@ GEM
54
54
  public_suffix (>= 2.0.2, < 4.0)
55
55
  arel (9.0.0)
56
56
  builder (3.2.3)
57
- capybara (3.1.0)
57
+ capybara (3.1.1)
58
58
  addressable
59
59
  mini_mime (>= 0.1.3)
60
60
  nokogiri (~> 1.8)
@@ -65,7 +65,7 @@ GEM
65
65
  concurrent-ruby (1.0.5)
66
66
  crass (1.0.4)
67
67
  diff-lcs (1.3)
68
- docile (1.3.0)
68
+ docile (1.3.1)
69
69
  erubi (1.7.1)
70
70
  ffi (1.9.23)
71
71
  formatador (0.2.5)
data/README.md CHANGED
@@ -24,6 +24,7 @@ Changes include:
24
24
  10. All css classes are managed in renderers and can be easily overriden from them
25
25
  11. Added [breadcrumbs_on_rails](https://github.com/weppos/breadcrumbs_on_rails) integration
26
26
  12. expand_all defaults to true, as pretty much all menus are js-based now.
27
+ 13. Includes bootstrap 4 renderer
27
28
 
28
29
  ## Installation
29
30
 
@@ -23,6 +23,7 @@ module RocketNavigation
23
23
  self.registered_renderers = {
24
24
  list: RocketNavigation::Renderer::List,
25
25
  links: RocketNavigation::Renderer::Links,
26
+ bootstrap: RocketNavigation::Renderer::Bootstrap,
26
27
  breadcrumbs: RocketNavigation::Renderer::Breadcrumbs,
27
28
  breadcrumbs_on_rails: RocketNavigation::Renderer::BreadcrumbsOnRails,
28
29
  text: RocketNavigation::Renderer::Text,
@@ -12,6 +12,8 @@ module RocketNavigation
12
12
  def_delegators :container, :view_context
13
13
  def_delegators :view_context, :is_active_nav_link?
14
14
 
15
+ def_delegators :container, :level
16
+
15
17
  # see ItemContainer#item
16
18
  #
17
19
  # The subnavigation (if any) is either provided by a block or
@@ -5,6 +5,7 @@ module RocketNavigation
5
5
  module Renderer
6
6
  autoload :List, 'rocket_navigation/renderer/list'
7
7
  autoload :Links, 'rocket_navigation/renderer/links'
8
+ autoload :Bootstrap, 'rocket_navigation/renderer/bootstrap'
8
9
  autoload :Breadcrumbs, 'rocket_navigation/renderer/breadcrumbs'
9
10
  autoload :BreadcrumbsOnRails, 'rocket_navigation/renderer/breadcrumbs_on_rails'
10
11
  autoload :Text, 'rocket_navigation/renderer/text'
@@ -35,7 +35,11 @@ module RocketNavigation
35
35
  @base_item_html ||= container.item_html.merge(options[:item_html] || {})
36
36
  end
37
37
 
38
- def item_html(item)
38
+ # override in renderer if needed
39
+ def item_extra_classes(item)
40
+ []
41
+ end
42
+ def item_classes(item)
39
43
  classes = Array.wrap(base_item_html[:class] || [])
40
44
  if item.selected?
41
45
  classes.push(selected_class(:item))
@@ -43,9 +47,13 @@ module RocketNavigation
43
47
  if item.active_branch?
44
48
  classes.push(selected_class(:branch))
45
49
  end
50
+ classes = classes.reject { |c| c.nil? } + item_extra_classes(item)
51
+ end
46
52
 
53
+ def item_html(item)
47
54
  ret = base_item_html.except(:class)
48
- classes = classes.reject { |c| c.nil? }
55
+
56
+ classes = item_classes(item)
49
57
  ret.merge!({class: classes}) unless classes.blank?
50
58
  ret
51
59
  end
@@ -59,16 +67,24 @@ module RocketNavigation
59
67
  @base_link_html ||= container.link_html.merge(options[:link_html] || {})
60
68
  end
61
69
 
62
- def link_html(item)
70
+ # override in renderer if needed
71
+ def link_extra_classes(item)
72
+ []
73
+ end
74
+ def link_classes(item)
63
75
  classes = Array.wrap(base_link_html[:class] || [])
64
76
  if item.selected?
65
77
  classes.push(selected_class(:link))
66
78
  end
79
+ classes = classes.reject { |c| c.nil? } + link_extra_classes(item)
80
+ end
81
+
82
+ def link_html(item)
67
83
  ret = base_link_html.except(:class)
68
84
 
69
85
  ret.merge!({ method: item.method }) unless item.method.blank?
70
86
 
71
- classes = classes.reject { |c| c.nil? }
87
+ classes = link_classes(item)
72
88
  ret.merge!({class: classes}) unless classes.blank?
73
89
 
74
90
  ret
@@ -0,0 +1,90 @@
1
+ # source: https://github.com/pdf/simple-navigation-bootstrap/blob/master/lib/simple_navigation/rendering/renderer/bootstrap.rb
2
+ # Copyright (c) 2017 Peter Fern
3
+ # MIT License
4
+
5
+ module RocketNavigation
6
+ module Renderer
7
+ class Bootstrap < RocketNavigation::Renderer::Base
8
+ def initialize(container, options = {})
9
+ super(container, options)
10
+ end
11
+
12
+ def render(item_container)
13
+ if skip_if_empty? && item_container.empty?
14
+ ''.html_safe
15
+ else
16
+ if item_container.level > 1
17
+ content = list_content(item_container)
18
+ content_tag(:div, content, {class: "dropdown-menu"})
19
+ else
20
+ tag = options[:ordered] ? :ol : :ul
21
+ content = list_content(item_container)
22
+ content_tag(tag, content, container_html)
23
+ end
24
+ end
25
+ end
26
+
27
+ def render_item(item)
28
+ if item.level == 1
29
+ li_content = tag_for(item)
30
+ if include_sub_navigation?(item)
31
+ li_content << render_sub_navigation_for(item)
32
+ end
33
+ content_tag(:li, li_content, item_options(item))
34
+ else
35
+ tag_for(item)
36
+ end
37
+ end
38
+
39
+ def list_content(item_container)
40
+ ret = ActiveSupport::SafeBuffer.new
41
+ item_container.items.each do |item|
42
+ ret << render_item(item)
43
+ end
44
+ ret
45
+ end
46
+
47
+ def expand_all?
48
+ true
49
+ end
50
+ def consider_sub_navigation?(item)
51
+ return false unless item.sub_navigation
52
+ true
53
+ end
54
+
55
+ def item_extra_classes(item)
56
+ if include_sub_navigation?(item)
57
+ ["dropdown"]
58
+ else
59
+ []
60
+ end
61
+ end
62
+
63
+ def link_classes(item)
64
+ if item.level > 1
65
+ classes = ["dropdown-item"]
66
+ if item.selected?
67
+ classes.push('active')
68
+ end
69
+ classes
70
+ else
71
+ super(item)
72
+ end
73
+ end
74
+
75
+ def tag_for(item)
76
+ if item.level == 1 && item.sub_navigation
77
+ link_to(item.name, item.url, {class: "nav-link dropdown-toggle", 'data-toggle' => "dropdown"})
78
+ else
79
+ super(item)
80
+ end
81
+ end
82
+
83
+ def render_sub_navigation_for(item)
84
+ opts = options.dup
85
+ p opts
86
+ item.sub_navigation.render(opts)
87
+ end
88
+ end
89
+ end
90
+ end
@@ -1,3 +1,3 @@
1
1
  module RocketNavigation
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rocket_navigation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gleb Tv
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-24 00:00:00.000000000 Z
11
+ date: 2018-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -220,6 +220,7 @@ files:
220
220
  - lib/rocket_navigation/railtie.rb
221
221
  - lib/rocket_navigation/renderer.rb
222
222
  - lib/rocket_navigation/renderer/base.rb
223
+ - lib/rocket_navigation/renderer/bootstrap.rb
223
224
  - lib/rocket_navigation/renderer/breadcrumbs.rb
224
225
  - lib/rocket_navigation/renderer/breadcrumbs_on_rails.rb
225
226
  - lib/rocket_navigation/renderer/json.rb