module Breezy::Helpers

Constants

POSSIBLE_STANDARD_NAMES

Public Instance Methods

param_to_search_path(param) click to toggle source
# File lib/breezy/helpers.rb, line 526
def param_to_search_path(param)
  if param
    param.gsub(/[^\da-zA-Z\_\=\.]+/, '')
      .gsub(/\.+/, '.')
      .split('.')
      .map do |part|
        if part =~ /^-?[0-9]+$/
          part.to_i
        else
          part
        end
      end
  end
end
props_from_form_with(model: nil, scope: nil, url: nil, format: nil, **options) click to toggle source
# File lib/breezy/helpers.rb, line 505
def props_from_form_with(model: nil, scope: nil, url: nil, format: nil, **options)
  options[:allow_method_names_outside_object] = true
  options[:skip_default_ids] = !helpers.send(:form_with_generates_ids)

  if model
    url ||= helpers.send(:polymorphic_path, model, format: format)

    model   = model.last if model.is_a?(Array)
    scope ||= helpers.send(:model_name_from_record_or_class, model).param_key
  end

  html_options = helpers.send(:html_options_for_form_with, url, model, options)
  html_options.delete("authenticity_token")
  html_options.delete("enforce_utf8")

  key_vals = html_options.map { |k, v|
    [POSSIBLE_STANDARD_NAMES[k.to_sym] || k.camelize(:lower), v]
  }
  Hash[key_vals]
end
redirect_back_with_bzq(opts) click to toggle source
# File lib/breezy/helpers.rb, line 491
def redirect_back_with_bzq(opts)
  if request.referrer && params[:bzq]
    referrer_url = URI.parse(request.referrer)
    referrer_url.query = Rack::Utils
      .parse_nested_query(referrer_url.query)
      .merge({bzq: params[:bzq]})
      .to_query

    redirect_to referrer_url.to_s, opts
  else
    redirect_back(opts)
  end
end
search_path_to_camelized_param(path) click to toggle source
# File lib/breezy/helpers.rb, line 541
def search_path_to_camelized_param(path)
  path.map do |part|
    if part.include? '='
      key, rest = part.split('=')
      [key.camelize(:lower), rest].join('=')
    else
      part.camelize(:lower)
    end
  end.join('.')
end