simple-navigation 4.4.1 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +84 -0
- data/.rspec +1 -2
- data/.rubocop.yml +49 -0
- data/.rubocop_todo.yml +38 -0
- data/Appraisals +55 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +21 -0
- data/Guardfile +4 -2
- data/README.md +11 -23
- data/Rakefile +2 -27
- data/bin/_guard-core +16 -0
- data/bin/appraisal +16 -0
- data/bin/guard +16 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/bin/rubocop +16 -0
- data/gemfiles/rails_6.1.gemfile +35 -0
- data/gemfiles/rails_7.0.gemfile +23 -0
- data/gemfiles/rails_7.1.gemfile +23 -0
- data/gemfiles/rails_7.2.gemfile +23 -0
- data/gemfiles/rails_8.0.gemfile +23 -0
- data/gemfiles/rails_8.1.gemfile +23 -0
- data/generators/navigation_config/navigation_config_generator.rb +2 -0
- data/generators/navigation_config/templates/config/navigation.rb +30 -26
- data/lib/generators/navigation_config/navigation_config_generator.rb +2 -0
- data/lib/simple-navigation.rb +3 -1
- data/lib/simple_navigation/adapters/base.rb +2 -0
- data/lib/simple_navigation/adapters/nanoc.rb +8 -3
- data/lib/simple_navigation/adapters/padrino.rb +3 -1
- data/lib/simple_navigation/adapters/rails.rb +12 -14
- data/lib/simple_navigation/adapters/sinatra.rb +4 -6
- data/lib/simple_navigation/config_file.rb +1 -1
- data/lib/simple_navigation/config_file_finder.rb +3 -3
- data/lib/simple_navigation/configuration.rb +5 -5
- data/lib/simple_navigation/helpers.rb +9 -11
- data/lib/simple_navigation/item.rb +26 -20
- data/lib/simple_navigation/item_adapter.rb +16 -5
- data/lib/simple_navigation/item_container.rb +13 -7
- data/lib/simple_navigation/items_provider.rb +6 -4
- data/lib/simple_navigation/railtie.rb +3 -1
- data/lib/simple_navigation/renderer/base.rb +5 -5
- data/lib/simple_navigation/renderer/breadcrumbs.rb +4 -3
- data/lib/simple_navigation/renderer/json.rb +1 -1
- data/lib/simple_navigation/renderer/links.rb +2 -0
- data/lib/simple_navigation/renderer/list.rb +5 -5
- data/lib/simple_navigation/renderer/text.rb +3 -1
- data/lib/simple_navigation/version.rb +3 -1
- data/lib/simple_navigation.rb +32 -24
- data/simple-navigation.gemspec +16 -27
- data/spec/fake_app/config/navigation.rb +4 -2
- data/spec/fake_app/rails_app.rb +5 -3
- data/spec/integration/rendering_navigation_spec.rb +7 -5
- data/spec/simple_navigation/adapters/nanoc_spec.rb +97 -0
- data/spec/simple_navigation/adapters/padrino_spec.rb +41 -22
- data/spec/simple_navigation/adapters/rails_spec.rb +199 -206
- data/spec/simple_navigation/adapters/sinatra_spec.rb +21 -5
- data/spec/simple_navigation/config_file_finder_spec.rb +32 -28
- data/spec/simple_navigation/config_file_spec.rb +14 -14
- data/spec/simple_navigation/configuration_spec.rb +128 -121
- data/spec/simple_navigation/helpers_spec.rb +282 -284
- data/spec/simple_navigation/item_adapter_spec.rb +109 -122
- data/spec/simple_navigation/item_container_spec.rb +407 -408
- data/spec/simple_navigation/item_spec.rb +333 -301
- data/spec/simple_navigation/items_provider_spec.rb +30 -27
- data/spec/simple_navigation/renderer/base_spec.rb +166 -168
- data/spec/simple_navigation/renderer/breadcrumbs_spec.rb +81 -83
- data/spec/simple_navigation/renderer/json_spec.rb +49 -56
- data/spec/simple_navigation/renderer/links_spec.rb +81 -83
- data/spec/simple_navigation/renderer/list_spec.rb +111 -91
- data/spec/simple_navigation/renderer/text_spec.rb +37 -39
- data/spec/simple_navigation_spec.rb +54 -47
- data/spec/spec_helper.rb +146 -53
- metadata +25 -164
- data/.travis.yml +0 -23
- data/gemfiles/rails-3-2-stable.gemfile +0 -11
- data/gemfiles/rails-4-1-stable.gemfile +0 -7
- data/gemfiles/rails-4-2-stable.gemfile +0 -7
- data/gemfiles/rails-5-2-stable.gemfile +0 -7
- data/gemfiles/rails-6-0-stable.gemfile +0 -9
- data/gemfiles/rails-6-1-stable.gemfile +0 -9
- data/init.rb +0 -1
- data/install.rb +0 -5
- data/lib/simple_navigation/adapters.rb +0 -10
- data/lib/simple_navigation/renderer.rb +0 -12
- data/spec/initializers/coveralls.rb +0 -3
- data/spec/initializers/have_css_matcher.rb +0 -19
- data/spec/initializers/memfs.rb +0 -7
- data/spec/initializers/rails.rb +0 -4
- data/spec/initializers/rspec.rb +0 -7
- data/uninstall.rb +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module SimpleNavigation
|
|
4
4
|
module Renderer
|
|
@@ -13,7 +13,7 @@ module SimpleNavigation
|
|
|
13
13
|
|
|
14
14
|
def_delegators :adapter, :link_to, :content_tag
|
|
15
15
|
|
|
16
|
-
def initialize(options)
|
|
16
|
+
def initialize(options) # :nodoc:
|
|
17
17
|
@options = options
|
|
18
18
|
@adapter = SimpleNavigation.adapter
|
|
19
19
|
end
|
|
@@ -44,7 +44,7 @@ module SimpleNavigation
|
|
|
44
44
|
# include_sub_navigation? to determine whether an item's sub_navigation
|
|
45
45
|
# should be rendered or not.
|
|
46
46
|
def render(item_container)
|
|
47
|
-
|
|
47
|
+
raise NotImplementedError, 'subclass responsibility'
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
protected
|
|
@@ -89,11 +89,11 @@ module SimpleNavigation
|
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
# Extracts the options relevant for the generated link
|
|
92
|
-
def link_options_for(item)
|
|
92
|
+
def link_options_for(item) # rubocop:disable Metrics/MethodLength
|
|
93
93
|
special_options = {
|
|
94
94
|
method: item.method,
|
|
95
95
|
class: item.selected_class
|
|
96
|
-
}.
|
|
96
|
+
}.compact
|
|
97
97
|
|
|
98
98
|
link_options = item.link_html_options
|
|
99
99
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module SimpleNavigation
|
|
2
4
|
module Renderer
|
|
3
5
|
# Renders an ItemContainer as a <div> element and its containing items as
|
|
@@ -25,11 +27,10 @@ module SimpleNavigation
|
|
|
25
27
|
def a_tags(item_container)
|
|
26
28
|
item_container.items.each_with_object([]) do |item, list|
|
|
27
29
|
next unless item.selected?
|
|
30
|
+
|
|
28
31
|
list << tag_for(item)
|
|
29
32
|
|
|
30
|
-
if include_sub_navigation?(item)
|
|
31
|
-
list.concat a_tags(item.sub_navigation)
|
|
32
|
-
end
|
|
33
|
+
list.concat a_tags(item.sub_navigation) if include_sub_navigation?(item)
|
|
33
34
|
end
|
|
34
35
|
end
|
|
35
36
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module SimpleNavigation
|
|
2
4
|
module Renderer
|
|
3
5
|
# Renders an ItemContainer as a <ul> element and its containing items as
|
|
@@ -28,14 +30,12 @@ module SimpleNavigation
|
|
|
28
30
|
private
|
|
29
31
|
|
|
30
32
|
def list_content(item_container)
|
|
31
|
-
item_container.items.map
|
|
33
|
+
item_container.items.map do |item|
|
|
32
34
|
li_options = item.html_options.except(:link)
|
|
33
35
|
li_content = tag_for(item)
|
|
34
|
-
if include_sub_navigation?(item)
|
|
35
|
-
li_content << render_sub_navigation_for(item)
|
|
36
|
-
end
|
|
36
|
+
li_content << render_sub_navigation_for(item) if include_sub_navigation?(item)
|
|
37
37
|
content_tag(:li, li_content, li_options)
|
|
38
|
-
|
|
38
|
+
end.join
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module SimpleNavigation
|
|
2
4
|
module Renderer
|
|
3
5
|
# Renders the 'chain' of selected navigation items as simple text items,
|
|
@@ -13,7 +15,7 @@ module SimpleNavigation
|
|
|
13
15
|
def list(item_container)
|
|
14
16
|
item_container.items.keep_if(&:selected?).map do |item|
|
|
15
17
|
[item.name(apply_generator: false)] +
|
|
16
|
-
|
|
18
|
+
(include_sub_navigation?(item) ? list(item.sub_navigation) : [])
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
end
|
data/lib/simple_navigation.rb
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# require ruby dependencies
|
|
4
|
+
require 'cgi/escape'
|
|
5
|
+
require 'forwardable'
|
|
6
|
+
require 'json'
|
|
7
|
+
require 'singleton'
|
|
8
|
+
|
|
9
|
+
# require external dependencies
|
|
2
10
|
require 'active_support/core_ext/array'
|
|
3
11
|
require 'active_support/core_ext/hash'
|
|
12
|
+
require 'active_support/core_ext/string'
|
|
4
13
|
require 'active_support/core_ext/module/attribute_accessors'
|
|
14
|
+
require 'zeitwerk'
|
|
5
15
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
require 'simple_navigation/renderer'
|
|
13
|
-
require 'simple_navigation/adapters'
|
|
14
|
-
require 'simple_navigation/config_file_finder'
|
|
15
|
-
require 'simple_navigation/railtie' if defined?(::Rails::Railtie)
|
|
16
|
-
|
|
17
|
-
require 'forwardable'
|
|
16
|
+
# load zeitwerk
|
|
17
|
+
Zeitwerk::Loader.for_gem.tap do |loader|
|
|
18
|
+
loader.ignore("#{__dir__}/generators")
|
|
19
|
+
loader.ignore("#{__dir__}/simple-navigation.rb")
|
|
20
|
+
loader.setup
|
|
21
|
+
end
|
|
18
22
|
|
|
19
23
|
# A plugin for generating a simple navigation. See README for resources on
|
|
20
24
|
# usage instructions.
|
|
21
25
|
module SimpleNavigation
|
|
26
|
+
require_relative 'simple_navigation/railtie' if defined?(Rails::Railtie)
|
|
27
|
+
|
|
22
28
|
mattr_accessor :adapter,
|
|
23
29
|
:adapter_class,
|
|
24
30
|
:config_files,
|
|
@@ -38,21 +44,21 @@ module SimpleNavigation
|
|
|
38
44
|
# Maps renderer keys to classes. The keys serve as shortcut in the
|
|
39
45
|
# render_navigation calls (renderer: :list)
|
|
40
46
|
self.registered_renderers = {
|
|
41
|
-
list:
|
|
42
|
-
links:
|
|
47
|
+
list: SimpleNavigation::Renderer::List,
|
|
48
|
+
links: SimpleNavigation::Renderer::Links,
|
|
43
49
|
breadcrumbs: SimpleNavigation::Renderer::Breadcrumbs,
|
|
44
|
-
text:
|
|
45
|
-
json:
|
|
50
|
+
text: SimpleNavigation::Renderer::Text,
|
|
51
|
+
json: SimpleNavigation::Renderer::Json
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
class << self
|
|
49
55
|
extend Forwardable
|
|
50
56
|
|
|
51
57
|
def_delegators :adapter, :context_for_eval,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
:current_page?,
|
|
59
|
+
:request,
|
|
60
|
+
:request_path,
|
|
61
|
+
:request_uri
|
|
56
62
|
|
|
57
63
|
def_delegators :adapter_class, :register
|
|
58
64
|
|
|
@@ -67,11 +73,13 @@ module SimpleNavigation
|
|
|
67
73
|
# Returns the current framework in which the plugin is running.
|
|
68
74
|
def framework
|
|
69
75
|
return :rails if defined?(Rails)
|
|
76
|
+
# :nocov:
|
|
70
77
|
return :padrino if defined?(Padrino)
|
|
71
78
|
return :sinatra if defined?(Sinatra)
|
|
72
79
|
return :nanoc if defined?(Nanoc3)
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
|
|
81
|
+
raise 'simple_navigation currently only works for Rails, Sinatra and Padrino apps'
|
|
82
|
+
# :nocov:
|
|
75
83
|
end
|
|
76
84
|
|
|
77
85
|
# Loads the adapter for the current framework
|
|
@@ -138,7 +146,7 @@ module SimpleNavigation
|
|
|
138
146
|
when Integer then primary_navigation.active_item_container_for(level)
|
|
139
147
|
when Range then primary_navigation.active_item_container_for(level.min)
|
|
140
148
|
else
|
|
141
|
-
|
|
149
|
+
raise ArgumentError, "Invalid navigation level: #{level}"
|
|
142
150
|
end
|
|
143
151
|
end
|
|
144
152
|
|
data/simple-navigation.gemspec
CHANGED
|
@@ -1,42 +1,31 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
require 'simple_navigation/version'
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/simple_navigation/version'
|
|
5
4
|
|
|
6
5
|
Gem::Specification.new do |spec|
|
|
7
6
|
spec.name = 'simple-navigation'
|
|
8
7
|
spec.version = SimpleNavigation::VERSION
|
|
9
8
|
spec.authors = ['Andi Schacke', 'Mark J. Titorenko', 'Simon Courtois']
|
|
10
9
|
spec.email = ['andi@codeplant.ch']
|
|
11
|
-
spec.description =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
spec.summary =
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
spec.description = 'With the simple-navigation gem installed you can easily ' \
|
|
11
|
+
'create multilevel navigations for your Rails, Sinatra or ' \
|
|
12
|
+
'Padrino applications. The navigation is defined in a ' \
|
|
13
|
+
'single configuration file. It supports automatic as well ' \
|
|
14
|
+
'as explicit highlighting of the currently active ' \
|
|
15
|
+
'navigation through regular expressions.'
|
|
16
|
+
spec.summary = 'simple-navigation is a ruby library for creating navigations ' \
|
|
17
|
+
'(with multiple levels) for your Rails, Sinatra or ' \
|
|
18
|
+
'Padrino application.'
|
|
20
19
|
spec.homepage = 'http://github.com/codeplant/simple-navigation'
|
|
21
20
|
spec.license = 'MIT'
|
|
22
21
|
|
|
23
22
|
spec.files = `git ls-files -z`.split("\x0")
|
|
24
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
25
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
26
|
-
spec.require_paths = ['lib']
|
|
27
23
|
|
|
28
24
|
spec.rdoc_options = ['--inline-source', '--charset=UTF-8']
|
|
29
25
|
|
|
30
|
-
spec.
|
|
31
|
-
spec.add_runtime_dependency 'ostruct'
|
|
26
|
+
spec.required_ruby_version = '>= 3.0.0'
|
|
32
27
|
|
|
33
|
-
spec.
|
|
34
|
-
spec.
|
|
35
|
-
spec.
|
|
36
|
-
spec.add_development_dependency 'guard-rspec', '~> 4.2'
|
|
37
|
-
spec.add_development_dependency 'memfs', '~> 0.4.1'
|
|
38
|
-
spec.add_development_dependency 'rake'
|
|
39
|
-
spec.add_development_dependency 'rdoc'
|
|
40
|
-
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
41
|
-
spec.add_development_dependency 'tzinfo', '>= 0'
|
|
28
|
+
spec.add_dependency 'activesupport', '>= 6.1.0'
|
|
29
|
+
spec.add_dependency 'json'
|
|
30
|
+
spec.add_dependency 'zeitwerk'
|
|
42
31
|
end
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
SimpleNavigation::Configuration.run do |navigation|
|
|
2
4
|
navigation.items do |nav|
|
|
3
|
-
nav.item :
|
|
4
|
-
nav.item :
|
|
5
|
+
nav.item :item1, 'Item 1', '/item_1', html: { class: 'item_1' }, link_html: { id: 'link_1' }
|
|
6
|
+
nav.item :item2, 'Item 2', '/item_2', html: { class: 'item_2' }, link_html: { id: 'link_2' }
|
|
5
7
|
end
|
|
6
8
|
end
|
data/spec/fake_app/rails_app.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
ENV['RAILS_ENV'] ||= 'test'
|
|
2
4
|
|
|
3
5
|
require 'action_controller/railtie'
|
|
@@ -9,20 +11,20 @@ module RailsApp
|
|
|
9
11
|
config.cache_classes = true
|
|
10
12
|
config.eager_load = false
|
|
11
13
|
config.root = __dir__
|
|
12
|
-
config.secret_token = 'x'*100
|
|
14
|
+
config.secret_token = 'x' * 100
|
|
13
15
|
config.session_store :cookie_store, key: '_myapp_session'
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
class TestsController < ActionController::Base
|
|
17
19
|
def base
|
|
18
|
-
render inline: <<-
|
|
20
|
+
render inline: <<-HTML
|
|
19
21
|
<!DOCTYPE html>
|
|
20
22
|
<html>
|
|
21
23
|
<body>
|
|
22
24
|
<%= render_navigation %>
|
|
23
25
|
</body>
|
|
24
26
|
</html>
|
|
25
|
-
|
|
27
|
+
HTML
|
|
26
28
|
end
|
|
27
29
|
end
|
|
28
30
|
end
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
RSpec.feature 'Rendering navigation' do
|
|
2
4
|
background do
|
|
3
5
|
SimpleNavigation.set_env(RailsApp::Application.root, 'test')
|
|
4
6
|
end
|
|
5
7
|
|
|
6
|
-
scenario 'Rendering basic navigation', type: :feature do
|
|
8
|
+
scenario 'Rendering basic navigation', type: :feature do # rubocop:disable RSpec/MultipleExpectations
|
|
7
9
|
visit '/base_spec'
|
|
8
10
|
|
|
9
|
-
expect(page).to
|
|
10
|
-
expect(page).to
|
|
11
|
-
expect(page).to
|
|
12
|
-
expect(page).to
|
|
11
|
+
expect(page).to have_text('Item 1')
|
|
12
|
+
expect(page).to have_text('Item 2')
|
|
13
|
+
expect(page).to have_css('li.item_1 a#link_1')
|
|
14
|
+
expect(page).to have_css('li.item_2 a#link_2')
|
|
13
15
|
end
|
|
14
16
|
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# NOTE: This adapter is deprecated. It supports Nanoc3 (circa 2011-2012) which is obsolete.
|
|
4
|
+
# These tests are maintained for backward compatibility only.
|
|
5
|
+
RSpec.describe SimpleNavigation::Adapters::Nanoc do
|
|
6
|
+
let(:adapter) { described_class.new(context) }
|
|
7
|
+
let(:context) { double(:context, item: item) }
|
|
8
|
+
let(:item) { double(:item, path: '/test/path/') }
|
|
9
|
+
|
|
10
|
+
describe '.register' do
|
|
11
|
+
let(:nanoc_context) { double(:nanoc_context) }
|
|
12
|
+
|
|
13
|
+
before do
|
|
14
|
+
stub_const('Nanoc3::Context', nanoc_context)
|
|
15
|
+
allow(SimpleNavigation).to receive(:set_env)
|
|
16
|
+
allow(nanoc_context).to receive(:include)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'calls SimpleNavigation.set_env with root and development environment' do
|
|
20
|
+
expect(SimpleNavigation).to receive(:set_env).with('/root/path', 'development')
|
|
21
|
+
described_class.register('/root/path')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'includes SimpleNavigation::Helpers in Nanoc3::Context' do
|
|
25
|
+
expect(nanoc_context).to receive(:include).with(SimpleNavigation::Helpers)
|
|
26
|
+
described_class.register('/root/path')
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe '#initialize' do
|
|
31
|
+
it 'sets the context' do
|
|
32
|
+
expect(adapter.instance_variable_get(:@context)).to eq context
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe '#context_for_eval' do
|
|
37
|
+
it 'returns the context' do
|
|
38
|
+
expect(adapter.context_for_eval).to eq context
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe '#current_page?' do
|
|
43
|
+
context 'when the path matches the url (after chomping the trailing slash)' do
|
|
44
|
+
it 'returns true' do
|
|
45
|
+
expect(adapter.current_page?('/test/path')).to be true
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context 'when the path does not match the url' do
|
|
50
|
+
it 'returns false' do
|
|
51
|
+
expect(adapter.current_page?('/other/path')).to be false
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context 'when path is nil' do
|
|
56
|
+
let(:item) { double(:item, path: nil) }
|
|
57
|
+
|
|
58
|
+
it 'returns nil' do
|
|
59
|
+
expect(adapter.current_page?('/test/path')).to be_nil
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe '#link_to' do
|
|
65
|
+
it 'returns a link with the correct attributes' do
|
|
66
|
+
link = adapter.link_to('Test Link', '/url', class: 'nav-link', id: 'link1')
|
|
67
|
+
expect(link).to eq "<a href='/url' class='nav-link' id='link1'>Test Link</a>"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'handles options without values' do
|
|
71
|
+
link = adapter.link_to('Test', '/url', {})
|
|
72
|
+
expect(link).to eq "<a href='/url' >Test</a>"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'filters out nil values' do
|
|
76
|
+
link = adapter.link_to('Test', '/url', class: 'nav', id: nil)
|
|
77
|
+
expect(link).to eq "<a href='/url' class='nav'>Test</a>"
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
describe '#content_tag' do
|
|
82
|
+
it 'returns a tag with the correct type, content and attributes' do
|
|
83
|
+
tag = adapter.content_tag(:div, 'Content', class: 'container', id: 'main')
|
|
84
|
+
expect(tag).to eq "<div class='container' id='main'>Content</div>"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'handles tags without attributes' do
|
|
88
|
+
tag = adapter.content_tag(:span, 'Text', {})
|
|
89
|
+
expect(tag).to eq '<span >Text</span>'
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'filters out nil values from attributes' do
|
|
93
|
+
tag = adapter.content_tag(:p, 'Paragraph', class: 'text', id: nil)
|
|
94
|
+
expect(tag).to eq "<p class='text'>Paragraph</p>"
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -1,27 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
module Adapters
|
|
3
|
-
describe Padrino do
|
|
4
|
-
let(:adapter) { SimpleNavigation::Adapters::Padrino.new(context) }
|
|
5
|
-
let(:content) { double(:content) }
|
|
6
|
-
let(:context) { double(:context, request: request) }
|
|
7
|
-
let(:request) { double(:request) }
|
|
1
|
+
# frozen_string_literal: true
|
|
8
2
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
end
|
|
15
|
-
end
|
|
3
|
+
RSpec.describe SimpleNavigation::Adapters::Padrino do
|
|
4
|
+
let(:adapter) { described_class.new(context) }
|
|
5
|
+
let(:content) { double(:content) }
|
|
6
|
+
let(:context) { double(:context, request: request) }
|
|
7
|
+
let(:request) { double(:request) }
|
|
16
8
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
describe '.register' do
|
|
10
|
+
let(:padrino_module) { Module.new }
|
|
11
|
+
let(:padrino_application) { Module.new }
|
|
12
|
+
|
|
13
|
+
before do
|
|
14
|
+
stub_const('Padrino', padrino_module)
|
|
15
|
+
stub_const('Padrino::Application', padrino_application)
|
|
16
|
+
allow(padrino_module).to receive_messages(root: '/padrino/root', env: 'production')
|
|
17
|
+
allow(SimpleNavigation).to receive(:set_env)
|
|
18
|
+
allow(padrino_application).to receive(:send)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'calls SimpleNavigation.set_env with Padrino root and env' do
|
|
22
|
+
expect(SimpleNavigation).to receive(:set_env).with('/padrino/root', 'production')
|
|
23
|
+
described_class.register(nil)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'includes SimpleNavigation::Helpers in Padrino::Application' do
|
|
27
|
+
expect(padrino_application).to receive(:send).with(:helpers, SimpleNavigation::Helpers)
|
|
28
|
+
described_class.register(nil)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe '#link_to' do
|
|
33
|
+
it 'delegates to context' do
|
|
34
|
+
expect(context).to receive(:link_to).with('name', 'url', { my_option: true })
|
|
35
|
+
adapter.link_to('name', 'url', my_option: true)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe '#content_tag' do
|
|
40
|
+
it 'delegates to context' do # rubocop:disable RSpec/MultipleExpectations
|
|
41
|
+
expect(content).to receive(:html_safe).and_return('content') # rubocop:disable RSpec/StubbedMock
|
|
42
|
+
expect(context).to receive(:content_tag).with('type', 'content', { my_option: true })
|
|
43
|
+
adapter.content_tag('type', content, my_option: true)
|
|
25
44
|
end
|
|
26
45
|
end
|
|
27
46
|
end
|