<commit_before>module ConsumersCoopPlugin::LayoutHelper

  protected

  include TermsHelper

  HeaderButtons = {
    start: [-> { profile.url }, -> { on_homepage? }],
    orders: [{controller: :consumers_coop_plugin_order, action: :index}],
    products: [{controller: :catalog, action: :index}, nil, -> { profile.enterprise? }],
    volunteering: [{controller: :consumers_coop_plugin_volunteers, action: :index}, nil, -> { profile.volunteers_settings.cycle_volunteers_enabled }],
    administration: [{controller: :consumers_coop_plugin_myprofile, action: :index},
     -> { @admin }, -> { profile.has_admin? user }],
  }

  def display_header_buttons
    # FIXME: call method on controller
    @admin = @controller.is_a? MyProfileController

    HeaderButtons.map do |key, (url, selected_proc, if_proc)|
      next if if_proc and not instance_exec(&if_proc)

      label = t "consumers_coop_plugin.lib.layout_helper.#{key}"
      if url.is_a? Proc
        url = instance_exec &url
      else
        # necessary for profile with own domain
        url[:profile] = profile.identifier
      end

      if key != :administration and @admin
        selected = false
      elsif selected_proc
        selected = instance_exec &selected_proc
      else
        selected = params[:controller].to_s == url[:controller].to_s
      end

      link_to label, url, class: "menu-button #{"menu-selected" if selected}"
    end.join
  end

  def consumers_coop_header
    return unless consumers_coop_enabled?
    output = render file: 'consumers_coop_plugin_layouts/default'
    if on_homepage?<commit_msg>consumers_coop: fix html_safe on header<commit_after>module ConsumersCoopPlugin::LayoutHelper

  protected

  include TermsHelper

  HeaderButtons = {
    start: [-> { profile.url }, -> { on_homepage? }],
    orders: [{controller: :consumers_coop_plugin_order, action: :index}],
    products: [{controller: :catalog, action: :index}, nil, -> { profile.enterprise? }],
    volunteering: [{controller: :consumers_coop_plugin_volunteers, action: :index}, nil, -> { profile.volunteers_settings.cycle_volunteers_enabled }],
    administration: [{controller: :consumers_coop_plugin_myprofile, action: :index},
     -> { @admin }, -> { profile.has_admin? user }],
  }

  def display_header_buttons
    # FIXME: call method on controller
    @admin = @controller.is_a? MyProfileController

    HeaderButtons.map do |key, (url, selected_proc, if_proc)|
      next if if_proc and not instance_exec(&if_proc)

      label = t "consumers_coop_plugin.lib.layout_helper.#{key}"
      if url.is_a? Proc
        url = instance_exec &url
      else
        # necessary for profile with own domain
        url[:profile] = profile.identifier
      end

      if key != :administration and @admin
        selected = false
      elsif selected_proc
        selected = instance_exec &selected_proc
      else
        selected = params[:controller].to_s == url[:controller].to_s
      end

      link_to label, url, class: "menu-button #{"menu-selected" if selected}"
    end.safe_join
  end

  def consumers_coop_header
    return unless consumers_coop_enabled?
    output = render file: 'consumers_coop_plugin_layouts/default'
    if on_homepage?
{'fraction_non_alphanumeric': 0.10655483069276173, 'fraction_numerical': 0.0, 'mean_word_length': 3.5034965034965033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '3019818', 'n_tokens_mistral': 976, 'n_tokens_neox': 961, 'n_words': 233}