<commit_before>module ToolbarHelper
  # Public interface

  # Render a list of buttons (toolbar) to html
  #
  # Called directly when updating toolbars in an existing page.
  #
  def buttons_to_html(buttons_in)
    groups = split_to_groups(Array(buttons_in))

    groups.collect do |buttons|
      # exceptional behavior for view toolbar view mode buttons
      first_button = Array(buttons)[0]
      view_buttons = first_button.present? &&
                     first_button[:name] =~ /^view_/

      cls = view_buttons ? 'toolbar-pf-view-selector ' : ''
      cls += 'hidden ' unless buttons.find { |button| !button[:hidden] }
      content_tag(:div, :class => "#{cls} form-group") do # form-group aroung each toolbar section
        if view_buttons
          view_mode_buttons(buttons)
        else
          normal_toolbar_buttons(buttons)
        end
      end
    end.join('').html_safe
  end

  # Request that a toolbar is rendered.
  #
  #   * div_id        -- toolbar div DOM id
  #   * toolbar_name  -- toolbar name (presently means name of the yaml file
  #                      with tb definition)
  #
  # We should remove this method as we refactor the partials that call it.
  #
  def defered_toolbar_render(div_id, toolbar_name)
    div_id ||= 'center_tb'
    @toolbars[div_id] = toolbar_name
  end

  # Actually render the toolbars requested by 'defered_toolbar_render'
  #
  # We should call rendering directly once when remove 'defered_toolbar_render'.
  #
  def render_toolbars
    @toolbars.collect do |div_id, toolbar_name|
      content_tag(:div, :id => div_id) do # div for each toolbar
        buttons = toolbar_name ? build_toolbar(toolbar_name) : nil
        buttons_to_html(buttons)
      end
    end.join('').html_safe
  end

  # Internal stuff to generate html markup

  # Render a group of view toolbar buttons
  #
  def view_mode_buttons(buttons)
    content_tag(:ul, :class => 'list-inline') do
      buttons.collect do |button|
        toolbar_button_normal(button, true)
      end.join('').html_safe
    end
  end

  # Render a group of normal toolbar buttons
  #
  def normal_toolbar_buttons(buttons)
    Array(buttons).collect do |button|
      toolbar_top_button(button)
    end.join('').html_safe
  end
<commit_msg>Toolbars: unify nil array handling.<commit_after>module ToolbarHelper
  # Public interface

  # Render a list of buttons (toolbar) to html
  #
  # Called directly when updating toolbars in an existing page.
  #
  def buttons_to_html(buttons_in)
    groups = split_to_groups(Array(buttons_in))

    groups.collect do |buttons|
      buttons = Array(buttons)

      # exceptional behavior for view toolbar view mode buttons
      view_buttons = buttons.first.present? &&
                     buttons.first[:name] =~ /^view_/

      cls = view_buttons ? 'toolbar-pf-view-selector ' : ''
      cls += 'hidden ' unless buttons.find { |button| !button[:hidden] }
      content_tag(:div, :class => "#{cls} form-group") do # form-group aroung each toolbar section
        if view_buttons
          view_mode_buttons(buttons)
        else
          normal_toolbar_buttons(buttons)
        end
      end
    end.join('').html_safe
  end

  # Request that a toolbar is rendered.
  #
  #   * div_id        -- toolbar div DOM id
  #   * toolbar_name  -- toolbar name (presently means name of the yaml file
  #                      with tb definition)
  #
  # We should remove this method as we refactor the partials that call it.
  #
  def defered_toolbar_render(div_id, toolbar_name)
    div_id ||= 'center_tb'
    @toolbars[div_id] = toolbar_name
  end

  # Actually render the toolbars requested by 'defered_toolbar_render'
  #
  # We should call rendering directly once when remove 'defered_toolbar_render'.
  #
  def render_toolbars
    @toolbars.collect do |div_id, toolbar_name|
      content_tag(:div, :id => div_id) do # div for each toolbar
        buttons = toolbar_name ? build_toolbar(toolbar_name) : nil
        buttons_to_html(buttons)
      end
    end.join('').html_safe
  end

  # Internal stuff to generate html markup

  # Render a group of view toolbar buttons
  #
  def view_mode_buttons(buttons)
    content_tag(:ul, :class => 'list-inline') do
      buttons.collect do |button|
        toolbar_button_normal(button, true)
      end.join('').html_safe
    end
  end

  # Render a group of normal toolbar buttons
  #
  def normal_toolbar_buttons(buttons)
    buttons.collect do |button|
      toolbar_top_button(button)
    end.join('').html_safe
  end

{'fraction_non_alphanumeric': 0.0872840053167922, 'fraction_numerical': 0.00022153300841825432, 'mean_word_length': 2.82303132938188, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6933198', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1331, 'n_words': 394}