<commit_before>module MenuHelper
  LINE_BREAK = "\n"
  TAB_INDEX = 2
  WHITE_SPACE = ' '

  def build_menu_header(options = {})
    menu = []
    menu << _break_tab('<nav class="navbar navbar-toggleable-md fixed-top">')
    menu.concat(_button_icon)
    menu << _home_menu_item(options)
    menu.concat(_container_menu_items(options))
    menu << _break_tab('</nav>')
    menu.concat(_container_title)

    menu.join.html_safe
  end

  def build_menu_footer

  end

  private

  def _break_tab(text_excerpt, tabs = 0)
    text = LINE_BREAK.dup
    text << WHITE_SPACE * (tabs * TAB_INDEX) if tabs > 0
    text << text_excerpt
  end

  def _container_menu_items(options)
    container = []
    container << _break_tab('<div class="collapse navbar-collapse justify-content-end" id="navbarCollapse">', 1)
    container << _break_tab('<ul class="navbar-nav">', 2)

    options[:menu_items] ||= []
    menu_items = options[:menu_items].collect do |item|
      _menu_item item[:label], item[:path]
    end
    container.concat menu_items
    container.concat _authentication_menu_item

    container << _break_tab('</ul>', 2)
    container << _break_tab('</div>', 1)
  end

  def _menu_item(label, path)
    menu = []
    menu << _break_tab('<li class="nav-item">', 3)
    menu << _break_tab('<h5>', 4)
    menu << link_to(label, path, class: 'nav-link')
    menu << '</h5>'
    menu << _break_tab('</li>', 3)
  end

  def _home_menu_item(options)
    path = (options[:home_path]) ? options[:home_path] : home_path
    _break_tab(link_to(I18n.translate('menu.header.home'), path, class: 'navbar-brand'), 1)
  end

  def _authentication_menu_item
    if session[:user_so].nil?
      _signin_menu_item
    else
      _signout_menu_item
    end
  end

  def _signin_menu_item
    menu = []
    menu << _break_tab('<li class="nav-item">', 3)
    menu << _break_tab('<h5>', 4)
    menu << link_to(t('menu.header.login'), login_path, class: 'nav-link')
    menu << '</h5>'
    menu << _break_tab('</li>', 3)
  end

  def _signout_menu_item
    menu = []
    menu << _break_tab('<li class="nav-item">', 3)
    menu << _break_tab('<h5>', 4)
    menu << link_to(t('menu.header.sign_out'), signout_path, method: :delete, class: 'nav-link')
    menu << '</h5>'
    menu << _break_tab('</li>', 3)
  end

  def _container_title
    menu = []
    menu << _break_tab('<br/><br/>')
    menu << _break_tab('<div class="jumbotron text-center">')
    menu << _break_tab("<h1>#{I18n.translate 'menu.header.title'}</h1>", 1)
    menu << _break_tab("<p>#{I18n.translate 'menu.header.subtitle'}</p>", 1)
    menu << _break_tab('</div>')
  end

  def _button_icon
    menu = []
    menu << _break_tab(
      '<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" ' +
      'data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" ' +
      'aria-label="Toggle navigation">', 1
    )
    menu << _break_tab('<span class="navbar-toggler-icon"></span>', 2)
    menu << _break_tab('</button>', 1)
  end
end<commit_msg>Cria classe helper para construção dos menus header e footer.<commit_after>module MenuHelper
  LINE_BREAK = "\n"
  TAB_INDEX = 2
  WHITE_SPACE = ' '

  def build_menu_header(options = {})
    return if request[:menu_header_built]
    
    menu = []
    menu << _break_tab('<nav class="navbar navbar-toggleable-md fixed-top">')
    menu.concat(_button_icon)
    menu << _home_menu_item(options)
    menu.concat(_container_menu_items(options))
    menu << _break_tab('</nav>')
    menu.concat(_container_title)
    
    request[:menu_header_built] = true
    menu.join.html_safe
  end

  def build_menu_footer

  end

  private

  def _break_tab(text_excerpt, tabs = 0)
    text = LINE_BREAK.dup
    text << WHITE_SPACE * (tabs * TAB_INDEX) if tabs > 0
    text << text_excerpt
  end

  def _container_menu_items(options)
    container = []
    container << _break_tab('<div class="collapse navbar-collapse justify-content-end" id="navbarCollapse">', 1)
    container << _break_tab('<ul class="navbar-nav">', 2)

    options[:menu_items] ||= []
    menu_items = options[:menu_items].collect do |item|
      _menu_item item[:label], item[:path]
    end
    container.concat menu_items
    container.concat _authentication_menu_item

    container << _break_tab('</ul>', 2)
    container << _break_tab('</div>', 1)
  end

  def _menu_item(label, path)
    menu = []
    menu << _break_tab('<li class="nav-item">', 3)
    menu << _break_tab('<h5>', 4)
    menu << link_to(label, path, class: 'nav-link')
    menu << '</h5>'
    menu << _break_tab('</li>', 3)
  end

  def _home_menu_item(options)
    path = (options[:home_path]) ? options[:home_path] : home_path
    _break_tab(link_to(I18n.translate('menu.header.home'), path, class: 'navbar-brand'), 1)
  end

  def _authentication_menu_item
    if session[:user_so].nil?
      _signin_menu_item
    else
      _signout_menu_item
    end
  end

  def _signin_menu_item
    menu = []
    menu << _break_tab('<li class="nav-item">', 3)
    menu << _break_tab('<h5>', 4)
    menu << link_to(t('menu.header.login'), login_path, class: 'nav-link')
    menu << '</h5>'
    menu << _break_tab('</li>', 3)
  end

  def _signout_menu_item
    menu = []
    menu << _break_tab('<li class="nav-item">', 3)
    menu << _break_tab('<h5>', 4)
    menu << link_to(t('menu.header.sign_out'), signout_path, method: :delete, class: 'nav-link')
    menu << '</h5>'
    menu << _break_tab('</li>', 3)
  end

  def _container_title
    menu = []
    menu << _break_tab('<br/><br/>')
    menu << _break_tab('<div class="jumbotron text-center">')
    menu << _break_tab("<h1>#{I18n.translate 'menu.header.title'}</h1>", 1)
    menu << _break_tab("<p>#{I18n.translate 'menu.header.subtitle'}</p>", 1)
    menu << _break_tab('</div>')
  end

  def _button_icon
    menu = []
    menu << _break_tab(
      '<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" ' +
      'data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" ' +
      'aria-label="Toggle navigation">', 1
    )
    menu << _break_tab('<span class="navbar-toggler-icon"></span>', 2)
    menu << _break_tab('</button>', 1)
  end
end
{'fraction_non_alphanumeric': 0.1666131621187801, 'fraction_numerical': 0.011556982343499198, 'mean_word_length': 3.5548245614035086, 'pattern_counts': {'":': 0, '<': 191, '<?xml version=': 0, '>': 65, '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': '2456720', 'n_tokens_mistral': 2303, 'n_tokens_neox': 2216, 'n_words': 433}