Module: SelectionHelper

Defined in:
lib/coadjutor/selection_helper.rb

Instance Method Summary collapse

Instance Method Details

#selected_if_current(path_to_match, current_path = request.fullpath) ⇒ Object



2
3
4
# File 'lib/coadjutor/selection_helper.rb', line 2

def selected_if_current(path_to_match, current_path = request.fullpath)
  current_path == path_to_match ? 'selected' : ''
end

#selected_if_params_match(params_to_match, options = {:default => {}}) ⇒ Object



6
7
8
9
10
# File 'lib/coadjutor/selection_helper.rb', line 6

def selected_if_params_match(params_to_match, options = {:default => {}})
  current_params = request.query_parameters.empty? ? options[:default] : request.query_parameters

  current_params == params_to_match ? 'selected' : ''
end

#selected_if_url_matches(string_to_match, options = {:default => {}}) ⇒ Object



12
13
14
15
16
17
# File 'lib/coadjutor/selection_helper.rb', line 12

def selected_if_url_matches(string_to_match, options = {:default => {}})
  path_with_params = [request.fullpath, request.query_parameters.to_param].select(&:present?).join '?'
  content_to_match = path_with_params == options[:default][:if_path_equals] ? options[:default][:then_match] : path_with_params

  content_to_match.include?(string_to_match) ? 'selected' : ''
end