<commit_before># encoding: UTF-8
module ApplicationHelper

  # wrapper for +content_tag+ that yields a url for +options+,
  # unless the current action matches +options+, in which case it
  # yields '#'.
  # suitable to generate navigation links.
  def content_tag_with_path_checking(tag, options = {})
    html_options = options.delete(:html) || {}

    if current_user
      options_to_match = options.reverse_merge(controller: 'ideas', action: 'index')
      is_current = (params.symbolize_keys.slice(*options_to_match.keys) == options_to_match)
      path = url_for(options_to_match)

      if is_current
        classes = html_options.fetch(:class, '').split
        classes.push 'active'
        options[:class] = classes.join(' ')
      end
    else
      path = '#'
    end

    content_tag(tag, options) do
      yield path, is_current
    end
  end

  # conditional link_to that generates a disabled link when the condition fails
  # path a boolean to the +if+ options,
  # a +can?+ array of parameters to the +auth+ option,
  # or both.
  # 
  # e.g.
  #   can_link_to foo_path, if:(a || b), auth:[:update, Stuff]
  # 
  def can_link_to(*args, &block)
    options = args.last { |arg| arg.kind_of?(Hash) }.dup

    auth_criteria  = options.delete(:auth)
    auth_condition = auth_criteria.nil? ? true : can?(*auth_criteria)
    if_condition   = options.fetch(:if, true)

    if if_condition && auth_condition
      link_to(*args, &block)
    else
      options.slice!(:class, :id)
      options[:class] = [options.fetch(:class, '').split + %w(disabled)].join(' ')
      options[:title] = not_authorized_message(*auth_criteria) if auth_criteria
      content_tag(:a, options, &block)
    end
  end
end<commit_msg>Propagates tooltip placement to authorisation links<commit_after># encoding: UTF-8
module ApplicationHelper

  # wrapper for +content_tag+ that yields a url for +options+,
  # unless the current action matches +options+, in which case it
  # yields '#'.
  # suitable to generate navigation links.
  def content_tag_with_path_checking(tag, options = {})
    html_options = options.delete(:html) || {}

    if current_user
      options_to_match = options.reverse_merge(controller: 'ideas', action: 'index')
      is_current = (params.symbolize_keys.slice(*options_to_match.keys) == options_to_match)
      path = url_for(options_to_match)

      if is_current
        classes = html_options.fetch(:class, '').split
        classes.push 'active'
        options[:class] = classes.join(' ')
      end
    else
      path = '#'
    end

    content_tag(tag, options) do
      yield path, is_current
    end
  end

  # conditional link_to that generates a disabled link when the condition fails
  # path a boolean to the +if+ options,
  # a +can?+ array of parameters to the +auth+ option,
  # or both.
  # 
  # e.g.
  #   can_link_to foo_path, if:(a || b), auth:[:update, Stuff]
  # 
  def can_link_to(*args, &block)
    options = args.last { |arg| arg.kind_of?(Hash) }.dup

    auth_criteria  = options.delete(:auth)
    auth_condition = auth_criteria.nil? ? true : can?(*auth_criteria)
    if_condition   = options.fetch(:if, true)

    if if_condition && auth_condition
      link_to(*args, &block)
    else
      options.slice!(:class, :id, :'data-placement')
      options[:class] = [options.fetch(:class, '').split + %w(disabled)].join(' ')
      options[:title] = not_authorized_message(*auth_criteria) if auth_criteria
      content_tag(:a, options, &block)
    end
  end
end
{'fraction_non_alphanumeric': 0.1213938874607255, 'fraction_numerical': 0.0005712653527563553, 'mean_word_length': 3.3234567901234566, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4648020', 'n_tokens_mistral': 1134, 'n_tokens_neox': 1105, 'n_words': 291}