rails_controller_action_name_helpers 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: de1e3707f8850daf26fecc93752897711e22e332e2115782f22e9aa9f010f841
4
+ data.tar.gz: 66965ac9c83b22c2dfaea7554abe694c923e375693193bc923508ffdee8c110d
5
+ SHA512:
6
+ metadata.gz: 852b4f24e2d649a6f8f74c099d73735b228d49d407746f35107c258e31f1a1db5708184e56f94ef3a035babe772a0c1c1dabc4c1e6ef7303c770d3f2ce1a6950
7
+ data.tar.gz: b153b6970dae418628eab4f101151737c09046106e4c8c483053a2f5f0ed5cc192ba665e64c92aeff4afbce87a5a53dc6bde198c6da42a949050b238bbec138a
@@ -0,0 +1,3 @@
1
+ w�����˿U��! s�c�T?�? *�suD���,d�S�"Ni:�k9���J�����s� )lB� 
2
+ ��ǫ��K'sض�3��6-�L�)4��+�;���+_
3
+ *]�ћt/�<Vw�C��� �Ag5�N=�Y�9��A��p���ڹ�^�)�����2�/����)�Ī
Binary file
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Kaspar Vollenweider
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,16 @@
1
+ # Rails Controller Action Name Helpers
2
+
3
+ [Repository - casaper/rails_controller_action_name_helpers](https://github.com/casaper/rails_controller_action_name_helpers)
4
+ [Documentation](https://casaper.github.io/rails_controller_action_name_helpers/)
5
+
6
+ Simple view helpers to have more readable checks for current controller name or action name.
7
+
8
+ ```haml
9
+ - # this condition here
10
+ - if action_name == 'index' && (controller_name == 'members' || controller_name == 'users')
11
+ %p This will only show if the partial is run on the index action on the members or users controller
12
+ - # can be done like this
13
+ - if ca_index?(:members, :users)
14
+ %p This will only show if the partial is run on the index action on the members or users controller
15
+ ```
16
+
@@ -0,0 +1,7 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,206 @@
1
+ ## Controller Action Name Helpers
2
+ #
3
+ # Simple view helpers to determine current action and controller name in
4
+ # a more readable manner within Rails views.
5
+ module ControllerActionNameHelpers
6
+ ## Current controller name is in name or multiple names
7
+ #
8
+ # @example current controller_name is users
9
+ # controller?(:users)
10
+ # @example current controller_name is in list
11
+ # controller?(:users, 'members')
12
+ # @example use with an array of symbols
13
+ # controller?(*%i[users members guests])
14
+ # @overload controller?(controller_name)
15
+ # @param controller_name [Symbol,String] a controller name
16
+ # @overload controller?(controller_name1, controller_name2)
17
+ # @param controller_name1 [Symbol,String] a controller name
18
+ # @param controller_name2 [Symbol,String] a controller name
19
+ # @note takes unlimited amount of controller names.
20
+ # @return [Boolean] the controller name is in list
21
+ def controller?(*controller_names)
22
+ controller_names.map(&:to_s).include?(controller_name)
23
+ end
24
+ alias controller_name? controller?
25
+ alias controller_in? controller?
26
+ alias controller_name_in? controller?
27
+
28
+ ## Current action name is in name or multiple names
29
+ #
30
+ # @example current action is index
31
+ # action?(:index)
32
+ # @example current action is index or show
33
+ # action?('index', :show)
34
+ # @example use with an array of strings
35
+ # action?(*%w[index show custom])
36
+ # @overload action?(action_name)
37
+ # @param action_name [Symbol,String] a action name
38
+ # @overload action?(action_name1, action_name2)
39
+ # @param action_name1 [Symbol,String] a action name
40
+ # @param action_name2 [Symbol,String] a action name
41
+ # @note takes unlimited amount of action names.
42
+ # @return [Boolean] the action name is in action_names
43
+ def action?(*action_names)
44
+ action_names.map(&:to_s).include?(action_name)
45
+ end
46
+ alias action_name? action?
47
+ alias action_in? action?
48
+ alias action_name_in? action?
49
+
50
+ ## Current action and controller name in lists
51
+ #
52
+ # @example action name in array and controller name in array
53
+ # action_controller?(%w[index show custom], [:users, :members, 'guests'])
54
+ # @param action_names [Array(Symbol,String)] the action name list
55
+ # @param controller_names [Array(Symbol,String)] the controller name list
56
+ # @return [Bolean] the action and controller name match lists
57
+ def actions_controllers?(action_names, controller_names)
58
+ action?(*action_names) && controller?(*controller_names)
59
+ end
60
+
61
+ ## Controller of name and multiple actions
62
+ #
63
+ # @example controller users and new, create, edit or update
64
+ # controller_actions?(:users, :new, :create, :edit, :update)
65
+ # @param contr_name [Symbol,String] the controllers name
66
+ # @param action_names [List(Symbol,String)] the action names to match
67
+ # @return [Boolean] the controller is name and actions in list
68
+ def controller_actions?(contr_name, *action_names)
69
+ controller_name == contr_name.to_s && action?(*action_names)
70
+ end
71
+
72
+ ## Action of name and mutliple controllers
73
+ #
74
+ # @example action is custom and controller in list
75
+ # action_controllers?(:custom_action_name, :users, :members, :guests)
76
+ # @param act_name [Symbol,String] the controllers name
77
+ # @param controller_names [List(Symbol,String)] the action names to match
78
+ # @return [Boolean] the action is name and controllers in list
79
+ def action_controllers?(act_name, *controller_names)
80
+ action_name == act_name.to_s && controller?(*controller_names)
81
+ end
82
+
83
+ ## Current action name is index
84
+ #
85
+ def a_index?
86
+ action_name == 'index'
87
+ end
88
+ alias action_index? a_index?
89
+ alias action_name_index? a_index?
90
+
91
+ ## Current action name is show
92
+ #
93
+ def a_show?
94
+ action_name == 'show'
95
+ end
96
+ alias action_show? a_show?
97
+ alias action_name_show? a_show?
98
+
99
+ ## Current action name is new or create
100
+ #
101
+ # @note
102
+ # Often controllers do `render :new` when there is errors in forms.
103
+ # So it makes sense to be true when new or edit.
104
+ # @param without_create [Boolean] only new action
105
+ def a_new?(without_create = false)
106
+ if without_create
107
+ action_name == 'new'
108
+ else
109
+ action?(:new, :create)
110
+ end
111
+ end
112
+ alias action_new? a_new?
113
+ alias action_name_new? a_new?
114
+
115
+ ## Current action name is edit or update
116
+ #
117
+ # @note
118
+ # Often controllers do `render :edit` when there is errors in forms.
119
+ # So it makes sense to be true when new or edit.
120
+ # @param without_update [Boolean] only edit action
121
+ def a_edit?(without_update = false)
122
+ if without_update
123
+ action_name == 'edit'
124
+ else
125
+ action?(:edit, :update)
126
+ end
127
+ end
128
+ alias action_edit? a_edit?
129
+ alias action_name_edit? a_edit?
130
+
131
+ ## Current action name is index and controller name is in list
132
+ #
133
+ # @example current action is index and controller name is users
134
+ # ca_index?('users')
135
+ # @example current action is index and controller name is in list
136
+ # ca_index?(:users, :members)
137
+ # @overload ca_index?(controller_name)
138
+ # @param controller_name [Symbol,String] a controller name
139
+ # @overload ca_index?(controller_name1, controller_name2)
140
+ # @param controller_name1 [Symbol,String] a controller name
141
+ # @param controller_name2 [Symbol,String] a controller name
142
+ # @note takes unlimited amount of controller names.
143
+ # @return [Boolean] the controller name is in list
144
+ def ca_index?(*controller_names)
145
+ a_index? && controller?(*controller_names)
146
+ end
147
+ alias controller_index? ca_index?
148
+ alias controller_names_index? ca_index?
149
+
150
+ ## Current action name is show and controller name is in list
151
+ #
152
+ # @example current action is show and controller name is users
153
+ # ca_show?('users')
154
+ # @example current action is show and controller name is in list
155
+ # ca_show?(:users, :members)
156
+ # @overload ca_show?(controller_name)
157
+ # @param controller_name [Symbol,String] a controller name
158
+ # @overload ca_show?(controller_name1, controller_name2)
159
+ # @param controller_name1 [Symbol,String] a controller name
160
+ # @param controller_name2 [Symbol,String] a controller name
161
+ # @note takes unlimited amount of controller names.
162
+ # @return [Boolean] the controller name is in list
163
+ def ca_show?(*controller_names)
164
+ a_show? && controller?(*controller_names)
165
+ end
166
+ alias controller_names_show? ca_show?
167
+ alias controller_show? ca_show?
168
+
169
+ ## Current action name is new or create and controller name is in list
170
+ #
171
+ # @example current action is new or create and controller name is users
172
+ # ca_new?('users')
173
+ # @example current action is new or create and controller name is in list
174
+ # ca_new?(:users, :members)
175
+ # @overload ca_new?(controller_name)
176
+ # @param controller_name [Symbol,String] a controller name
177
+ # @overload ca_new?(controller_name1, controller_name2)
178
+ # @param controller_name1 [Symbol,String] a controller name
179
+ # @param controller_name2 [Symbol,String] a controller name
180
+ # @note takes unlimited amount of controller names.
181
+ # @return [Boolean] the controller name is in list
182
+ def ca_new?(*controller_names)
183
+ a_new? && controller?(*controller_names)
184
+ end
185
+ alias controller_names_new? ca_new?
186
+ alias controller_new? ca_new?
187
+
188
+ ## Current action name is edit or update and controller name is in list
189
+ #
190
+ # @example current action is edit or update and controller name is users
191
+ # ca_edit?('users')
192
+ # @example current action is edit or update and controller name is in list
193
+ # ca_edit?(:users, :members)
194
+ # @overload ca_edit?(controller_name)
195
+ # @param controller_name [Symbol,String] a controller name
196
+ # @overload ca_edit?(controller_name1, controller_name2)
197
+ # @param controller_name1 [Symbol,String] a controller name
198
+ # @param controller_name2 [Symbol,String] a controller name
199
+ # @note takes unlimited amount of controller names.
200
+ # @return [Boolean] the controller name is in list
201
+ def ca_edit?(*controller_names)
202
+ a_edit? && controller?(*controller_names)
203
+ end
204
+ alias controller_names_edit? ca_edit?
205
+ alias controller_edit? ca_edit?
206
+ end
@@ -0,0 +1,7 @@
1
+ require 'rails_controller_action_name_helpers/engine'
2
+
3
+ module RailsControllerActionNameHelpers
4
+ def self.setup
5
+ yield self
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rails'
2
+ require File.expand_path('../../app/helpers/controller_acttion_name_helpers', __dir__)
3
+
4
+ module RailsControllerActionNameHelpers
5
+ class Engine < Rails::Engine
6
+ initializer 'rails_controller_action_name_helpers.helper' do
7
+ ActionView::Base.include ControllerActionNameHelpers
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module RailsControllerActionNameHelpers
2
+ VERSION = '0.1.4'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_controller_action_name_helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Kaspar Vollenweider
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEJDCCAoygAwIBAgIBATANBgkqhkiG9w0BAQsFADAeMRwwGgYDVQQDDBN2b2sv
14
+ REM9cGFudGVyL0RDPWNoMB4XDTIwMDMyMjEzMjkzNloXDTIxMDMyMjEzMjkzNlow
15
+ HjEcMBoGA1UEAwwTdm9rL0RDPXBhbnRlci9EQz1jaDCCAaIwDQYJKoZIhvcNAQEB
16
+ BQADggGPADCCAYoCggGBALGEZfAbnsIsRFm3ewtpMuEH0bQz9rh/m77aQ1mKMPi/
17
+ /NTsyUZ5UlwTC02kjIujHEju3wRhtnRZEC2u3uYlaFg+xyB9McQyp32+HeMGSuCI
18
+ 6e9Pb4zKksyBd9cJwWGeCc0iJKgErXWsaGp0g38lJ9tqSFobkKhM+uW2ezsRzc7t
19
+ V3hA6u0H6zSOacXZIRSpHIizumc4/Klf2dowfaVGNonSsLBwFAMF3Hw+V4RMY3PK
20
+ p9ALhbA3qZ/7GB4y2npyj8csgwB2cQWo6ei61ZlXTQp8FZjX6tWGO8RhKqtzBkNn
21
+ G6Ap8MPDCwT8DeEv7gt1TTyzdDtyfEIpHoTdJup2bYrr2jPTPq1SkIsHKdFVhkCJ
22
+ s/hzGpW77kMaVGCJY/MmxMyzQUwdhbhYtKMpf2HrlU3HtX3n5S5Qc1t+WCRznisb
23
+ Hzr1wIGqBRhLM5zTJkDoW/kdGTJ888DUa56G+q3gNgh2EZlFU0F+gOXQ0w9wWMDA
24
+ v2dwHNA3n/Kuvtda1riEHQIDAQABo20wazAJBgNVHRMEAjAAMAsGA1UdDwQEAwIE
25
+ sDAdBgNVHQ4EFgQUw7jysEz3OgQDjaQiFTUqIVoisxgwGAYDVR0RBBEwD4ENdm9r
26
+ QHBhbnRlci5jaDAYBgNVHRIEETAPgQ12b2tAcGFudGVyLmNoMA0GCSqGSIb3DQEB
27
+ CwUAA4IBgQBSsoFVo795nkB3plaYMknXSYQYgDu3pIB9Q2zdEAXOHKJ/4HKfbWwL
28
+ YCDkriU1Qz3P9XAs0a6sbX5fSMDdpy37RGtIiTZc/YUtfLavSGNpQSzPiH1e+sx9
29
+ 2th6KqY8pCGbSNvcxt4Fe6mnZBVvBggrSohUuiaQxQaS73vCLcTSqFJ5pvv2LbIi
30
+ WxKcAQ+94LY58LcbIRzSsr5seHcDkumKvCrvt/HsZ+saKjSiw7CqcTvn/ASpYRy6
31
+ m02uL0aINVjTShY+LvbTpmhXd3c1eiu3nTLrZ08hhRmsSryKjDS1ijgx89lHdiF4
32
+ aLGqcMJ4hVUkgyETYffOXqT2+45ZFnFiZnahedbqgocpbBKTi9DieFdd6d2NJ9yt
33
+ TCV3ppoMMaZvMdyWWd9rJS/+XbIv2Qh6S4pK3bt44Iw4OZzYXt9BlVzdBQ90KqVD
34
+ H8qKJCPtHNeEY1zTzVTIrUVDmsNhQN8QW14T233pMJVaNc7YLIt14k6yj6Hshr7b
35
+ H+0mfErZQ+o=
36
+ -----END CERTIFICATE-----
37
+ date: 2020-03-22 00:00:00.000000000 Z
38
+ dependencies:
39
+ - !ruby/object:Gem::Dependency
40
+ name: rails
41
+ requirement: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">"
44
+ - !ruby/object:Gem::Version
45
+ version: 4.0.0
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">"
51
+ - !ruby/object:Gem::Version
52
+ version: 4.0.0
53
+ description: Simple helpers to have more readable checks for current controller name
54
+ or action name in rails views.
55
+ email:
56
+ - vok@panter.ch
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - LICENSE
62
+ - README.md
63
+ - Rakefile
64
+ - app/helpers/controller_acttion_name_helpers.rb
65
+ - lib/rails_controller_action_name_helpers.rb
66
+ - lib/rails_controller_action_name_helpers/engine.rb
67
+ - lib/rails_controller_action_name_helpers/version.rb
68
+ homepage: https://github.com/casaper/rails_controller_action_name_helpers
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 2.4.0
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubygems_version: 3.0.3
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Rails Controller Action Name Helpers
91
+ test_files: []
Binary file