navtastic 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -1
- data/CHANGELOG.md +9 -1
- data/README.md +9 -0
- data/lib/navtastic.rb +4 -2
- data/lib/navtastic/configuration.rb +25 -0
- data/lib/navtastic/railtie.rb +20 -0
- data/lib/navtastic/version.rb +1 -1
- data/spec/navtastic_spec.rb +10 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e38b165248d09e76592965914d31a637907efd3
|
4
|
+
data.tar.gz: c96c4568a2a0880b2b17cb0599a8bceaa9fa13d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bad84049a62139b26dd37950e9cc4120056a52c52fc959068eca024fa7655e07f12c516d204e82bb685843604b2c927be13ffa6b53e95df0a7dd0cc23bee78f7
|
7
|
+
data.tar.gz: 7733f9d31ec353558f23b6e9db2a24995e86cb5f3529df0bf155b9009537f04c2dce431fd7eaefa9f4c741922a2e5efd7051501722cbb4f70aa9555b748fb8ed
|
data/.rubocop.yml
CHANGED
@@ -8,6 +8,7 @@ AllCops:
|
|
8
8
|
- 'spec/demo/**/*'
|
9
9
|
- 'spec/support/**/*'
|
10
10
|
- 'vendor/**/*'
|
11
|
+
- '*.gemspec'
|
11
12
|
TargetRubyVersion: 2.4
|
12
13
|
|
13
14
|
Metrics/AbcSize:
|
@@ -26,6 +27,6 @@ Style/FrozenStringLiteralComment:
|
|
26
27
|
Style/StringLiterals:
|
27
28
|
Enabled: false
|
28
29
|
|
29
|
-
Style/
|
30
|
+
Style/TrailingCommaInHashLiteral:
|
30
31
|
EnforcedStyleForMultiline: consistent_comma
|
31
32
|
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
## [Unreleased]
|
4
4
|
|
5
|
+
## [0.2.0] - 2018-03-06
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- Hot reload option of renderer class
|
10
|
+
- Support for Rails (configuration and view helpers)
|
11
|
+
|
5
12
|
## [0.1.0] - 2017-09-05
|
6
13
|
|
7
14
|
### Added
|
@@ -21,4 +28,5 @@
|
|
21
28
|
- Runtime parameters
|
22
29
|
|
23
30
|
[Unreleased]: https://github.com/aramvisser/navtastic/compare/v0.1.0...HEAD
|
24
|
-
[0.1.0]: https://github.com/
|
31
|
+
[0.1.0]: https://github.com/aramvisser/navtastic/compare/v0.0.1...v0.1.0
|
32
|
+
[0.2.0]: https://github.com/aramvisser/navtastic/compare/v0.1.0...v0.2.0
|
data/README.md
CHANGED
@@ -80,6 +80,12 @@ Using the default renderer, assuming that the current url starts with `/posts`,
|
|
80
80
|
</ul>
|
81
81
|
```
|
82
82
|
|
83
|
+
### Rails
|
84
|
+
|
85
|
+
When using rails, a `render_menu` helper is added that automatically sets the current_url.
|
86
|
+
|
87
|
+
Also, put defined menus in `app/menus` to take advantage of hot reload.
|
88
|
+
|
83
89
|
## Documentation
|
84
90
|
|
85
91
|
### Submenus
|
@@ -172,6 +178,9 @@ Navtastic.configure do |config|
|
|
172
178
|
|
173
179
|
# Options that are passed to the renderer
|
174
180
|
config.renderer_options = {}
|
181
|
+
|
182
|
+
# Reload the renderer class every time menu is rendered (helpful during development)
|
183
|
+
config.reload_renderer = false
|
175
184
|
end
|
176
185
|
```
|
177
186
|
|
data/lib/navtastic.rb
CHANGED
@@ -59,13 +59,13 @@ module Navtastic
|
|
59
59
|
raise KeyError, "menu not defined: #{name.inspect}" if block.nil?
|
60
60
|
|
61
61
|
# Merge renderer options globally with those passed at runtime
|
62
|
-
renderer_options = configuration.renderer_options
|
62
|
+
renderer_options = configuration.renderer_options.dup
|
63
63
|
renderer_options.merge!(params.delete(:renderer) || {})
|
64
64
|
|
65
65
|
menu = Menu.new
|
66
66
|
block.call(menu, params)
|
67
67
|
menu.current_url = current_url
|
68
|
-
Navtastic.configuration.
|
68
|
+
Navtastic.configuration.current_renderer.render(menu, renderer_options)
|
69
69
|
end
|
70
70
|
|
71
71
|
# A list of all defined menus
|
@@ -75,3 +75,5 @@ module Navtastic
|
|
75
75
|
@menu_store.keys
|
76
76
|
end
|
77
77
|
end
|
78
|
+
|
79
|
+
require 'navtastic/railtie.rb' if defined?(Rails)
|
@@ -22,9 +22,20 @@ module Navtastic # :nodoc:
|
|
22
22
|
# @return [Hash]
|
23
23
|
attr_accessor :renderer_options
|
24
24
|
|
25
|
+
# Should the renderer class be reloaded everytime the menu is rendered?
|
26
|
+
#
|
27
|
+
# This is helpful during development, to avoid restarting the server after
|
28
|
+
# every change, but should be disabled during production.
|
29
|
+
#
|
30
|
+
# Defaults to `false`
|
31
|
+
#
|
32
|
+
# @return bool
|
33
|
+
attr_accessor :reload_renderer
|
34
|
+
|
25
35
|
def initialize
|
26
36
|
@renderer = Navtastic::Renderer::Simple
|
27
37
|
@renderer_options = {}
|
38
|
+
@reload_renderer = false
|
28
39
|
@base_url = nil
|
29
40
|
end
|
30
41
|
|
@@ -45,6 +56,20 @@ module Navtastic # :nodoc:
|
|
45
56
|
end
|
46
57
|
end
|
47
58
|
|
59
|
+
# @return [Navtastic::Renderer] renderer to use
|
60
|
+
#
|
61
|
+
# Will hot reload the renderer class if needed
|
62
|
+
def current_renderer
|
63
|
+
klass = renderer
|
64
|
+
|
65
|
+
if reload_renderer
|
66
|
+
klass = klass.to_s unless klass.is_a?(String)
|
67
|
+
Object.const_get(klass)
|
68
|
+
else
|
69
|
+
klass
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
48
73
|
private
|
49
74
|
|
50
75
|
# Built in renderers
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Navtastic
|
2
|
+
# Helper methods for ActionView
|
3
|
+
module ViewHelpers
|
4
|
+
def render_menu(menu, options = {})
|
5
|
+
Navtastic.render menu, request.fullpath, options
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
# Setup hot reload and add helper to ApplicationHelper
|
10
|
+
class Railtie < ::Rails::Railtie
|
11
|
+
initializer "navtastic_railtie.initialize_configuration" do |app|
|
12
|
+
Navtastic.configuration.reload_renderer = !app.config.eager_load
|
13
|
+
ActiveSupport.on_load(:action_view) { include Navtastic::ViewHelpers }
|
14
|
+
end
|
15
|
+
|
16
|
+
config.to_prepare do
|
17
|
+
Dir["app/menus/*.rb"].each { |file| load file }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/navtastic/version.rb
CHANGED
data/spec/navtastic_spec.rb
CHANGED
@@ -85,5 +85,15 @@ RSpec.describe Navtastic do
|
|
85
85
|
expect(render.options[:foo]).to eq :foo
|
86
86
|
end
|
87
87
|
end
|
88
|
+
|
89
|
+
context "when render gets called twice in a row" do
|
90
|
+
before do
|
91
|
+
described_class.render(menu_name, '/', renderer: { foo: :bar })
|
92
|
+
end
|
93
|
+
|
94
|
+
it "won't use the renderer params from the first call" do
|
95
|
+
expect(render.options[:foo]).to be_nil
|
96
|
+
end
|
97
|
+
end
|
88
98
|
end
|
89
99
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: navtastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aram Visser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: arbre
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/navtastic/configuration.rb
|
118
118
|
- lib/navtastic/item.rb
|
119
119
|
- lib/navtastic/menu.rb
|
120
|
+
- lib/navtastic/railtie.rb
|
120
121
|
- lib/navtastic/renderer.rb
|
121
122
|
- lib/navtastic/renderer/bootstrap4.rb
|
122
123
|
- lib/navtastic/renderer/bulma.rb
|