<commit_before>defmodule CoursePlanner.SharedView do
  @moduledoc false
  use CoursePlanner.Web, :view

  # helpers

  def path_exact_match(conn, path) do
    conn.request_path == path
  end

  def path_match(conn, path) do
    String.starts_with? conn.request_path, path
  end

  def get_gravatar_url(email, size \\ 100) do
    hash =
      :md5
      |> :crypto.hash(email)
      |> Base.encode16()
      |> String.downcase()

    "https://www.gravatar.com/avatar/#{hash}?d=mm&s=#{size}"
  end

  def display_user_name(user) do
    [user.name, user.family_name, user.nickname && "(#{user.nickname})"]
    |> Enum.filter(fn v -> String.length(to_string v) > 0 end)
    |> Enum.join(" ")
  end

  # form components

  def form_text(form, field, opts \\ []) do
    class = opts[:class] || ""
    label = opts[:label] || humanize(field)
    required = opts[:required] || nil
    {error, _} = Keyword.get form.errors, field, {nil, nil}

    value = Map.get form.data, field
    wrapper_class =
      if error do
        "is-invalid"
      else
        if required && String.length to_string value > 0 do
          "form-init"
        else
          ""
        end
      end

    render "form_text.html", form: form,
                             field: field,
                             label: label,
                             error: error,
                             wrapper_class: wrapper_class,
                             class: class,
                             required: required
  end

  def form_textarea(form, field, opts \\ []) do
    class = opts[:class] || ""
    label = opts[:label] || humanize(field)
    required = opts[:required] || nil
    {error, _} = Keyword.get form.errors, field, {nil, nil}

    value = Map.get form.data, field
    wrapper_class =
      if error do
        "is-invalid"
      else
        if required && String.length to_string value > 0 do
          "form-init"
        else
          ""
        end
      end

    rows = opts[:rows] || 3

    render "form_textarea.html", form: form,
                                 field: field,
                                 label: label,
                                 error: error,
                                 wrapper_class: wrapper_class,
                                 class: class,
                                 required: required,
                                 rows: rows
  end

  def form_password(form, field, opts \\ []) do
    class = opts[:class] || ""
    label = opts[:label] || humanize(field)
    required = opts[:required] || nil
    {error, _} = Keyword.get form.errors, field, {nil, nil}

    wrapper_class =
      if error do
        "is-invalid"
      else
        if required do "form-init" else "" end
      end

    render "form_password.html", form: form,
                                 field: field,
                                 label: label,
                                 error: error,
                                 wrapper_class: wrapper_class,
                                 class: class,
                                 required: required
  end

  def form_date(form, field, opts \\ []) do
    default = input_value(form, field) || opts[:value] || Ecto.Date.utc()
    class = opts[:class] || ""
    label = opts[:label] || humanize(field)
    {error, _} = Keyword.get form.errors, field, {nil, nil}

    wrapper_class = if error do "is-invalid" else "" end

    render "form_date.html", form: form,
                             field: field,
                             label: label,
                             error: error,
                             wrapper_class: wrapper_class,
                             class: class,
                             default: default
  end

  def form_time(form, field, opts \\ []) do
    default = input_value(form, field) || opts[:value] || %{hour: 0, min: 0}
    class = opts[:class] || ""
    label = opts[:label] || humanize(field)
    {error, _} = Keyword.get form.errors, field, {nil, nil}

    wrapper_class = if error do "is-invalid" else "" end

    render "form_time.html", form: form,
                             field: field,
                             label: label,
                             error: error,
                             wrapper_class: wrapper_class,
                             class: class,
                             default: default
  end

  def form_datetime(form, field, opts \\ []) do
    default = input_value(form, field) ||
      Map.merge(Ecto.DateTime.utc(), opts[:value] || %{})

    class = opts[:class] || ""
    label = opts[:label] || humanize(field)
    {error, _} = Keyword.get form.errors, field, {nil, nil}

    wrapper_class = if error do "is-invalid" else "" end

    render "form_datetime.html", form: form,
                                 field: field,
                                 label: label,
                                 error: error,
                                 wrapper_class: wrapper_class,
                                 class: class,
                                 default: default
  end

  def form_select(form, field, options, opts \\ []) do
    class = opts[:class] || ""
    label = opts[:label] || humanize(field)
    selected = opts[:selected] || nil
    {error, _} = Keyword.get form.errors, field, {nil, nil}

    wrapper_class = if error do "is-invalid" else "" end

    render "form_select.html", form: form,
                               field: field,
                               label: label,
                               error: error,
                               selected: selected,
                               options: options,<commit_msg>Removes the exessive input_value since the default takes care of it<commit_after>defmodule CoursePlanner.SharedView do
  @moduledoc false
  use CoursePlanner.Web, :view

  # helpers

  def path_exact_match(conn, path) do
    conn.request_path == path
  end

  def path_match(conn, path) do
    String.starts_with? conn.request_path, path
  end

  def get_gravatar_url(email, size \\ 100) do
    hash =
      :md5
      |> :crypto.hash(email)
      |> Base.encode16()
      |> String.downcase()

    "https://www.gravatar.com/avatar/#{hash}?d=mm&s=#{size}"
  end

  def display_user_name(user) do
    [user.name, user.family_name, user.nickname && "(#{user.nickname})"]
    |> Enum.filter(fn v -> String.length(to_string v) > 0 end)
    |> Enum.join(" ")
  end

  # form components

  def form_text(form, field, opts \\ []) do
    class = opts[:class] || ""
    label = opts[:label] || humanize(field)
    required = opts[:required] || nil
    {error, _} = Keyword.get form.errors, field, {nil, nil}

    value = Map.get form.data, field
    wrapper_class =
      if error do
        "is-invalid"
      else
        if required && String.length to_string value > 0 do
          "form-init"
        else
          ""
        end
      end

    render "form_text.html", form: form,
                             field: field,
                             label: label,
                             error: error,
                             wrapper_class: wrapper_class,
                             class: class,
                             required: required
  end

  def form_textarea(form, field, opts \\ []) do
    class = opts[:class] || ""
    label = opts[:label] || humanize(field)
    required = opts[:required] || nil
    {error, _} = Keyword.get form.errors, field, {nil, nil}

    value = Map.get form.data, field
    wrapper_class =
      if error do
        "is-invalid"
      else
        if required && String.length to_string value > 0 do
          "form-init"
        else
          ""
        end
      end

    rows = opts[:rows] || 3

    render "form_textarea.html", form: form,
                                 field: field,
                                 label: label,
                                 error: error,
                                 wrapper_class: wrapper_class,
                                 class: class,
                                 required: required,
                                 rows: rows
  end

  def form_password(form, field, opts \\ []) do
    class = opts[:class] || ""
    label = opts[:label] || humanize(field)
    required = opts[:required] || nil
    {error, _} = Keyword.get form.errors, field, {nil, nil}

    wrapper_class =
      if error do
        "is-invalid"
      else
        if required do "form-init" else "" end
      end

    render "form_password.html", form: form,
                                 field: field,
                                 label: label,
                                 error: error,
                                 wrapper_class: wrapper_class,
                                 class: class,
                                 required: required
  end

  def form_date(form, field, opts \\ []) do
    default = opts[:value] || Ecto.Date.utc()
    class = opts[:class] || ""
    label = opts[:label] || humanize(field)
    {error, _} = Keyword.get form.errors, field, {nil, nil}

    wrapper_class = if error do "is-invalid" else "" end

    render "form_date.html", form: form,
                             field: field,
                             label: label,
                             error: error,
                             wrapper_class: wrapper_class,
                             class: class,
                             default: default
  end

  def form_time(form, field, opts \\ []) do
    default = opts[:value] || %{hour: 0, min: 0}
    class = opts[:class] || ""
    label = opts[:label] || humanize(field)
    {error, _} = Keyword.get form.errors, field, {nil, nil}

    wrapper_class = if error do "is-invalid" else "" end

    render "form_time.html", form: form,
                             field: field,
                             label: label,
                             error: error,
                             wrapper_class: wrapper_class,
                             class: class,
                             default: default
  end

  def form_datetime(form, field, opts \\ []) do
    default = Map.merge(Ecto.DateTime.utc(), opts[:value] || %{})

    class = opts[:class] || ""
    label = opts[:label] || humanize(field)
    {error, _} = Keyword.get form.errors, field, {nil, nil}

    wrapper_class = if error do "is-invalid" else "" end

    render "form_datetime.html", form: form,
                                 field: field,
                                 label: label,
                                 error: error,
                                 wrapper_class: wrapper_class,
                                 class: class,
                                 default: default
  end

  def form_select(form, field, options, opts \\ []) do
    class = opts[:class] || ""
    label = opts[:label] || humanize(field)
    selected = opts[:selected] || nil
    {error, _} = Keyword.get form.errors, field, {nil, nil}

    wrapper_class = if error do "is-invalid" else "" end

    render "form_select.html", form: form,
                               field: field,
                               label: label,
                               error: error,
                               selected: selected,
                               options: options,
{'fraction_non_alphanumeric': 0.10873044096728307, 'fraction_numerical': 0.0021337126600284497, 'mean_word_length': 1.353347280334728, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '206627', 'n_tokens_mistral': 3099, 'n_tokens_neox': 2998, 'n_words': 803}