<commit_before>require 'rubygems'
require 'extensions/kernel'
require_relative '../Path'
require_relative 'Utilities'

module WebBlocks
  
  module Build
    
    module Module
      
      include ::WebBlocks::Path::Source
      include ::WebBlocks::Path::Temporary_Build
      include ::WebBlocks::Build::Utilities
      
      def modules
        
        if config[:src][:modules] == :all
          all_modules
        elsif config[:src][:modules]
          config[:src][:modules].respond_to?(:each) ? config[:src][:modules] : [config[:src][:modules]]
        else
          []
        end
        
      end
      
      def all_modules
        
        modules = []
        dir = src_core_definitions_dir
        Dir.entries(dir).sort.each do |name|
          next if name[0,1] == '.'
          if File.directory? "#{dir}/#{name}"
            modules.push name
          end
        end
        modules
        
      end
    
      def link_sass_libs_for base_dir

        File.open tmp_sass_lib_file, "a" do |linker|
          File.open tmp_sass_lib_file_ie, "a" do |ie_linker|
            File.open tmp_sass_lib_file_require, "a" do |require_linker|

              # Pull _require.scss file from root (special file)
              get_files(base_dir, 'scss', false).sort.each do |file|
                
                next unless file.match /\/_+require.scss$/
                
                log.debug "#{File.basename require_linker.path} <- #{file}"
                require_linker << "@import \"#{file}\"\n"
                
              end
              
              # For all modules, link files as standard, IE and require
              modules.each do |dir|

                dir = ::WebBlocks::Path.to base_dir, dir
                
                if File.exists? "#{dir}.scss"
                  linker << "@import \"#{dir}.scss\";\n" 
                end
                
                if File.exists? "#{File.dirname(dir)}/_#{File.basename(dir)}.scss"
                  linker << "@import \"#{File.dirname(dir)}/_#{File.basename(dir)}.scss\";\n"
                end
                
                if File.exists? "#{dir}-ie.scss"
                  ie_linker << "@import \"#{dir}-ie.scss\";\n" 
                end
                
                if File.exists? "#{File.dirname(dir)}/_#{File.basename(dir)}-ie.scss"
                  ie_linker << "@import \"#{File.dirname(dir)}/_#{File.basename(dir)}-ie.scss\";\n"
                end

                get_files(dir, 'scss').sort.each do |file|

                  next if file.match /\/_+variables.scss$/

                  if file.match /\/_+require.scss$/
                    target = require_linker
                  elsif file.match /-ie.scss$/
                    target = ie_linker
                  else
                    target = linker 
                  end

                  log.debug "#{File.basename target.path} <- #{file}"
                  target << "@import \"#{file}\";\n"
                  
                end

              end

            end
          end
        end

        # Link all variables files
        File.open tmp_sass_lib_file_variables, "a" do |variables_linker|

          get_files(base_dir, 'scss').each do |file|
            next unless file.match /\/_+variables.scss$/
            variables_linker << "@import \"#{file}\";\n"
          end

        end

      end
      
      def assemble_img_files_for base_dir
        
        get_files(base_dir, ['gif','jpg','jpeg','png','bmp']).each do |file|
          
          dst = "#{tmp_img_build_dir}/#{file.gsub /^#{base_dir}\//, ''}"
          log.debug "#{tmp_img_build_dir.gsub /^#{root_dir}\//, ''} <- #{file.gsub /^#{root_dir}\//, ''}"
          FileUtils.mkdir_p File.dirname(dst)
          FileUtils.cp_r file, dst
          
        end
        
      end
      
      def assemble_js_libs_into_file_for base_dir, target_absolute_name
        
        files = [[],[]]
        
        if File.exists? "#{base_dir}.js"
          files[1] << "#{base_dir}.js"<commit_msg>Extricate sass lib linkage write routine from find [#140]<commit_after>require 'rubygems'
require 'extensions/kernel'
require_relative '../Path'
require_relative 'Utilities'

module WebBlocks
  
  module Build
    
    module Module
      
      include ::WebBlocks::Path::Source
      include ::WebBlocks::Path::Temporary_Build
      include ::WebBlocks::Build::Utilities
      
      def modules
        
        if config[:src][:modules] == :all
          all_modules
        elsif config[:src][:modules]
          config[:src][:modules].respond_to?(:each) ? config[:src][:modules] : [config[:src][:modules]]
        else
          []
        end
        
      end
      
      def all_modules
        
        modules = []
        dir = src_core_definitions_dir
        Dir.entries(dir).sort.each do |name|
          next if name[0,1] == '.'
          if File.directory? "#{dir}/#{name}"
            modules.push name
          end
        end
        modules
        
      end
      
      def link_sass_lib file
        
        if file.match /\/_+variables.scss$/
          target = tmp_sass_lib_file_variables
        elsif file.match /\/_+require.scss$/
          target = tmp_sass_lib_file_require
        elsif file.match /-ie.scss$/
          target = tmp_sass_lib_file_ie
        else
          target = tmp_sass_lib_file
        end
        
        File.open target, "a" do |handle|
          log.debug "#{File.basename target} <- #{file}"
          handle.puts "@import \"#{file}\";"
        end
        
      end
    
      def link_sass_libs_for base_dir

        get_files(base_dir, 'scss').each do |file|
          if file.match /\/_+require.scss$/ or file.match /\/_+variables.scss$/
            link_sass_lib file
          end
        end

        get_files(base_dir, 'scss', false).each do |file|
          unless file.match /\/_+require.scss$/ or file.match /\/_+variables.scss$/ # as already included
            link_sass_lib file
          end
        end
        
        modules.each do |dir|
          
          dir = ::WebBlocks::Path.to base_dir, dir
          
          if File.exists? "#{dir}.scss"
            link_sass_lib "#{dir}.scss"
          end

          if File.exists? "#{File.dirname(dir)}/_#{File.basename(dir)}.scss"
            link_sass_lib "#{File.dirname(dir)}/_#{File.basename(dir)}.scss"
          end

          if File.exists? "#{dir}-ie.scss"
            link_sass_lib "#{dir}-ie.scss"
          end

          if File.exists? "#{File.dirname(dir)}/_#{File.basename(dir)}-ie.scss"
            link_sass_lib "#{File.dirname(dir)}/_#{File.basename(dir)}-ie.scss"
          end
          
          get_files(dir, 'scss').sort.each do |file|

            next if file.match /\/_+variables.scss$/

            link_sass_lib file

          end
          
        end

      end
      
      def assemble_img_files_for base_dir
        
        get_files(base_dir, ['gif','jpg','jpeg','png','bmp']).each do |file|
          
          dst = "#{tmp_img_build_dir}/#{file.gsub /^#{base_dir}\//, ''}"
          log.debug "#{tmp_img_build_dir.gsub /^#{root_dir}\//, ''} <- #{file.gsub /^#{root_dir}\//, ''}"
          FileUtils.mkdir_p File.dirname(dst)
          FileUtils.cp_r file, dst
          
        end
        
      end
      
      def assemble_js_libs_into_file_for base_dir, target_absolute_name
        
        files = [[],[]]
        
        if File.exists? "#{base_dir}.js"
          files[1] << "#{base_dir}.js"
{'fraction_non_alphanumeric': 0.13125414731254148, 'fraction_numerical': 0.0011944260119442602, 'mean_word_length': 1.4871287128712871, 'pattern_counts': {'":': 0, '<': 26, '<?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': '5961103', 'n_tokens_mistral': 2344, 'n_tokens_neox': 2284, 'n_words': 438}