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
active_assert(‘notice’ == ‘notice’, expected: ‘ui info message’, unexpected: ‘ui negative message’).
-
#active_asserts(join: true, **options) ⇒ Object
active_asserts(‘active’: true, expected: false).
-
#active_helper(paths: [], controllers: [], modules: [], active_class: 'item active', item_class: 'item', **options) ⇒ Object
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_params state: ‘xxx’ active_helper controller: ‘users’, action: ‘show’, id: 371.
- #active_params(active_class: 'item active', item_class: 'item', **options) ⇒ Object
- #filter_params(options = {}) ⇒ Object
Instance Method Details
#active_assert(assert, expected: 'item active', unexpected: 'item') ⇒ Object
active_assert(‘notice’ == ‘notice’, expected: ‘ui info message’, unexpected: ‘ui negative message’)
5 6 7 8 9 10 11 |
# File 'app/helpers/rails_com/active_helper.rb', line 5 def active_assert(assert, expected: 'item active', unexpected: 'item') if assert expected else unexpected end end |
#active_asserts(join: true, **options) ⇒ Object
active_asserts(‘active’: true, expected: false)
14 15 16 17 18 19 20 21 22 |
# File 'app/helpers/rails_com/active_helper.rb', line 14 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
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_params state: ‘xxx’ active_helper controller: ‘users’, action: ‘show’, id: 371
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/helpers/rails_com/active_helper.rb', line 30 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
59 60 61 62 63 64 65 66 67 |
# File 'app/helpers/rails_com/active_helper.rb', line 59 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
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/helpers/rails_com/active_helper.rb', line 69 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 |