<commit_before>require 'spiderfw/templates/template_blocks'

module Spider; module TemplateBlocks
    
    class Each < Block
        
        def initialize(el, template=nil, allowed_blocks=nil)
            @repeated = []
            super
        end
        
        def compile
            init = ""
            rep_type = nil
            rep = nil
            ['sp:each', 'sp:each_index'].each do |name|
                if (@el.attributes[name])
                    rep_type = name[3..-1]
                    rep = @el.attributes[name]
                    @el.remove_attribute(name)
                    break
                end
            end
            return nil unless rep_type
            if (rep =~ /\s*(.+)\s*\|\s*(.+)\s*\|/)
                repeated = $1.strip
                arguments = $2.strip
            end
            c = "#{var_to_scene(repeated)}.#{rep_type} do |#{arguments}|\n"
            content = Spider::TemplateBlocks.parse_element(@el, @allowed_blocks, @template).compile
            content.run_code.each_line do |line|
                c += '  '+line
            end
            c += '   $out << "\n"'
            c += "\n"
            c += "end\n"
            init += content.init_code
            return CompiledBlock.new(init, c)
        end
        <commit_msg>vars_to_scene instead of var_to_scene in each param<commit_after>require 'spiderfw/templates/template_blocks'

module Spider; module TemplateBlocks
    
    class Each < Block
        
        def initialize(el, template=nil, allowed_blocks=nil)
            @repeated = []
            super
        end
        
        def compile
            init = ""
            rep_type = nil
            rep = nil
            ['sp:each', 'sp:each_index'].each do |name|
                if (@el.attributes[name])
                    rep_type = name[3..-1]
                    rep = @el.attributes[name]
                    @el.remove_attribute(name)
                    break
                end
            end
            return nil unless rep_type
            if (rep =~ /\s*(.+)\s*\|\s*(.+)\s*\|/)
                repeated = $1.strip
                arguments = $2.strip
            end
            c = "#{vars_to_scene(repeated)}.#{rep_type} do |#{arguments}|\n"
            content = Spider::TemplateBlocks.parse_element(@el, @allowed_blocks, @template).compile
            content.run_code.each_line do |line|
                c += '  '+line
            end
            c += '   $out << "\n"'
            c += "\n"
            c += "end\n"
            init += content.init_code
            return CompiledBlock.new(init, c)
        end
        
{'fraction_non_alphanumeric': 0.11755783086841107, 'fraction_numerical': 0.0030337504740235114, 'mean_word_length': 1.2261603375527426, 'pattern_counts': {'":': 0, '<': 9, '<?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': '2632940', 'n_tokens_mistral': 743, 'n_tokens_neox': 714, 'n_words': 158}