<commit_before>module Spider; module Components
    
    class Menu < Spider::Widget
        tag 'menu'
        
        attr_to_scene :items, :sections, :labels, :links, :current, :current_widget
        attr_reader :current, :current_label
        
        def init
            @items = []
            @sections = {}
            @labels = {}
            @links = {}
            @all_widgets = {}
            @widgets_by_action = {}
        end
        
        def route_widget
            [@current, @_action.split('/', 2)[1]]
        end


        def prepare(action='')
            if (@_action_local)
                act = @_action_local
            else
                redirect(request_path+'/'+@links[@items[0]]) unless @items.empty?
            end
            widget = @widgets_by_action[act]
            raise NotFound.new(request_path) unless widget
            add_widget(widget)
            @current = widget.id
            @current_widget = widget
            @current_label = @labels[widget.id]
            super
        end
        
        def add(section, label, widget)
            @items << widget.id
            @sections[section] ||= []
            @sections[section] << widget.id
            @labels[widget.id] = label
            w_action = label.downcase.gsub(/\s+/, '_')
            @widgets_by_action[w_action] = widget
            @links[widget.id] = w_action
            @all_widgets[widget.id] = widget
        end
        
        def widget_resources
            return @current_widget.resources if @current_widget
            return []
        end<commit_msg>Fixed redirect<commit_after>module Spider; module Components
    
    class Menu < Spider::Widget
        tag 'menu'
        
        attr_to_scene :items, :sections, :labels, :links, :current, :current_widget
        attr_reader :current, :current_label
        
        def init
            @items = []
            @sections = {}
            @labels = {}
            @links = {}
            @all_widgets = {}
            @widgets_by_action = {}
        end
        
        def route_widget
            [@current, @_action.split('/', 2)[1]]
        end


        def prepare(action='')
            if (@_action_local)
                act = @_action_local
            else
                redirect(widget_request_path+'/'+@links[@items[0]]) unless @items.empty?
            end
            widget = @widgets_by_action[act]
            raise NotFound.new(request_path) unless widget
            add_widget(widget)
            @current = widget.id
            @current_widget = widget
            @current_label = @labels[widget.id]
            super
        end
        
        def add(section, label, widget)
            @items << widget.id
            @sections[section] ||= []
            @sections[section] << widget.id
            @labels[widget.id] = label
            w_action = label.downcase.gsub(/\s+/, '_')
            @widgets_by_action[w_action] = widget
            @links[widget.id] = w_action
            @all_widgets[widget.id] = widget
        end
        
        def widget_resources
            return @current_widget.resources if @current_widget
            return []
        end
{'fraction_non_alphanumeric': 0.1032540675844806, 'fraction_numerical': 0.0018773466833541927, 'mean_word_length': 1.455453149001536, 'pattern_counts': {'":': 0, '<': 13, '<?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': '239159', 'n_tokens_mistral': 870, 'n_tokens_neox': 845, 'n_words': 176}