<commit_before># frozen_string_literal: true

module Jekyll
  class LiquidRenderer
    class File
      def initialize(renderer, filename)
        @renderer = renderer
        @filename = filename
      end

      def parse(content)
        measure_time do
          @renderer.cache[@filename] ||= Liquid::Template.parse(content, :line_numbers => true)
        end
        @template = @renderer.cache[@filename]

        self
      end

      def render(*args)
        measure_time do
          measure_bytes do
            measure_counts do
              @template.render(*args)
            end
          end
        end
      end

      # This method simply 'rethrows any error' before attempting to render the template.
      def render!(*args)
        measure_time do
          measure_bytes do
            measure_counts do
              @template.render!(*args)
            end
          end
        end
      end

      def warnings
        @template.warnings
      end

      private

      def measure_counts
        @renderer.increment_count(@filename)
        yield
      end

      def measure_bytes
        yield.tap do |str|
          @renderer.increment_bytes(@filename, str.bytesize)
        end
      end

      def measure_time
        before = Time.now
        yield
      ensure
        after = Time.now
        @renderer.increment_time(@filename, after - before)
      end<commit_msg>Clear cached Liquid template scope before render (#7967)<commit_after># frozen_string_literal: true

module Jekyll
  class LiquidRenderer
    class File
      def initialize(renderer, filename)
        @renderer = renderer
        @filename = filename
      end

      def parse(content)
        measure_time do
          @renderer.cache[@filename] ||= Liquid::Template.parse(content, :line_numbers => true)
        end
        @template = @renderer.cache[@filename]

        self
      end

      def render(*args)
        reset_template_assigns

        measure_time do
          measure_bytes do
            measure_counts do
              @template.render(*args)
            end
          end
        end
      end

      # This method simply 'rethrows any error' before attempting to render the template.
      def render!(*args)
        reset_template_assigns

        measure_time do
          measure_bytes do
            measure_counts do
              @template.render!(*args)
            end
          end
        end
      end

      def warnings
        @template.warnings
      end

      private

      # clear assigns to `Liquid::Template` instance prior to rendering since
      # `Liquid::Template` instances are cached in Jekyll 4.
      def reset_template_assigns
        @template.instance_assigns.clear
      end

      def measure_counts
        @renderer.increment_count(@filename)
        yield
      end

      def measure_bytes
        yield.tap do |str|
          @renderer.increment_bytes(@filename, str.bytesize)
        end
      end

      def measure_time
        before = Time.now
        yield
      ensure
        after = Time.now
        @renderer.increment_time(@filename, after - before)
      end
{'fraction_non_alphanumeric': 0.061445399554282076, 'fraction_numerical': 0.001591849729385546, 'mean_word_length': 1.6946826758147513, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1192389', 'n_tokens_mistral': 839, 'n_tokens_neox': 811, 'n_words': 226}