<commit_before>require "less"

module Jekyll
  module Assets
    module Processors
      class LESS

        # --------------------------------------------------------------------
        # Setup and pull out the context and update the data, shipping it.
        # --------------------------------------------------------------------

        def self.call(input)
          data = input[:data]; paths = [input[:load_path]]
          tree = Less.instance_variable_get(:@loader).require("less/tree")
          context = input[:environment].context_class.new(input)
          patch_tree(tree, context)

          paths |= input[:environment].paths
          paths |= Dir.glob(input[:load_path] + '/*').select(&File.method(:directory?))
          parser = Less::Parser.new(:paths => paths)

          context.metadata.merge({
            :data => Less::Parser.new(:paths => paths) \
              .parse(data).to_css
          })
        end

        # --------------------------------------------------------------------
        # Add the sprockets helpers into the Less environment so people can
        # use assets from within Less... as they see fit.
        # --------------------------------------------------------------------
        # We also make sure to disable their quotes so that we can quote
        # ourselves if we need to, otherwise we simply just take the values.
        # --------------------------------------------------------------------

        def self.patch_tree(tree, context)
          Sprockets::Helpers.instance_methods.reject { |v| v=~ /^(path_to_|assets_environment$)/ }.each do |m|
            tree.functions[m.to_s.tr("_", "-")] = tree.functions[m.to_s] = lambda do |*args|
              args.last.tap do |o|
                o[:quote] = "" # We handle that ourselves, fuck that.
                o[:value] = context.send(m, args.last.toCSS().gsub(
                  /^"|"$/, ""
                ))

                if m.to_s.end_with?("_path")
                  o[:value] = o[:value].inspect
                end
              end
            end
          end
        end
      end
    end
  end
end

# ----------------------------------------------------------------------------

Sprockets.register_engine ".less", Jekyll::Assets::Processors::LESS<commit_msg>Start preparing for Sprockets 4.0<commit_after>require "less"

module Jekyll
  module Assets
    module Processors
      class LESS

        # --------------------------------------------------------------------
        # Setup and pull out the context and update the data, shipping it.
        # --------------------------------------------------------------------

        def self.call(input)
          data = input[:data]; paths = [input[:load_path]]
          tree = Less.instance_variable_get(:@loader).require("less/tree")
          context = input[:environment].context_class.new(input)
          patch_tree(tree, context)

          paths |= input[:environment].paths
          paths |= Dir.glob(input[:load_path] + '/*').select(&File.method(:directory?))
          parser = Less::Parser.new(:paths => paths)

          context.metadata.merge({
            :data => Less::Parser.new(:paths => paths) \
              .parse(data).to_css
          })
        end

        # --------------------------------------------------------------------
        # Add the sprockets helpers into the Less environment so people can
        # use assets from within Less... as they see fit.
        # --------------------------------------------------------------------
        # We also make sure to disable their quotes so that we can quote
        # ourselves if we need to, otherwise we simply just take the values.
        # --------------------------------------------------------------------

        def self.patch_tree(tree, context)
          Sprockets::Helpers.instance_methods.reject { |v| v=~ /^(path_to_|assets_environment$)/ }.each do |m|
            tree.functions[m.to_s.tr("_", "-")] = tree.functions[m.to_s] = lambda do |*args|
              args.last.tap do |o|
                o[:quote] = "" # We handle that ourselves, fuck that.
                o[:value] = context.send(m, args.last.toCSS().gsub(
                  /^"|"$/, ""
                ))

                if m.to_s.end_with?("_path")
                  o[:value] = o[:value].inspect
                end
              end
            end
          end
        end
      end
    end
  end
end

# ----------------------------------------------------------------------------

if Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new(4.0)
  Sprockets.register_mime_type "text/less", :extensions => [".less", ".css.less"]
  Sprockets.register_transformer("text/less", "test/css",
    Jekyll::Assets::Processors::LESS
  )
else
  Sprockets.register_engine(
    ".less", Jekyll::Assets::Processors::LESS
  )
end
{'fraction_non_alphanumeric': 0.27618069815195073, 'fraction_numerical': 0.0008213552361396304, 'mean_word_length': 1.1745535714285715, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5307836', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1183, 'n_words': 290}