menu_builder 0.4.4 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9892ebf03c1453e32f80de3f3bbbdd9da851a657
4
- data.tar.gz: d0ffd34b7f563921e9af1e25605f0b5b93eb7a95
2
+ SHA256:
3
+ metadata.gz: bd40fb9093c6a9304773af1f8d1df754a9b1b6f73892e2a32fea0b0eff1ce2e8
4
+ data.tar.gz: f2338b661e62a06aa7bbc00e6ca95267ac2be218678795a113fd93f7454bd77e
5
5
  SHA512:
6
- metadata.gz: 62dfbba5498cb7e7ae3c9013cb4f534d33615f85e0780cb9033bb57a4f8980d505d59dff52f8276c8c168c527351637bf9922655dfca7af10b43b8d54bfda9dd
7
- data.tar.gz: 786bf942fe3ec80d7b64da0397594184d597d49671fc58c2bc3503fb9fe1e3e1955ad6b3925338bf3af9d4af4da5d5fcc20a6dc26e16714f58fa89d6e0655d43
6
+ metadata.gz: 6286c8604678a2f7d6e0b9a540663bbe0677a1c77ae7512f719570676fc38c5fd370f1f40b0f70c73800c3f0ac2a9e64e3e2402743ab62d3c5a2c09155fe6a6d
7
+ data.tar.gz: 077b99f82df070266dea96fdae091e4f7d916531b45c2f7c5cbe59f97d123214e49ed737ae8bcd62d6fc6863327cc1a084eb137dfbc527585ad28210262b435e
data/.gitignore CHANGED
@@ -20,3 +20,4 @@ pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
22
  .rvmrc
23
+ .tool-versions
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,8 +1,6 @@
1
1
  = menu_builder
2
2
 
3
- A simple helper to make easier the process of highlighting menu items based on current
4
- url. The goal here is to reduce the amount of if/elses you would typically need in your
5
- views to achieve the same results.
3
+ A simple helper + controller macro to make easier to highligh menu items based on actions (instead of urls)
6
4
 
7
5
  == Instalation
8
6
 
@@ -10,8 +8,6 @@ views to achieve the same results.
10
8
 
11
9
  == Usage
12
10
 
13
- First flag at class level in your Controller which item should be highlighted
14
-
15
11
  === Controller
16
12
 
17
13
  class DashboardController < ApplicationController
@@ -19,9 +15,7 @@ First flag at class level in your Controller which item should be highlighted
19
15
  ...
20
16
  end
21
17
 
22
- You can also change to menu item at action level instead of class level. This
23
- option is helpful when you have most of the actions pointing to one menu item
24
- but a few actions pointing to another.
18
+ You can also change to menu item at action level instead of class level.
25
19
 
26
20
  class DashboardController < ApplicationController
27
21
  menu_item :mydashboard
@@ -32,6 +26,17 @@ but a few actions pointing to another.
32
26
  end
33
27
  end
34
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
+
35
40
  === View
36
41
 
37
42
  ==== ERB code
@@ -3,21 +3,29 @@ module MenuBuilder
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  def menu_items(*items)
6
- instance_variable_set('@menu_items', items)
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
24
  before_action(options) do |controller|
15
- controller.instance_variable_set('@menu_items', items)
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
@@ -1,3 +1,3 @@
1
1
  module MenuBuilder
2
- VERSION = "0.4.4"
2
+ VERSION = "0.5".freeze
3
3
  end
data/menu_builder.gemspec CHANGED
@@ -1,5 +1,4 @@
1
- # -*- encoding: utf-8 -*-
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.homepage = "http://objetiva.co/"
12
- s.summary = %q{minimalist solution for menus and tabs in Rails}
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 'actionpack', '>3.0'
22
- s.add_dependency 'activemodel', '>3.0'
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
@@ -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 "ability to assign more than one current tab" do
12
+ test "can assign more than one current tab" do
33
13
  get :index
34
- assert_equal([:settings, :home], assigns(:menu_items))
14
+ assert_equal(%i[settings home], assigns(:menu_items))
35
15
  end
36
16
 
37
- test "that instance level menu_items override class level" do
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
@@ -40,7 +40,7 @@ class HelperTest < ActionView::TestCase
40
40
 
41
41
  assert_select "li.current", 1
42
42
  end
43
-
43
+
44
44
  test "customize the current item class" do
45
45
  @menu_items = [:home]
46
46
  concat(menu({:current_class => "active"}) { |m|
@@ -63,7 +63,7 @@ class HelperTest < ActionView::TestCase
63
63
 
64
64
  assert_select "li.current", 2
65
65
  end
66
-
66
+
67
67
  test "accept more than one menu item for a custom current item class" do
68
68
  @menu_items = [:settings, :notifications]
69
69
 
@@ -76,8 +76,8 @@ class HelperTest < ActionView::TestCase
76
76
  assert_select "li.current", 0
77
77
  assert_select "li.active", 2
78
78
  end
79
-
80
-
79
+
80
+
81
81
  test "accept more than one menu" do
82
82
  @menu_items = [:settings, :notifications]
83
83
 
@@ -120,5 +120,5 @@ class HelperTest < ActionView::TestCase
120
120
 
121
121
  assert_select "ul > li > a > img"
122
122
  end
123
-
123
+
124
124
  end
@@ -1,6 +1,59 @@
1
- class ApplicationController < ActionController::Base
2
- protected
3
- def default_render
4
- render :text => action_name
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 'rubygems'
2
- require 'test/unit'
1
+ require "rubygems"
3
2
 
4
- require 'action_controller'
5
- require 'action_view'
6
- require 'action_view/template'
7
- require 'active_support'
8
- require 'rails/railtie'
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
- $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
11
- require 'menu_builder'
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
- Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f }
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
- class ApplicationController < ActionController::Base; end
21
- ActionController::Base.send :include, MenuBuilder::Routes.url_helpers
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: menu_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Lopes
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-15 00:00:00.000000000 Z
11
+ date: 2022-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -16,28 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - ">"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '6.0'
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
- version: '3.0'
26
+ version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.0'
33
+ version: '6.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.0'
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'
41
69
  description: helper and controller macros to define current menu item and also create
42
70
  the menu in view.
43
71
  email:
@@ -48,7 +76,9 @@ extra_rdoc_files: []
48
76
  files:
49
77
  - ".document"
50
78
  - ".gitignore"
79
+ - ".rubocop.yml"
51
80
  - Gemfile
81
+ - Gemfile.lock
52
82
  - LICENSE
53
83
  - README.rdoc
54
84
  - Rakefile
@@ -62,10 +92,10 @@ files:
62
92
  - test/helper_test.rb
63
93
  - test/support/controllers.rb
64
94
  - test/test_helper.rb
65
- homepage: http://objetiva.co/
95
+ homepage:
66
96
  licenses: []
67
97
  metadata: {}
68
- post_install_message:
98
+ post_install_message:
69
99
  rdoc_options: []
70
100
  require_paths:
71
101
  - lib
@@ -80,9 +110,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
110
  - !ruby/object:Gem::Version
81
111
  version: '0'
82
112
  requirements: []
83
- rubyforge_project: menu_builder
84
- rubygems_version: 2.6.12
85
- signing_key:
113
+ rubygems_version: 3.2.32
114
+ signing_key:
86
115
  specification_version: 4
87
116
  summary: minimalist solution for menus and tabs in Rails
88
117
  test_files: