Module: RailsCom::ActiveHelper
- Defined in:
- app/helpers/rails_com/active_helper.rb
Instance Method Summary collapse
-
#active_assert(assert, expected: 'item active', unexpected: 'item') ⇒ Object
return by assert return active_assert(‘notice’ == ‘notice’, expected: ‘ui info message’, unexpected: ‘ui negative message’) #=> ‘ui info message’.
-
#active_asserts(join = true, **options) ⇒ Object
return value by each keys which is true active_asserts(active: true, item: false) #=> ‘active’.
-
#active_helper(paths: [], controllers: [], modules: [], active_class: 'item active', item_class: 'item', **options) ⇒ Object
See examples bellow: paths: active_helper paths: ‘/work/employees’ or active_helper paths: [‘/work/employees’] controllers: active_helper controllers: ‘xxx’ or active_helper controllers: [‘xxx1’, ‘admin/xxx2’] modules: active_helper modules: ‘admin/oa’ action: active_helper ‘work/employee’: [‘index’, ‘show’] params: active_helper controller: ‘users’, action: ‘show’, id: 371.
-
#active_params(active_class: 'item active', item_class: 'item', **options) ⇒ Object
return value by params active_params state: ‘xxx’.
- #filter_params(options = {}) ⇒ Object
Instance Method Details
#active_assert(assert, expected: 'item active', unexpected: 'item') ⇒ Object
return by assert return
active_assert('notice' == 'notice', expected: 'ui info message', unexpected: 'ui negative message')
#=> 'ui info message'
8 9 10 11 12 13 14 |
# File 'app/helpers/rails_com/active_helper.rb', line 8 def active_assert(assert, expected: 'item active', unexpected: 'item') if assert expected else unexpected end end |
#active_asserts(join = true, **options) ⇒ Object
return value by each keys which is true
active_asserts(active: true, item: false)
#=> 'active'
19 20 21 22 23 24 25 26 27 |
# File 'app/helpers/rails_com/active_helper.rb', line 19 def active_asserts(join = true, **) keys = .select { |_, v| v }.keys if join keys.join(' ') else keys.last.to_s end end |
#active_helper(paths: [], controllers: [], modules: [], active_class: 'item active', item_class: 'item', **options) ⇒ Object
See examples bellow: paths:
active_helper paths: '/work/employees' or active_helper paths: ['/work/employees']
controllers:
active_helper controllers: 'xxx' or active_helper controllers: ['xxx1', 'admin/xxx2']
modules:
active_helper modules: 'admin/oa'
action:
active_helper 'work/employee': ['index', 'show']
params:
active_helper controller: 'users', action: 'show', id: 371
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/helpers/rails_com/active_helper.rb', line 40 def active_helper(paths: [], controllers: [], modules: [], active_class: 'item active', item_class: 'item', **) check_parameters = .delete(:check_parameters) if paths.present? Array(paths).each do |path| return active_class if current_page?(path, check_parameters: check_parameters) end end if controllers.present? return active_class if (Array(controllers) & [controller_name, controller_path]).size > 0 end if modules.present? this_modules = controller_path.split('/') this_modules.pop _this_modules = this_modules.map.with_index { |_, index| this_modules[0, index + 1].join('/') } return active_class if (Array(modules) & _this_modules).size > 0 end return active_class if .present? && current_page?() .select { |k, _| [controller_name, controller_path].include?(k.to_s) }.each do |_, value| return active_class if Array(value).include?(action_name) end item_class end |
#active_params(active_class: 'item active', item_class: 'item', **options) ⇒ Object
return value by params
active_params state: 'xxx'
71 72 73 74 75 76 77 78 79 |
# File 'app/helpers/rails_com/active_helper.rb', line 71 def active_params(active_class: 'item active', item_class: 'item', **) .select { |_, v| v.present? }.each do |k, v| if params[k].to_s == v.to_s return active_class end end item_class end |
#filter_params(options = {}) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/helpers/rails_com/active_helper.rb', line 81 def filter_params( = {}) except = .delete(:except) only = .delete(:only) query = ActionController::Parameters.new(request.GET) query.merge!() if only query = query.permit(only) else excepts = [] excepts += (Array(except).map(&:to_s) & request.GET.keys) excepts += ['commit', 'utf8', 'page'] query = query.permit!.except(*excepts) end query.reject! { |_, value| value.blank? } query end |