menu_builder 0.4.2 → 0.5
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 +7 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +137 -0
- data/Gemfile.lock +69 -0
- data/README.rdoc +16 -91
- data/lib/menu_builder/controller.rb +13 -5
- data/lib/menu_builder/helper.rb +9 -7
- data/lib/menu_builder/version.rb +1 -1
- data/menu_builder.gemspec +7 -7
- data/test/controller_test.rb +17 -25
- data/test/helper_test.rb +26 -0
- data/test/support/controllers.rb +57 -4
- data/test/test_helper.rb +23 -16
- metadata +81 -73
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: bd40fb9093c6a9304773af1f8d1df754a9b1b6f73892e2a32fea0b0eff1ce2e8
|
|
4
|
+
data.tar.gz: f2338b661e62a06aa7bbc00e6ca95267ac2be218678795a113fd93f7454bd77e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6286c8604678a2f7d6e0b9a540663bbe0677a1c77ae7512f719570676fc38c5fd370f1f40b0f70c73800c3f0ac2a9e64e3e2402743ab62d3c5a2c09155fe6a6d
|
|
7
|
+
data.tar.gz: 077b99f82df070266dea96fdae091e4f7d916531b45c2f7c5cbe59f97d123214e49ed737ae8bcd62d6fc6863327cc1a084eb137dfbc527585ad28210262b435e
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
require:
|
|
2
|
+
- rubocop-rails
|
|
3
|
+
|
|
4
|
+
AllCops:
|
|
5
|
+
Exclude:
|
|
6
|
+
- db/schema.rb
|
|
7
|
+
- db/**
|
|
8
|
+
TargetRubyVersion: 3.0
|
|
9
|
+
NewCops: enable
|
|
10
|
+
|
|
11
|
+
Rails:
|
|
12
|
+
Enabled: true
|
|
13
|
+
|
|
14
|
+
Rails/Validation:
|
|
15
|
+
Enabled: false
|
|
16
|
+
|
|
17
|
+
Rails/Delegate:
|
|
18
|
+
Enabled: false
|
|
19
|
+
|
|
20
|
+
Rails/DynamicFindBy:
|
|
21
|
+
Whitelist:
|
|
22
|
+
- find_by_expiring_token
|
|
23
|
+
- find_by_alias
|
|
24
|
+
- find_by_unicode
|
|
25
|
+
|
|
26
|
+
Rails/UnknownEnv:
|
|
27
|
+
Environments:
|
|
28
|
+
- production
|
|
29
|
+
- development
|
|
30
|
+
- test
|
|
31
|
+
- staging
|
|
32
|
+
|
|
33
|
+
Rails/HasAndBelongsToMany:
|
|
34
|
+
Enabled: false
|
|
35
|
+
|
|
36
|
+
Rails/InverseOf:
|
|
37
|
+
Enabled: false
|
|
38
|
+
|
|
39
|
+
Rails/I18nLocaleTexts:
|
|
40
|
+
Enabled: false
|
|
41
|
+
|
|
42
|
+
Style/MultilineBlockChain:
|
|
43
|
+
Enabled: false
|
|
44
|
+
|
|
45
|
+
Style/Documentation:
|
|
46
|
+
Enabled: false
|
|
47
|
+
|
|
48
|
+
Style/Alias:
|
|
49
|
+
Enabled: false
|
|
50
|
+
|
|
51
|
+
Style/GuardClause:
|
|
52
|
+
Enabled: false
|
|
53
|
+
|
|
54
|
+
Style/NegatedIf:
|
|
55
|
+
Enabled: false
|
|
56
|
+
|
|
57
|
+
Style/SymbolProc:
|
|
58
|
+
Enabled: false
|
|
59
|
+
|
|
60
|
+
Style/Semicolon:
|
|
61
|
+
Enabled: false
|
|
62
|
+
|
|
63
|
+
Style/RegexpLiteral:
|
|
64
|
+
Enabled: false
|
|
65
|
+
|
|
66
|
+
Naming/AccessorMethodName:
|
|
67
|
+
Enabled: false
|
|
68
|
+
|
|
69
|
+
Style/ClassAndModuleChildren:
|
|
70
|
+
Enabled: false
|
|
71
|
+
|
|
72
|
+
Style/FormatString:
|
|
73
|
+
Enabled: false
|
|
74
|
+
|
|
75
|
+
Style/FrozenStringLiteralComment:
|
|
76
|
+
EnforcedStyle: never
|
|
77
|
+
|
|
78
|
+
Style/IfUnlessModifier:
|
|
79
|
+
Enabled: false
|
|
80
|
+
|
|
81
|
+
Style/NumericPredicate:
|
|
82
|
+
Enabled: false
|
|
83
|
+
|
|
84
|
+
Metrics/PerceivedComplexity:
|
|
85
|
+
Max: 15
|
|
86
|
+
|
|
87
|
+
Layout/LineLength:
|
|
88
|
+
Exclude:
|
|
89
|
+
- config/routes.rb
|
|
90
|
+
- config/routes/marketing.rb
|
|
91
|
+
Max: 120
|
|
92
|
+
|
|
93
|
+
Layout/DotPosition:
|
|
94
|
+
EnforcedStyle: trailing
|
|
95
|
+
Enabled: true
|
|
96
|
+
|
|
97
|
+
Naming/PredicateName:
|
|
98
|
+
Enabled: false
|
|
99
|
+
|
|
100
|
+
Style/StringLiterals:
|
|
101
|
+
EnforcedStyle: double_quotes
|
|
102
|
+
|
|
103
|
+
Style/LambdaCall:
|
|
104
|
+
Enabled: false
|
|
105
|
+
|
|
106
|
+
Style/Lambda:
|
|
107
|
+
Enabled: false
|
|
108
|
+
|
|
109
|
+
Style/NumericLiterals:
|
|
110
|
+
Enabled: false
|
|
111
|
+
|
|
112
|
+
Style/SingleLineMethods:
|
|
113
|
+
Enabled: false
|
|
114
|
+
|
|
115
|
+
Metrics/MethodLength:
|
|
116
|
+
Max: 50
|
|
117
|
+
|
|
118
|
+
Metrics/ModuleLength:
|
|
119
|
+
Enabled: false
|
|
120
|
+
|
|
121
|
+
Metrics/CyclomaticComplexity:
|
|
122
|
+
Enabled: false
|
|
123
|
+
|
|
124
|
+
Metrics/AbcSize:
|
|
125
|
+
Enabled: false
|
|
126
|
+
|
|
127
|
+
Bundler/OrderedGems:
|
|
128
|
+
Enabled: false
|
|
129
|
+
|
|
130
|
+
Metrics/BlockLength:
|
|
131
|
+
Enabled: false
|
|
132
|
+
|
|
133
|
+
Metrics/ClassLength:
|
|
134
|
+
Enabled: false
|
|
135
|
+
|
|
136
|
+
Style/EmptyMethod:
|
|
137
|
+
Enabled: false
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
menu_builder (1.0.0)
|
|
5
|
+
actionpack (> 6.0)
|
|
6
|
+
activemodel (> 6.0)
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: http://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
actionpack (7.0.2.3)
|
|
12
|
+
actionview (= 7.0.2.3)
|
|
13
|
+
activesupport (= 7.0.2.3)
|
|
14
|
+
rack (~> 2.0, >= 2.2.0)
|
|
15
|
+
rack-test (>= 0.6.3)
|
|
16
|
+
rails-dom-testing (~> 2.0)
|
|
17
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
18
|
+
actionview (7.0.2.3)
|
|
19
|
+
activesupport (= 7.0.2.3)
|
|
20
|
+
builder (~> 3.1)
|
|
21
|
+
erubi (~> 1.4)
|
|
22
|
+
rails-dom-testing (~> 2.0)
|
|
23
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
24
|
+
activemodel (7.0.2.3)
|
|
25
|
+
activesupport (= 7.0.2.3)
|
|
26
|
+
activesupport (7.0.2.3)
|
|
27
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
28
|
+
i18n (>= 1.6, < 2)
|
|
29
|
+
minitest (>= 5.1)
|
|
30
|
+
tzinfo (~> 2.0)
|
|
31
|
+
builder (3.2.4)
|
|
32
|
+
concurrent-ruby (1.1.10)
|
|
33
|
+
crass (1.0.6)
|
|
34
|
+
erubi (1.10.0)
|
|
35
|
+
i18n (1.10.0)
|
|
36
|
+
concurrent-ruby (~> 1.0)
|
|
37
|
+
loofah (2.16.0)
|
|
38
|
+
crass (~> 1.0.2)
|
|
39
|
+
nokogiri (>= 1.5.9)
|
|
40
|
+
minitest (5.15.0)
|
|
41
|
+
nokogiri (1.13.4-x86_64-darwin)
|
|
42
|
+
racc (~> 1.4)
|
|
43
|
+
racc (1.6.0)
|
|
44
|
+
rack (2.2.3)
|
|
45
|
+
rack-test (1.1.0)
|
|
46
|
+
rack (>= 1.0, < 3)
|
|
47
|
+
rails-controller-testing (1.0.5)
|
|
48
|
+
actionpack (>= 5.0.1.rc1)
|
|
49
|
+
actionview (>= 5.0.1.rc1)
|
|
50
|
+
activesupport (>= 5.0.1.rc1)
|
|
51
|
+
rails-dom-testing (2.0.3)
|
|
52
|
+
activesupport (>= 4.2.0)
|
|
53
|
+
nokogiri (>= 1.6)
|
|
54
|
+
rails-html-sanitizer (1.4.2)
|
|
55
|
+
loofah (~> 2.3)
|
|
56
|
+
rake (13.0.6)
|
|
57
|
+
tzinfo (2.0.4)
|
|
58
|
+
concurrent-ruby (~> 1.0)
|
|
59
|
+
|
|
60
|
+
PLATFORMS
|
|
61
|
+
x86_64-darwin-21
|
|
62
|
+
|
|
63
|
+
DEPENDENCIES
|
|
64
|
+
menu_builder!
|
|
65
|
+
rails-controller-testing
|
|
66
|
+
rake
|
|
67
|
+
|
|
68
|
+
BUNDLED WITH
|
|
69
|
+
2.2.32
|
data/README.rdoc
CHANGED
|
@@ -1,24 +1,13 @@
|
|
|
1
1
|
= menu_builder
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
in controller. Easy like always should be!
|
|
3
|
+
A simple helper + controller macro to make easier to highligh menu items based on actions (instead of urls)
|
|
5
4
|
|
|
6
5
|
== Instalation
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
gem.config "menu_builder", :version => '0.2.1'
|
|
11
|
-
|
|
12
|
-
Rails3
|
|
13
|
-
|
|
14
|
-
gem "menu_builder", '>=0.4.1'
|
|
7
|
+
gem "menu_builder"
|
|
15
8
|
|
|
16
9
|
== Usage
|
|
17
10
|
|
|
18
|
-
Just install the plugin and see the example below:
|
|
19
|
-
|
|
20
|
-
== Example
|
|
21
|
-
|
|
22
11
|
=== Controller
|
|
23
12
|
|
|
24
13
|
class DashboardController < ApplicationController
|
|
@@ -26,17 +15,28 @@ Just install the plugin and see the example below:
|
|
|
26
15
|
...
|
|
27
16
|
end
|
|
28
17
|
|
|
29
|
-
You can also change to menu item
|
|
18
|
+
You can also change to menu item at action level instead of class level.
|
|
30
19
|
|
|
31
20
|
class DashboardController < ApplicationController
|
|
32
21
|
menu_item :mydashboard
|
|
33
|
-
|
|
22
|
+
|
|
34
23
|
def prices
|
|
35
24
|
menu_item :prices
|
|
36
25
|
...
|
|
37
26
|
end
|
|
38
27
|
end
|
|
39
28
|
|
|
29
|
+
And you can prepend or append just one item to the collection
|
|
30
|
+
|
|
31
|
+
class DashboardController < ApplicationController
|
|
32
|
+
menu_item :mydashboard
|
|
33
|
+
|
|
34
|
+
def prices
|
|
35
|
+
append_menu_item :prices
|
|
36
|
+
...
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
40
|
=== View
|
|
41
41
|
|
|
42
42
|
==== ERB code
|
|
@@ -59,8 +59,7 @@ You can also change to menu item in action level instead of class level:
|
|
|
59
59
|
|
|
60
60
|
==== Blocks for content
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
In this way you can create menu item with icons. Like below:
|
|
62
|
+
You can also pass blocks:
|
|
64
63
|
|
|
65
64
|
<%= menu do |m| %>
|
|
66
65
|
<% m.account account_path do %>
|
|
@@ -69,77 +68,3 @@ In this way you can create menu item with icons. Like below:
|
|
|
69
68
|
<%= m.users "Users", users_path %>
|
|
70
69
|
<%= m.posts "Posts", posts_path %>
|
|
71
70
|
<% end %>
|
|
72
|
-
|
|
73
|
-
== CSS and HTML
|
|
74
|
-
|
|
75
|
-
This plugin don't came with any kind of asset like image or css.
|
|
76
|
-
The layout of menu depends of your css. You can use any kind of CSS technique you want,
|
|
77
|
-
like below:
|
|
78
|
-
|
|
79
|
-
<html>
|
|
80
|
-
<head>
|
|
81
|
-
<style type="text/css" charset="utf-8">
|
|
82
|
-
#header ul { font-family:Tahoma; position: absolute; margin:0; list-style:none; }
|
|
83
|
-
#header li { display:inline; margin:0; padding:0; }
|
|
84
|
-
|
|
85
|
-
#header a {
|
|
86
|
-
float:left;
|
|
87
|
-
background: url(corner_left.jpg) no-repeat left top;
|
|
88
|
-
margin:0;
|
|
89
|
-
padding:0 0 0 4px;
|
|
90
|
-
text-decoration:none;
|
|
91
|
-
}
|
|
92
|
-
#header a span {
|
|
93
|
-
float:left;
|
|
94
|
-
display:block;
|
|
95
|
-
background: url(corner_right.jpg) no-repeat right top;
|
|
96
|
-
padding:4px 14px 4px 6px;
|
|
97
|
-
color:#FFF;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
#header a:hover span { color:#FFF; }
|
|
101
|
-
#header a:hover { background-position:0% -43px; }
|
|
102
|
-
#header a:hover span { background-position:100% -43px; }
|
|
103
|
-
#header #current a { background-position:0% -43px; }
|
|
104
|
-
#header #current a span { background-position:100% -43px; }
|
|
105
|
-
</style>
|
|
106
|
-
</head>
|
|
107
|
-
|
|
108
|
-
<body>
|
|
109
|
-
<div id="header">
|
|
110
|
-
<ul>
|
|
111
|
-
<li><a href="#"><span>Home</span></a></li>
|
|
112
|
-
<li><a href="#"><span>Quem Somos</span></a></li>
|
|
113
|
-
<li><a href="#"><span>Portifólio</span></a></li>
|
|
114
|
-
<li><a href="#"><span>Contato</span></a></li>
|
|
115
|
-
</ul>
|
|
116
|
-
</div>
|
|
117
|
-
</body>
|
|
118
|
-
</html>
|
|
119
|
-
|
|
120
|
-
You can read a full tutorial and see a working demo of above in this
|
|
121
|
-
{link}[http://www.google.com/translate?langpair=pt|en&u=http://blog.areacriacoes.com.br//2009/1/23/bordas-arredondas-para-menus-em-abas]
|
|
122
|
-
|
|
123
|
-
== Author
|
|
124
|
-
|
|
125
|
-
Authors:: Daniel Lopes
|
|
126
|
-
Blog:: {http://blog.areacriacoes.com.br}[http://blog.areacriacoes.com.br]
|
|
127
|
-
Github:: {http://github.com/danielvlopes}[http://github.com/danielvlopes]
|
|
128
|
-
Twitter:: {danielvlopes}[http://blog.areacriacoes.com.br]
|
|
129
|
-
|
|
130
|
-
== Note on Patches/Pull Requests
|
|
131
|
-
|
|
132
|
-
* Fork the project.
|
|
133
|
-
* Make your feature addition or bug fix.
|
|
134
|
-
* Add tests for it. This is important so I don't break it in a
|
|
135
|
-
future version unintentionally.
|
|
136
|
-
* Commit, do not mess with rakefile, version, or history.
|
|
137
|
-
* Send me a pull request :)
|
|
138
|
-
|
|
139
|
-
== License
|
|
140
|
-
|
|
141
|
-
MenuBuilder is released under the MIT License.
|
|
142
|
-
|
|
143
|
-
== Copyright
|
|
144
|
-
|
|
145
|
-
Copyright (c) 2010 Daniel Lopes. See LICENSE for details.
|
|
@@ -3,21 +3,29 @@ module MenuBuilder
|
|
|
3
3
|
extend ActiveSupport::Concern
|
|
4
4
|
|
|
5
5
|
def menu_items(*items)
|
|
6
|
-
|
|
6
|
+
@menu_items = items
|
|
7
7
|
end
|
|
8
8
|
alias_method :menu_item, :menu_items
|
|
9
9
|
|
|
10
|
+
def append_menu_items(*items)
|
|
11
|
+
@menu_items += items
|
|
12
|
+
end
|
|
13
|
+
alias_method :append_menu_item, :append_menu_items
|
|
14
|
+
|
|
15
|
+
def prepend_menu_items(*items)
|
|
16
|
+
@menu_items = items + @menu_items
|
|
17
|
+
end
|
|
18
|
+
alias_method :prepend_menu_item, :prepend_menu_items
|
|
19
|
+
|
|
10
20
|
module ClassMethods
|
|
11
21
|
def menu_items(*items)
|
|
12
22
|
options = items.extract_options!
|
|
13
23
|
|
|
14
|
-
|
|
15
|
-
controller.instance_variable_set(
|
|
24
|
+
before_action(options) do |controller|
|
|
25
|
+
controller.instance_variable_set("@menu_items", items)
|
|
16
26
|
end
|
|
17
27
|
end
|
|
18
28
|
alias_method :menu_item, :menu_items
|
|
19
|
-
|
|
20
29
|
end
|
|
21
|
-
|
|
22
30
|
end
|
|
23
31
|
end
|
data/lib/menu_builder/helper.rb
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
module MenuBuilder
|
|
2
2
|
module ViewHelpers
|
|
3
3
|
def menu(options={}, &block)
|
|
4
|
-
|
|
4
|
+
current_class = options.delete :current_class
|
|
5
|
+
content_tag :ul, Menu.new(self, current_class, &block).render, options
|
|
5
6
|
end
|
|
6
7
|
|
|
7
8
|
private
|
|
@@ -23,11 +24,12 @@ module MenuBuilder
|
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
class Menu
|
|
26
|
-
def initialize(context, &block)
|
|
27
|
-
@context
|
|
28
|
-
@
|
|
29
|
-
@
|
|
30
|
-
@
|
|
27
|
+
def initialize(context, current_class="current", &block)
|
|
28
|
+
@context = context
|
|
29
|
+
@current_class = current_class || "current"
|
|
30
|
+
@menu_items = context.instance_variable_get('@menu_items')
|
|
31
|
+
@actual_items = []
|
|
32
|
+
@block = block
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
def method_missing item, *args, &block
|
|
@@ -46,7 +48,7 @@ module MenuBuilder
|
|
|
46
48
|
|
|
47
49
|
def html_options_for item
|
|
48
50
|
css_classes = []
|
|
49
|
-
css_classes << "
|
|
51
|
+
css_classes << "#{@current_class}" if included_in_current_items? item
|
|
50
52
|
css_classes << "first" if first? item
|
|
51
53
|
css_classes << "last" if last? item
|
|
52
54
|
|
data/lib/menu_builder/version.rb
CHANGED
data/menu_builder.gemspec
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
|
1
|
+
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
|
|
3
2
|
require "menu_builder/version"
|
|
4
3
|
|
|
5
4
|
Gem::Specification.new do |s|
|
|
@@ -8,9 +7,8 @@ Gem::Specification.new do |s|
|
|
|
8
7
|
s.platform = Gem::Platform::RUBY
|
|
9
8
|
s.authors = ["Daniel Lopes"]
|
|
10
9
|
s.email = ["danielvlopes@gmail.com"]
|
|
11
|
-
s.
|
|
12
|
-
s.
|
|
13
|
-
s.description = %q{helper and controller macros to define current menu item and also create the menu in view.}
|
|
10
|
+
s.summary = "minimalist solution for menus and tabs in Rails"
|
|
11
|
+
s.description = "helper and controller macros to define current menu item and also create the menu in view."
|
|
14
12
|
|
|
15
13
|
s.rubyforge_project = "menu_builder"
|
|
16
14
|
|
|
@@ -18,6 +16,8 @@ Gem::Specification.new do |s|
|
|
|
18
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
19
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
20
18
|
s.require_paths = ["lib"]
|
|
21
|
-
s.add_dependency
|
|
22
|
-
s.add_dependency
|
|
19
|
+
s.add_dependency "actionpack", ">6.0"
|
|
20
|
+
s.add_dependency "activemodel", ">6.0"
|
|
21
|
+
s.add_development_dependency "rails-controller-testing"
|
|
22
|
+
s.add_development_dependency "rake"
|
|
23
23
|
end
|
data/test/controller_test.rb
CHANGED
|
@@ -1,25 +1,5 @@
|
|
|
1
1
|
require "test_helper"
|
|
2
|
-
|
|
3
|
-
class ActiveSupport::TestCase
|
|
4
|
-
setup do
|
|
5
|
-
@routes = MenuBuilder::Routes
|
|
6
|
-
end
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
class BooksController < ApplicationController
|
|
10
|
-
menu_item :books
|
|
11
|
-
def index ; end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
class SettingsController < ApplicationController
|
|
15
|
-
menu_items :settings, :home
|
|
16
|
-
|
|
17
|
-
def index ; end
|
|
18
|
-
|
|
19
|
-
def notifications
|
|
20
|
-
menu_item :notification
|
|
21
|
-
end
|
|
22
|
-
end
|
|
2
|
+
require_relative "./support/controllers"
|
|
23
3
|
|
|
24
4
|
class BooksControllerTest < ActionController::TestCase
|
|
25
5
|
test "assigns the current tab" do
|
|
@@ -29,13 +9,25 @@ class BooksControllerTest < ActionController::TestCase
|
|
|
29
9
|
end
|
|
30
10
|
|
|
31
11
|
class SettingsControllerTest < ActionController::TestCase
|
|
32
|
-
test "
|
|
12
|
+
test "can assign more than one current tab" do
|
|
33
13
|
get :index
|
|
34
|
-
assert_equal([
|
|
14
|
+
assert_equal(%i[settings home], assigns(:menu_items))
|
|
35
15
|
end
|
|
36
16
|
|
|
37
|
-
test "
|
|
17
|
+
test "can set action level menu_items" do
|
|
38
18
|
get :notifications
|
|
39
19
|
assert_equal([:notification], assigns(:menu_items))
|
|
40
20
|
end
|
|
41
|
-
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class AuthorsControllerTest < ActionController::TestCase
|
|
24
|
+
test "ability to append items" do
|
|
25
|
+
get :profile
|
|
26
|
+
assert_equal(%i[authors author_1 profile], assigns(:menu_items))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test "that instance level menu_items override class level" do
|
|
30
|
+
get :related
|
|
31
|
+
assert_equal(%i[related authors author_1], assigns(:menu_items))
|
|
32
|
+
end
|
|
33
|
+
end
|
data/test/helper_test.rb
CHANGED
|
@@ -41,6 +41,17 @@ class HelperTest < ActionView::TestCase
|
|
|
41
41
|
assert_select "li.current", 1
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
+
test "customize the current item class" do
|
|
45
|
+
@menu_items = [:home]
|
|
46
|
+
concat(menu({:current_class => "active"}) { |m|
|
|
47
|
+
concat m.home "Home", "/"
|
|
48
|
+
concat m.contact "Store", "/store"
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
assert_select "li.current", 0
|
|
52
|
+
assert_select "li.active", 1
|
|
53
|
+
end
|
|
54
|
+
|
|
44
55
|
test "accept more than one menu item" do
|
|
45
56
|
@menu_items = [:settings, :notifications]
|
|
46
57
|
|
|
@@ -53,6 +64,20 @@ class HelperTest < ActionView::TestCase
|
|
|
53
64
|
assert_select "li.current", 2
|
|
54
65
|
end
|
|
55
66
|
|
|
67
|
+
test "accept more than one menu item for a custom current item class" do
|
|
68
|
+
@menu_items = [:settings, :notifications]
|
|
69
|
+
|
|
70
|
+
concat(menu({:current_class => "active"}) { |m|
|
|
71
|
+
concat m.home "Home", "/"
|
|
72
|
+
concat m.notifications "Notifications", "/notifications"
|
|
73
|
+
concat m.settings "Settings", "/settings"
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
assert_select "li.current", 0
|
|
77
|
+
assert_select "li.active", 2
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
|
|
56
81
|
test "accept more than one menu" do
|
|
57
82
|
@menu_items = [:settings, :notifications]
|
|
58
83
|
|
|
@@ -95,4 +120,5 @@ class HelperTest < ActionView::TestCase
|
|
|
95
120
|
|
|
96
121
|
assert_select "ul > li > a > img"
|
|
97
122
|
end
|
|
123
|
+
|
|
98
124
|
end
|
data/test/support/controllers.rb
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
MenuBuilder::Routes = ActionDispatch::Routing::RouteSet.new
|
|
2
|
+
MenuBuilder::Routes.draw do
|
|
3
|
+
get "books" => "books#index"
|
|
4
|
+
|
|
5
|
+
get "author/profile" => "authors#profile"
|
|
6
|
+
get "author/related" => "authors#related"
|
|
7
|
+
|
|
8
|
+
get "settings" => "settings#index"
|
|
9
|
+
get "settings/notifications" => "settings#notifications"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class ApplicationController < ActionController::Base; end
|
|
13
|
+
ActionController::Base.send :include, MenuBuilder::Routes.url_helpers
|
|
14
|
+
|
|
15
|
+
class ActiveSupport::TestCase
|
|
16
|
+
setup do
|
|
17
|
+
@routes = MenuBuilder::Routes
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class BooksController < ApplicationController
|
|
22
|
+
menu_item :books
|
|
23
|
+
def index
|
|
24
|
+
head :ok
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class SettingsController < ApplicationController
|
|
29
|
+
menu_items :settings, :home
|
|
30
|
+
|
|
31
|
+
def index
|
|
32
|
+
head :ok
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def notifications
|
|
36
|
+
menu_item :notification
|
|
37
|
+
head :ok
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class AuthorsController < ApplicationController
|
|
42
|
+
before_action :set_base_items
|
|
43
|
+
|
|
44
|
+
def profile
|
|
45
|
+
append_menu_item :profile
|
|
46
|
+
head :ok
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def related
|
|
50
|
+
prepend_menu_item :related
|
|
51
|
+
head :ok
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def set_base_items
|
|
57
|
+
menu_item :authors, :author_1
|
|
5
58
|
end
|
|
6
59
|
end
|
data/test/test_helper.rb
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
|
-
require
|
|
2
|
-
require 'test/unit'
|
|
1
|
+
require "rubygems"
|
|
3
2
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require
|
|
8
|
-
require
|
|
3
|
+
require "active_support/testing/autorun"
|
|
4
|
+
require "abstract_controller"
|
|
5
|
+
require "abstract_controller/railties/routes_helpers"
|
|
6
|
+
require "action_controller"
|
|
7
|
+
require "action_view"
|
|
8
|
+
require "action_view/testing/resolvers"
|
|
9
|
+
require "action_dispatch"
|
|
10
|
+
require "active_support/dependencies"
|
|
11
|
+
require "rails-controller-testing"
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
module Rails
|
|
14
|
+
class << self
|
|
15
|
+
def env
|
|
16
|
+
@_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "test")
|
|
17
|
+
end
|
|
12
18
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
MenuBuilder::Routes = ActionDispatch::Routing::RouteSet.new
|
|
16
|
-
MenuBuilder::Routes.draw do
|
|
17
|
-
match ':controller(/:action(/:id(.:format)))'
|
|
19
|
+
def root; end
|
|
20
|
+
end
|
|
18
21
|
end
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
Rails::Controller::Testing.install
|
|
24
|
+
|
|
25
|
+
$LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/../lib")
|
|
26
|
+
require "menu_builder"
|
|
27
|
+
|
|
28
|
+
Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f }
|
metadata
CHANGED
|
@@ -1,65 +1,84 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: menu_builder
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
5
|
-
prerelease:
|
|
6
|
-
segments:
|
|
7
|
-
- 0
|
|
8
|
-
- 4
|
|
9
|
-
- 2
|
|
10
|
-
version: 0.4.2
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: '0.5'
|
|
11
5
|
platform: ruby
|
|
12
|
-
authors:
|
|
6
|
+
authors:
|
|
13
7
|
- Daniel Lopes
|
|
14
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
15
9
|
bindir: bin
|
|
16
10
|
cert_chain: []
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
- !ruby/object:Gem::Dependency
|
|
11
|
+
date: 2022-04-20 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
21
14
|
name: actionpack
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
none: false
|
|
25
|
-
requirements:
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
26
17
|
- - ">"
|
|
27
|
-
- !ruby/object:Gem::Version
|
|
28
|
-
|
|
29
|
-
segments:
|
|
30
|
-
- 3
|
|
31
|
-
- 0
|
|
32
|
-
version: "3.0"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '6.0'
|
|
33
20
|
type: :runtime
|
|
34
|
-
version_requirements: *id001
|
|
35
|
-
- !ruby/object:Gem::Dependency
|
|
36
|
-
name: activemodel
|
|
37
21
|
prerelease: false
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '6.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: activemodel
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
41
31
|
- - ">"
|
|
42
|
-
- !ruby/object:Gem::Version
|
|
43
|
-
|
|
44
|
-
segments:
|
|
45
|
-
- 3
|
|
46
|
-
- 0
|
|
47
|
-
version: "3.0"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '6.0'
|
|
48
34
|
type: :runtime
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '6.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rails-controller-testing
|
|
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: rake
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
description: helper and controller macros to define current menu item and also create
|
|
70
|
+
the menu in view.
|
|
71
|
+
email:
|
|
52
72
|
- danielvlopes@gmail.com
|
|
53
73
|
executables: []
|
|
54
|
-
|
|
55
74
|
extensions: []
|
|
56
|
-
|
|
57
75
|
extra_rdoc_files: []
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
- .
|
|
61
|
-
- .
|
|
76
|
+
files:
|
|
77
|
+
- ".document"
|
|
78
|
+
- ".gitignore"
|
|
79
|
+
- ".rubocop.yml"
|
|
62
80
|
- Gemfile
|
|
81
|
+
- Gemfile.lock
|
|
63
82
|
- LICENSE
|
|
64
83
|
- README.rdoc
|
|
65
84
|
- Rakefile
|
|
@@ -73,40 +92,29 @@ files:
|
|
|
73
92
|
- test/helper_test.rb
|
|
74
93
|
- test/support/controllers.rb
|
|
75
94
|
- test/test_helper.rb
|
|
76
|
-
homepage:
|
|
95
|
+
homepage:
|
|
77
96
|
licenses: []
|
|
78
|
-
|
|
79
|
-
post_install_message:
|
|
97
|
+
metadata: {}
|
|
98
|
+
post_install_message:
|
|
80
99
|
rdoc_options: []
|
|
81
|
-
|
|
82
|
-
require_paths:
|
|
100
|
+
require_paths:
|
|
83
101
|
- lib
|
|
84
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
|
-
|
|
86
|
-
requirements:
|
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
|
+
requirements:
|
|
87
104
|
- - ">="
|
|
88
|
-
- !ruby/object:Gem::Version
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
version: "0"
|
|
93
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
|
-
none: false
|
|
95
|
-
requirements:
|
|
105
|
+
- !ruby/object:Gem::Version
|
|
106
|
+
version: '0'
|
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
|
+
requirements:
|
|
96
109
|
- - ">="
|
|
97
|
-
- !ruby/object:Gem::Version
|
|
98
|
-
|
|
99
|
-
segments:
|
|
100
|
-
- 0
|
|
101
|
-
version: "0"
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
version: '0'
|
|
102
112
|
requirements: []
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
signing_key:
|
|
107
|
-
specification_version: 3
|
|
113
|
+
rubygems_version: 3.2.32
|
|
114
|
+
signing_key:
|
|
115
|
+
specification_version: 4
|
|
108
116
|
summary: minimalist solution for menus and tabs in Rails
|
|
109
|
-
test_files:
|
|
117
|
+
test_files:
|
|
110
118
|
- test/controller_test.rb
|
|
111
119
|
- test/helper_test.rb
|
|
112
120
|
- test/support/controllers.rb
|